예제 #1
0
        public ResultWrapper <IEnumerable <object> > eth_getFilterChanges(BigInteger filterId)
        {
            var        id         = (int)filterId;
            FilterType filterType = _blockchainBridge.GetFilterType(id);

            switch (filterType)
            {
            case FilterType.BlockFilter:
                return(_blockchainBridge.FilterExists(id)
                        ? ResultWrapper <IEnumerable <object> > .Success(_blockchainBridge.GetBlockFilterChanges(id)
                                                                         .Select(b => new Data.Data(b.Bytes)).ToArray())
                        : ResultWrapper <IEnumerable <object> > .Fail($"Filter with id: '{filterId}' does not exist."));

            case FilterType.PendingTransactionFilter:
                return(_blockchainBridge.FilterExists(id)
                        ? ResultWrapper <IEnumerable <object> > .Success(_blockchainBridge
                                                                         .GetPendingTransactionFilterChanges(id).Select(b => new Data.Data(b.Bytes)).ToArray())
                        : ResultWrapper <IEnumerable <object> > .Fail($"Filter with id: '{filterId}' does not exist."));

            case FilterType.LogFilter:
                return(_blockchainBridge.FilterExists(id)
                        ? ResultWrapper <IEnumerable <object> > .Success(
                           _blockchainBridge.GetLogFilterChanges(id).ToArray())
                        : ResultWrapper <IEnumerable <object> > .Fail($"Filter with id: '{filterId}' does not exist."));

            default:
                throw new NotSupportedException($"Filter type {filterType} is not supported");
            }
        }
예제 #2
0
        public ResultWrapper <IEnumerable <object> > eth_getFilterChanges(UInt256 filterId)
        {
            int        id         = (int)filterId;
            FilterType filterType = _blockchainBridge.GetFilterType(id);

            switch (filterType)
            {
            case FilterType.BlockFilter:
            {
                return(_blockchainBridge.FilterExists(id)
                        ? ResultWrapper <IEnumerable <object> > .Success(_blockchainBridge.GetBlockFilterChanges(id))
                        : ResultWrapper <IEnumerable <object> > .Fail($"Filter with id: '{filterId}' does not exist."));
            }

            case FilterType.PendingTransactionFilter:
            {
                return(_blockchainBridge.FilterExists(id)
                        ? ResultWrapper <IEnumerable <object> > .Success(_blockchainBridge.GetPendingTransactionFilterChanges(id))
                        : ResultWrapper <IEnumerable <object> > .Fail($"Filter with id: '{filterId}' does not exist."));
            }

            case FilterType.LogFilter:
            {
                return(_blockchainBridge.FilterExists(id)
                        ? ResultWrapper <IEnumerable <object> > .Success(
                           _blockchainBridge.GetLogFilterChanges(id).ToArray())
                        : ResultWrapper <IEnumerable <object> > .Fail($"Filter with id: '{filterId}' does not exist."));
            }

            default:
            {
                throw new NotSupportedException($"Filter type {filterType} is not supported");
            }
            }
        }
예제 #3
0
        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);
        }