public async Task BroadcastTransaction(NeoModules.NEP6.Transactions.Transaction signedTransaction, OperationAggregate aggregate) { var txHash = signedTransaction.Hash.ToString().Substring(2); var lastBlockHeight = await _blockchainProvider.GetHeightAsync(); try { var isSuccess = await _neoRawTransactionSender.SendRequestAsync(signedTransaction.ToHexString()); if (!isSuccess) { throw new Exception("Unknown error while broadcasting the tx"); } } catch (RpcResponseException e) when(e.RpcError.Code == -501) { throw new TransactionAlreadyBroadcastedException(e); } await _observableOperationRepository.InsertOrReplace(ObervableOperation.Create(aggregate, BroadcastStatus.InProgress, txHash, (int)lastBlockHeight)); await _unconfirmedTransactionRepository.InsertOrReplace( UnconfirmedTransaction.Create(aggregate.OperationId, txHash)); await _transactionOutputsService.CompleteTxOutputs(aggregate.OperationId, signedTransaction); }
public async Task BroadCastTransactionAsync(Guid operationId, Transaction tx) { var operation = await _operationMetaRepository.GetAsync(operationId); if (operation == null) { throw new BusinessException("Operation not found", ErrorCode.BadInputParameter); } if (await _operationEventRepository.ExistAsync(operationId, OperationEventType.Broadcasted)) { throw new BusinessException("Transaction already brodcasted", ErrorCode.TransactionAlreadyBroadcasted); } var hash = tx.GetHash().ToString(); await _transactionBlobStorage.AddOrReplaceTransactionAsync(operationId, hash, TransactionBlobType.BeforeBroadcast, tx.ToHex()); var lastBlockHeight = await _blockChainProvider.GetLastBlockHeightAsync(); await _blockChainProvider.BroadCastTransactionAsync(tx); await _observableOperationRepository.InsertOrReplaceAsync(ObervableOperation.Create(operation, BroadcastStatus.InProgress, hash, lastBlockHeight)); await _unconfirmedTransactionRepository.InsertOrReplaceAsync( UnconfirmedTransaction.Create(operationId, hash)); await _transactionOutputsService.CompleteTxOutputs(operationId, tx); await _operationEventRepository.InsertIfNotExistAsync(OperationEvent.Create(operationId, OperationEventType.Broadcasted)); }