public async Task <CashoutResult> ExecuteAsync(CashoutCommand cmd) { BlockchainType network = await _assetSettingsService.GetNetworkAsync(cmd.SourceAssetId); string hotwallet = _bcnSettingsResolver.GetCashoutHotWallet(network); if (string.IsNullOrEmpty(hotwallet)) { throw new CashoutHotwalletNotDefinedException(network); } string sourceAddress = await GetSourceAddressAsync(cmd); await _walletBalanceValidator.ValidateTransfer(sourceAddress, cmd.SourceAssetId, cmd.SourceAmount); TransferResult toHotWallet = await _retryPolicy .ExecuteAsync(() => _transferService.CashoutThrowFail( cmd.SourceAssetId, sourceAddress, hotwallet, cmd.SourceAmount)); foreach (var transferTransactionResult in toHotWallet.Transactions) { string historyId = await _walletHistoryService.PublishCashoutAsync(new WalletHistoryCashoutCommand { Blockchain = toHotWallet.Blockchain, AssetId = transferTransactionResult.AssetId, Amount = transferTransactionResult.Amount, DesiredAsset = cmd.DesiredAsset, EmployeeEmail = cmd.EmployeeEmail, TransactionHash = transferTransactionResult.Hash, WalletAddress = string.Join(Constants.Separator, transferTransactionResult.Sources) }); await _transactionsService.CreateTransactionAsync(new CreateTransactionCommand { Amount = transferTransactionResult.Amount, Blockchain = toHotWallet.Blockchain, AssetId = transferTransactionResult.AssetId, Confirmations = 0, Hash = transferTransactionResult.Hash, IdentityType = transferTransactionResult.IdentityType, Identity = transferTransactionResult.Identity, TransferId = toHotWallet.Id, Type = TransactionType.CashOut, SourceWalletAddresses = transferTransactionResult.Sources.ToArray(), ContextData = new CashoutTransactionContext { DesiredAsset = cmd.DesiredAsset, EmployeeEmail = cmd.EmployeeEmail, HistoryOperationId = historyId }.ToJson() }); } return(new CashoutResult { Amount = cmd.SourceAmount, AssetId = cmd.SourceAssetId, SourceWalletAddress = sourceAddress, DestWalletAddress = hotwallet }); }