public async Task FailOutgoingAsync(NotEnoughFundsOutTxCommand cmd) { var txs = (await _transactionsService.GetByBcnIdentityAsync( cmd.Blockchain, cmd.IdentityType, cmd.Identity)).ToList(); if (!txs.Any()) { throw new OutboundTransactionsNotFound(cmd.Blockchain, cmd.IdentityType, cmd.Identity); } foreach (var tx in txs) { _log.Info($"Failing outgoing transaction, not enough funds [type={tx.TransactionType}]", cmd.ToJson()); IUpdateTransactionCommand updateCommand = MapToUpdateCommand(cmd, tx.TransactionType); await _transactionsService.UpdateAsync(updateCommand); if (tx.TransactionType == TransactionType.Payment) { await _paymentRequestService.UpdateStatusAsync(tx.WalletAddress, PaymentRequestStatusInfo.New()); } if (tx.TransactionType == TransactionType.Exchange) { var context = tx.ContextData.DeserializeJson <ExchangeTransactonContext>(); if (context != null) { await _walletHistoryService.RemoveAsync(context.HistoryOperationId); } } if (tx.TransactionType == TransactionType.CashOut) { var context = tx.ContextData.DeserializeJson <CashoutTransactionContext>(); if (context != null) { await _walletHistoryService.RemoveAsync(context.HistoryOperationId); } } } }
private IUpdateTransactionCommand MapToUpdateCommand( NotEnoughFundsOutTxCommand cmd, TransactionType transactionType) { switch (transactionType) { case TransactionType.Payment: return(Mapper.Map <FailPaymentOutTxCommand>(cmd, MapConfirmed())); case TransactionType.CashOut: return(Mapper.Map <FailCashoutTxCommand>(cmd, MapConfirmed())); case TransactionType.Exchange: return(Mapper.Map <FailExchangeOutTxCommand>(cmd, MapConfirmed())); default: throw new UnexpectedTransactionTypeException(transactionType); } }