Example #1
0
        public async Task <ServiceResponse <SendBtcResultDto> > SendBtc([FromBody] SendBtcDto btc)
        {
            ValidateModelState();

            SendBtcResultDto result = await _transactionService.SendBtcAsync(btc).ConfigureAwait(false);

            return(ServiceResponse <SendBtcResultDto> .New(true, result));
        }
Example #2
0
        public async Task <SendBtcResultDto> SendBtcAsync(SendBtcDto btc)
        {
            var wallets = await _bitcoinApiWrapper.TryListWalletsWithBalancesAsync().ConfigureAwait(false);

            var walletsList = wallets.Where(x => x.Balance > btc.Amount).ToList();

            if (walletsList.Count == 0)
            {
                throw new Exception(Errors.NotEnoughFundsError);
            }

            var rand         = new Random(DateTime.Now.Millisecond);
            var randIndex    = rand.Next(0, walletsList.Count);
            var randomWallet = walletsList[randIndex];

            string transactionId = await _bitcoinApiWrapper.TrySendBtcAsync(btc, randomWallet.Name).ConfigureAwait(false);

            return(new SendBtcResultDto()
            {
                TransactionId = transactionId
            });
        }
Example #3
0
 public async Task <string> TrySendBtcAsync(SendBtcDto btc, string wallet)
 {
     return(await this.TryExecuteAsync <string>(BitcoinApiMethods.SendToAddress, wallet, btc.Address, btc.Amount).ConfigureAwait(false));
 }