public async Task BroadcastAsync(Transaction transaction, Guid operationId) { TxBroadcast response; try { response = await _dashInsightClient.BroadcastTxAsync(transaction.ToHex()); if (response == null) { throw new ArgumentException($"{nameof(response)} can not be null"); } if (string.IsNullOrEmpty(response.Txid)) { throw new ArgumentException($"{nameof(response)}{nameof(response.Txid)} can not be null or empty. Response={response}"); } } catch (Exception ex) { await _log.WriteErrorAsync(nameof(DashService), nameof(BroadcastAsync), $"transaction: {transaction}, operationId: {operationId}", ex); throw; } var block = await _dashInsightClient.GetLatestBlockHeight(); await _broadcastRepository.AddAsync(operationId, response.Txid, block); await _broadcastInProgressRepository.AddAsync(operationId, response.Txid); }
public async Task BroadcastAsync(Transaction transaction, Guid operationId) { var hash = transaction.GetHash().ToString(); var tx = await _dashInsightClient.GetTx(hash); if (tx == null) { await _dashInsightClient.BroadcastTxAsync(transaction.ToHex()); } else { _log.Info("Transaction already in block chain", new { transaction, operationId }); } var block = await _dashInsightClient.GetLatestBlockHeight(); await _broadcastRepository.AddAsync(operationId, hash, block); await _broadcastInProgressRepository.AddAsync(operationId, hash); }