public async Task DetectUnconfirmedTransactions() { var unconfirmedTxs = await _unconfirmedTransactionRepository.GetAll(); foreach (var unconfirmedTransaction in unconfirmedTxs) { var operationMeta = await _operationMetaRepository.Get(unconfirmedTransaction.OperationId); if (operationMeta == null) { await _log.WriteWarningAsync(nameof(UpdateObservableOperations), nameof(DetectUnconfirmedTransactions), unconfirmedTransaction.ToJson(), "OperationMeta not found"); continue; } var confirmationCount = await _blockChainProvider.GetTxConfirmationCount(unconfirmedTransaction.TxHash); var isCompleted = confirmationCount >= _confirmationsSettings.MinConfirmationsToDetectOperation; ; if (isCompleted) { //Force update balances var fromAddressUpdatedBalance = await _walletBalanceService.UpdateBalance(operationMeta.FromAddress); var toAddressUpdatedBalance = await _walletBalanceService.UpdateBalance(operationMeta.ToAddress); var operationCompletedLoggingContext = new { unconfirmedTransaction.OperationId, unconfirmedTransaction.TxHash, fromAddressUpdatedBalance, toAddressUpdatedBalance }; await _operationEventRepository.InsertIfNotExist(OperationEvent.Create(unconfirmedTransaction.OperationId, OperationEventType.DetectedOnBlockChain, operationCompletedLoggingContext)); await _log.WriteInfoAsync(nameof(UpdateBalanceFunctions), nameof(DetectUnconfirmedTransactions), operationCompletedLoggingContext.ToJson(), "Operation completed"); await _unconfirmedTransactionRepository.DeleteIfExist(unconfirmedTransaction.OperationId); } var status = isCompleted ? BroadcastStatus.Completed : BroadcastStatus.InProgress; await _observableOperationRepository.InsertOrReplace(ObervableOperation.Create(operationMeta, status, unconfirmedTransaction.TxHash)); } }
private async Task CheckTransaction(IUnconfirmedTransaction unconfirmedTx) { var operation = await _operationRepository.GetOrDefault(unconfirmedTx.OperationId); if (operation == null) { _log.Error(nameof(DetectTransactionsPeriodicalHandler), message: $"Aggregate for operation {unconfirmedTx.OperationId} not found"); return; } var blockchainTx = await _blockchainProvider.GetTransactionOrDefaultAsync(unconfirmedTx.TxHash); var isCompleted = blockchainTx?.blockHash != null; //once a tx included in a block means the tx is confirmed by the 7 consensus nodes and cannt be reversed var lastBlockHeight = await _blockchainProvider.GetHeightAsync(); var status = isCompleted ? BroadcastStatus.Completed : BroadcastStatus.InProgress; await _observableOperationRepository.InsertOrReplace(ObervableOperation.Create(operation, status, unconfirmedTx.TxHash, lastBlockHeight)); if (isCompleted) { var fromAddressBalance = await _walletBalanceService.UpdateBalance(operation.FromAddress); var toAddressBalance = await _walletBalanceService.UpdateBalance(operation.ToAddress); var operationCompletedLoggingContext = new { unconfirmedTx.OperationId, unconfirmedTx.TxHash, fromAddressBalance, toAddressBalance }; _log.Info("Transaction detected on blockchain", context: operationCompletedLoggingContext); await _unconfirmedTransactionRepository.DeleteIfExist(unconfirmedTx.OperationId); operation.OnDetectedOnBlockcain(DateTime.UtcNow); await _operationRepository.Save(operation); } }
public async Task UpdateBalances() { var wallets = (await _observableWalletRepository.GetAll()).ToList(); foreach (var observableWallet in wallets) { await _walletBalanceService.UpdateBalance(observableWallet); } }
public async Task Execute() { foreach (var wallet in await _observableWalletRepository.GetAll()) { try { await _walletBalanceService.UpdateBalance(wallet.Address); } catch (Exception e) { _log.Error(e); } } }
public async Task UpdateBalances() { var wallets = (await _observableWalletRepository.GetAll()).ToList(); foreach (var observableWallet in wallets) { try { await _walletBalanceService.UpdateBalance(observableWallet); } catch (Exception e) { await _log.WriteErrorAsync(nameof(UpdateBalanceFunctions), nameof(UpdateBalances), observableWallet.ToJson(), e); } } }
public async Task UpdateBalances() { string continuation = null; do { IEnumerable <IObservableWallet> wallets; (wallets, continuation) = (await _observableWalletRepository.GetAll(1000, continuation)); foreach (var observableWallet in wallets) { try { await _walletBalanceService.UpdateBalance(observableWallet); } catch (Exception e) { await _log.WriteErrorAsync(nameof(UpdateBalanceFunctions), nameof(UpdateBalances), observableWallet.ToJson(), e); } } } while (continuation != null); }