Пример #1
0
        public async Task <BigInteger?> IndexCashinEventsForErc20TransactionHashAsync(string transactionHash)
        {
            BigInteger result      = 0;
            var        transaction = await _ethereumIndexerService.GetTransactionAsync(transactionHash);

            if (transaction == null)
            {
                return(null);
            }

            if (transaction.ErcTransfer != null)
            {
                //only one transfer could appear in deposit transaction
                foreach (var item in transaction.ErcTransfer)
                {
                    if (item.To?.ToLower() != _settingsWrapper.Ethereum.HotwalletAddress?.ToLower())
                    {
                        continue;
                    }

                    await _cashinEventRepository.InsertAsync(new CashinEvent
                    {
                        CoinAdapterAddress = Erc20HotWalletMarker,
                        Amount             = item.Value,
                        TransactionHash    = item.TransactionHash,
                        UserAddress        = item.From,
                        ContractAddress    = item.ContractAddress
                    });

                    BigInteger.TryParse(item.Value, out result);
                }
            }

            return(result);
        }
Пример #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 _depositContractRepository.Contains(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.");
            }
        }