public async Task BroadcastAsync(Transaction transaction, Guid operationId) { TxBroadcast response; try { response = await _dynamicInsightClient.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(DynamicService), nameof(BroadcastAsync), $"transaction: {transaction}, operationId: {operationId}", ex); throw; } var block = await _dynamicInsightClient.GetLatestBlockHeight(); await _broadcastRepository.AddAsync(operationId, response.Txid, block); await _broadcastInProgressRepository.AddAsync(operationId, response.Txid); }
private async Task <decimal> RefreshAddressBalance(string address, bool deleteZeroBalance) { var balance = await _dynamicInsightClient.GetBalance(address, _minConfirmations); if (balance > 0) { var block = await _dynamicInsightClient.GetLatestBlockHeight(); var balancePositive = await _balancePositiveRepository.GetAsync(address); if (balancePositive == null) { _log.WriteInfo(nameof(RefreshAddressBalance), new { address, balance, block }, $"Positive balance is detected"); } if (balancePositive != null && balancePositive.Amount != balance) { _log.WriteInfo(nameof(RefreshAddressBalance), new { address, balance, oldBalance = balancePositive.Amount, block }, $"Change in positive balance is detected"); } await _balancePositiveRepository.SaveAsync(address, balance, block); _chaosKitty.Meow(new { address, balance, block }.ToJson()); } if (balance == 0 && deleteZeroBalance) { _log.WriteInfo(nameof(RefreshAddressBalance), new { address }, $"Zero balance is detected"); await _balancePositiveRepository.DeleteAsync(address); _chaosKitty.Meow(address); } return(balance); }