public async Task IndexCashinEventsForErc20Deposits() { var indexerStatusResponse = await _indexerApi.ApiSystemIsAliveGetWithHttpMessagesAsync(); if (indexerStatusResponse.Response.IsSuccessStatusCode) { var responseContent = await indexerStatusResponse.Response.Content.ReadAsStringAsync(); var indexerStatus = JObject.Parse(responseContent); var lastIndexedBlock = BigInteger.Parse(indexerStatus["blockchainTip"].Value <string>()); var lastSyncedBlock = await GetLastSyncedBlockNumber(Erc20HotWalletMarker); while (++lastSyncedBlock <= lastIndexedBlock - _baseSettings.Level2TransactionConfirmation) { var transfersResponse = await _indexerApi.ApiErc20TransferHistoryGetErc20TransfersPostAsync ( new GetErc20TransferHistoryRequest { AssetHolder = _settingsWrapper.Ethereum.HotwalletAddress?.ToLower(), BlockNumber = (long)lastSyncedBlock, } ); switch (transfersResponse) { case IEnumerable <Erc20TransferHistoryResponse> transfers: foreach (var transfer in transfers) { // Ignore transfers from not deposit contract addresses if (!await _depositContractService.ContainsAsync(transfer.FromProperty)) { continue; } var coinTransactionMessage = new CoinTransactionMessage { TransactionHash = transfer.TransactionHash }; await _cashinEventRepository.InsertAsync(new CashinEvent { CoinAdapterAddress = Erc20HotWalletMarker, Amount = transfer.TransferAmount, TransactionHash = transfer.TransactionHash, UserAddress = transfer.FromProperty, ContractAddress = transfer.Contract }); await _cointTransactionQueue.PutRawMessageAsync(JsonConvert.SerializeObject(coinTransactionMessage)); } break; case ApiException exception: throw new Exception($"Ethereum indexer responded with error: {exception.Error.Message}"); default: throw new Exception($"Ethereum indexer returned unexpected response"); } await _blockSyncedRepository.InsertAsync(new BlockSynced { BlockNumber = lastSyncedBlock.ToString(), CoinAdapterAddress = Erc20HotWalletMarker }); } } else { throw new Exception("Can not obtain ethereum indexer status."); } }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task ApiSystemIsAliveGetAsync(this IEthereumSamuraiApi operations, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.ApiSystemIsAliveGetWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false)).Dispose(); }