コード例 #1
0
        public static Block GetBlock(this IBlockchainBridge blockchainBridge, BlockParameter blockParameter, bool allowNulls = false, bool recoverTxSenders = false)
        {
            Block block;

            switch (blockParameter.Type)
            {
            case BlockParameterType.Pending:
            {
                block = blockchainBridge.FindPendingBlock();
                break;
            }

            case BlockParameterType.Latest:
            {
                block = blockchainBridge.FindLatestBlock();
                break;
            }

            case BlockParameterType.Earliest:
            {
                block = blockchainBridge.FindEarliestBlock();
                break;
            }

            case BlockParameterType.BlockId:
            {
                if (blockParameter.BlockId == null)
                {
                    throw new JsonRpcException(ErrorType.InvalidParams, $"Block number is required for {BlockParameterType.BlockId}");
                }

                block = blockchainBridge.FindBlock(blockParameter.BlockId.Value);
                break;
            }

            default:
                throw new Exception($"{nameof(BlockParameterType)} not supported: {blockParameter.Type}");
            }

            if (block == null && !allowNulls)
            {
                throw new JsonRpcException(ErrorType.NotFound, $"Cannot find block {blockParameter}");
            }

            if (block != null && recoverTxSenders)
            {
                blockchainBridge.RecoverTxSenders(block);
            }

            return(block);
        }
コード例 #2
0
        public void Trace_replay_block()
        {
            ParityLikeTxTrace result1 = BuildParityTxTrace();
            ParityLikeTxTrace result2 = BuildParityTxTrace();

            Block             block            = Build.A.Block.TestObject;
            IBlockchainBridge blockchainBridge = Substitute.For <IBlockchainBridge>();

            blockchainBridge.FindLatestBlock().Returns(block);

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTraceBlock(block.Hash, Arg.Any <ParityTraceTypes>()).Returns(new[] { result1, result2 });

            ITraceModule module = new TraceModule(blockchainBridge, NullLogManager.Instance, tracer);

            string serialized = RpcTest.TestSerializedRequest(TraceModuleFactory.Converters, module, "trace_replayBlockTransactions", "latest", "[\"stateDiff\", \"trace\"]");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":[{\"output\":null,\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x02\"}},\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}},\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":[1,2,3],\"type\":null},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":[0,0],\"type\":null}],\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"vmTrace\":null},{\"output\":null,\"stateDiff\":{\"0x76e68a8696537e4141926f3e528733af9e237d69\":{\"balance\":{\"*\":{\"from\":\"0x1\",\"to\":\"0x2\"}},\"code\":{\"*\":{\"from\":\"0x01\",\"to\":\"0x02\"}},\"nonce\":{\"*\":{\"from\":\"0x0\",\"to\":\"0x1\"}},\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":{\"*\":{\"from\":\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"to\":\"0x0000000000000000000000000000000000000000000000000000000000000002\"}}}}},\"trace\":[{\"action\":{\"callType\":\"init\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"gas\":\"0x9c40\",\"input\":\"0x010203040506\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x3039\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":1,\"traceAddress\":[1,2,3],\"type\":null},{\"action\":{\"callType\":\"call\",\"from\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"gas\":\"0x2710\",\"input\":\"0x\",\"to\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"value\":\"0x10932\"},\"result\":{\"gasUsed\":\"0x0\",\"output\":null},\"subtraces\":0,\"traceAddress\":[0,0],\"type\":null}],\"transactionHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"vmTrace\":null}]}", serialized);
        }