public async Task <IEnumerable <ErcAddressHistoryModel> > GetTokenHistory(TokenTransaction addressTransactions)
        {
            var transactionResponseRaw = await _ethereumSamuraiApi.ApiErc20TransferHistoryGetErc20TransfersPostAsync(
                new GetErc20TransferHistoryRequest(addressTransactions.Address, null, new List <string>()
            {
                addressTransactions.TokenAddress
            }),
                addressTransactions.Start,
                addressTransactions.Count);

            List <ErcAddressHistoryModel> result = MapErcHistoryFromResponse(transactionResponseRaw);

            return(result);
        }
Beispiel #2
0
        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.");
            }
        }
Beispiel #3
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='request'>
 /// </param>
 /// <param name='start'>
 /// </param>
 /// <param name='count'>
 /// </param>
 public static object ApiErc20TransferHistoryGetErc20TransfersPost(this IEthereumSamuraiApi operations, GetErc20TransferHistoryRequest request = default(GetErc20TransferHistoryRequest), int?start = default(int?), int?count = default(int?))
 {
     return(operations.ApiErc20TransferHistoryGetErc20TransfersPostAsync(request, start, count).GetAwaiter().GetResult());
 }