public async Task <BlockchainTransferResult> TransferAsync(BlockchainTransferCommand transfer) { BlockchainTransferResult result = new BlockchainTransferResult { Blockchain = BlockchainType.Bitcoin }; foreach (var transferAmountGroup in transfer.Amounts.GroupBy(x => x.Destination)) { string destination = transferAmountGroup.Key; var sources = transferAmountGroup.Select(x => { switch (transfer.AssetId) { case LykkeConstants.BitcoinAsset: return(new ToOneAddress(x.Source, x.Amount)); case LykkeConstants.SatoshiAsset: return(new ToOneAddress(x.Source, x.Amount?.SatoshiToBtc())); default: throw new AssetNotSupportedException(transfer.AssetId); } }).ToList(); OnchainResponse response = await _bitcoinServiceClient.TransactionMultipleTransfer( Guid.NewGuid(), destination, LykkeConstants.BitcoinAsset, _feeProvider.FeeRate, _feeProvider.FixedFee, sources); var errorMessage = response.HasError ? $"Error placing MultipleTransfer transaction to destination address = {transferAmountGroup.Key}, code = {response.Error?.Code}, message = {response.Error?.Message}" : string.Empty; result.Transactions.Add(new BlockchainTransactionResult { Amount = sources.Sum(x => x.Amount ?? 0), AssetId = LykkeConstants.BitcoinAsset, Hash = response.Transaction?.Hash, IdentityType = TransactionIdentityType.Hash, Identity = response.Transaction?.Hash, Sources = sources.Select(x => x.Address), Destinations = new List <string> { destination }, Error = errorMessage }); } return(result); }
public async Task <string> ExecuteAsync(BtcTransfer transfer) { IEnumerable <ToOneAddress> sources = transfer.Sources .Where(x => x != null) .Select(x => new ToOneAddress(x.Address, x.Amount)); OnchainResponse response = await _bitcoinServiceClient.TransactionMultipleTransfer( Guid.NewGuid(), transfer.DestAddress, LykkeConstants.BitcoinAsset, transfer.FeeRate, transfer.FixedFee, sources); if (response.HasError) { throw new TransferException(response.Error.Code, response.Error.Message); } return(response.Transaction?.TransactionId?.ToString()); }
private async Task <TransactionRepsonse> ProcessBitcoinApiResponse(string request, string commandType, OnchainResponse response, string contextData, Guid?existingTxId = null) { var id = Guid.NewGuid().ToString(); if (response.Error != null) { await _bitCoinTransactionsRepository.CreateAsync(id, commandType, request, null, response?.ToJson()); } else { id = response.Transaction.TransactionId.ToString(); await _bitCoinTransactionsRepository.UpdateAsync(id, request, null, response?.ToJson()); } await _bitcoinTransactionService.SetStringTransactionContext(id, contextData); return(response.Transaction); }