Exemple #1
0
        private async Task IndexEventsInRange(string coinAdapterAddress, Nethereum.Contracts.Event coinCashInEvent, BigInteger from, BigInteger to)
        {
            var fromBlock = new Nethereum.RPC.Eth.DTOs.BlockParameter(new Nethereum.Hex.HexTypes.HexBigInteger(from));
            var toBlock   = new Nethereum.RPC.Eth.DTOs.BlockParameter(new Nethereum.Hex.HexTypes.HexBigInteger(to));
            var filter    = await coinCashInEvent.CreateFilterBlockRangeAsync(fromBlock, toBlock);

            var filterByCaller = await coinCashInEvent.GetAllChanges <CoinCashinEvent>(filter);

            filterByCaller.ForEach(async @event =>
            {
                string transactionHash = @event.Log.TransactionHash;
                CoinEventCashinCompletedMessage cashinTransactionMessage = new CoinEventCashinCompletedMessage()
                {
                    TransactionHash = transactionHash
                };

                await _cashinEventRepository.InsertAsync(new CashinEvent()
                {
                    CoinAdapterAddress = coinAdapterAddress,
                    Amount             = @event.Event.Amount.ToString(),
                    TransactionHash    = transactionHash,
                    UserAddress        = @event.Event.Caller
                });

                await _cashinQueue.PutRawMessageAsync(Newtonsoft.Json.JsonConvert.SerializeObject(cashinTransactionMessage));
            });

            await _blockSyncedRepository.InsertAsync(new BlockSynced()
            {
                BlockNumber = to.ToString(), CoinAdapterAddress = coinAdapterAddress
            });
        }
Exemple #2
0
        public async Task GetAllChanges()
        {
            var filter = await _event.CreateFilterAsync(new Nethereum.RPC.Eth.DTOs.BlockParameter(0));

            var newEvents = await _event.GetAllChanges <T>(filter);

            foreach (var newEvent in newEvents)
            {
                var blockInfo = await _client.GetBlockInfo(newEvent.Log.BlockNumber);

                _callback(_contractAddress, blockInfo, newEvent.Event);
            }
        }