public ResultWrapper <IEnumerable <FilterLog> > eth_getLogs(Filter filter) { IEnumerable <FilterLog> GetLogs(BlockParameter blockParameter, BlockParameter toBlockParameter, CancellationTokenSource cancellationTokenSource, CancellationToken token) { using (cancellationTokenSource) { foreach (FilterLog log in _blockchainBridge.GetLogs(blockParameter, toBlockParameter, filter.Address, filter.Topics, token)) { yield return(log); } } } BlockParameter fromBlock = filter.FromBlock; BlockParameter toBlock = filter.ToBlock; try { CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(_cancellationTokenTimeout); return(ResultWrapper <IEnumerable <FilterLog> > .Success(GetLogs(fromBlock, toBlock, cancellationTokenSource, cancellationTokenSource.Token))); } catch (ArgumentException e) { switch (e.Message) { case ILogFinder.NotFoundError: return(ResultWrapper <IEnumerable <FilterLog> > .Fail(e.Message, ErrorCodes.ResourceNotFound)); default: return(ResultWrapper <IEnumerable <FilterLog> > .Fail(e.Message, ErrorCodes.InvalidParams)); } } }
public ResultWrapper <IEnumerable <FilterLog> > eth_getLogs(Filter filter) { var fromBlock = MapFilterBlock(filter.FromBlock); var toBlock = MapFilterBlock(filter.ToBlock); return(ResultWrapper <IEnumerable <FilterLog> > .Success(_blockchainBridge.GetLogs(fromBlock, toBlock, filter.Address, filter.Topics))); }
public void Eth_get_logs(string parameter) { IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>(); bridge.GetLogs(Arg.Any <FilterBlock>(), Arg.Any <FilterBlock>(), Arg.Any <object>(), Arg.Any <IEnumerable <object> >()).Returns(new[] { new FilterLog(1, 0, 1, TestItem.KeccakA, 1, TestItem.KeccakB, TestItem.AddressA, new byte[] { 1, 2, 3 }, new[] { TestItem.KeccakC, TestItem.KeccakD }) }); bridge.FilterExists(1).Returns(true); IEthModule module = new EthModule(NullLogManager.Instance, bridge); string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_getLogs", parameter); Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":[{\"address\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"blockHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockNumber\":\"0x1\",\"data\":\"0x010203\",\"logIndex\":\"0x1\",\"removed\":false,\"topics\":[\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"0x6c3fd336b49dcb1c57dd4fbeaf5f898320b0da06a5ef64e798c6497600bb79f2\"],\"transactionHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"transactionIndex\":\"0x1\",\"transactionLogIndex\":\"0x0\"}]}", serialized); }
public ResultWrapper <IEnumerable <FilterLog> > eth_getLogs(Filter filter) { IEnumerable <FilterLog> GetLogs(BlockParameter blockParameter, BlockParameter toBlockParameter, CancellationTokenSource cancellationTokenSource, CancellationToken token) { using (cancellationTokenSource) { foreach (FilterLog log in _blockchainBridge.GetLogs(blockParameter, toBlockParameter, filter.Address, filter.Topics, token)) { yield return(log); } } } // because of lazy evaluation of enumerable, we need to do the validation here first CancellationTokenSource cancellationTokenSource = new(_rpcConfig.Timeout); CancellationToken cancellationToken = cancellationTokenSource.Token; SearchResult <BlockHeader> toBlockResult = _blockFinder.SearchForHeader(filter.ToBlock); if (toBlockResult.IsError) { cancellationTokenSource.Dispose(); return(ResultWrapper <IEnumerable <FilterLog> > .Fail(toBlockResult)); } cancellationToken.ThrowIfCancellationRequested(); SearchResult <BlockHeader> fromBlockResult = _blockFinder.SearchForHeader(filter.FromBlock); if (fromBlockResult.IsError) { cancellationTokenSource.Dispose(); return(ResultWrapper <IEnumerable <FilterLog> > .Fail(fromBlockResult)); } cancellationToken.ThrowIfCancellationRequested(); long fromBlockNumber = fromBlockResult.Object !.Number; long toBlockNumber = toBlockResult.Object !.Number; if (fromBlockNumber > toBlockNumber && toBlockNumber != 0) { cancellationTokenSource.Dispose(); return(ResultWrapper <IEnumerable <FilterLog> > .Fail($"'From' block '{fromBlockNumber}' is later than 'to' block '{toBlockNumber}'.", ErrorCodes.InvalidParams)); } return(ResultWrapper <IEnumerable <FilterLog> > .Success(GetLogs(filter.FromBlock, filter.ToBlock, cancellationTokenSource, cancellationToken))); }
public ResultWrapper <IEnumerable <FilterLog> > eth_getLogs(Filter filter) { BlockParameter fromBlock = filter.FromBlock; BlockParameter toBlock = filter.ToBlock; try { return(ResultWrapper <IEnumerable <FilterLog> > .Success(_blockchainBridge.GetLogs(fromBlock, toBlock, filter.Address, filter.Topics))); } catch (ArgumentException e) { switch (e.Message) { case ILogFinder.NotFoundError: return(ResultWrapper <IEnumerable <FilterLog> > .Fail(e.Message, ErrorCodes.ResourceNotFound)); default: return(ResultWrapper <IEnumerable <FilterLog> > .Fail(e.Message, ErrorCodes.InvalidParams)); } } }