public async Task <bool> CheckAndUpdateBalanceAsync( BalanceMonitoringTask task) { var address = task.Address; try { var balance = await _balanceRepository.TryGetAsync(address); if (balance != null) { var bestBlockNumber = await _blockchainService.GetBestTrustedBlockNumberAsync(); var amount = await _blockchainService.GetBalanceAsync(address, bestBlockNumber); balance.OnUpdated ( amount: amount, blockNumber: bestBlockNumber ); _chaosKitty.Meow(address); await _balanceRepository.UpdateSafelyAsync(balance); _log.Info ( $"Account [{address}] balance updated to [{amount}] at block [{bestBlockNumber}].", new { address } ); } else { _log.Info ( $"Account [{address}] balance is not observable.", new { address } ); } return(true); } catch (Exception e) { _log.Warning ( $"Failed to check balance of account [{task.Address}].", e, new { address } ); return(false); } }
public Task CompleteMonitoringTaskAsync( BalanceMonitoringTask task) { return(_balanceMonitoringTaskRepository.CompleteAsync(task)); }