public BlockBodiesMessage Deserialize(byte[] bytes)
        {
            Rlp.DecoderContext decoderContext = bytes.AsRlpContext();
            BlockBodiesMessage message        = new BlockBodiesMessage();

            message.Bodies = decoderContext.DecodeArray(ctx =>
            {
                decoderContext.ReadSequenceLength();
                Transaction[] transactions = decoderContext.DecodeArray(txCtx => Rlp.Decode <Transaction>(ctx));
                BlockHeader[] ommers       = decoderContext.DecodeArray(txCtx => Rlp.Decode <BlockHeader>(ctx));
                return(transactions, ommers);
            });

            return(message);
        }
        public GetNodeDataMessage Deserialize(byte[] bytes)
        {
            Rlp.DecoderContext decoderContext = bytes.AsRlpContext();
            var keys = decoderContext.DecodeArray(itemContext => itemContext.DecodeKeccak());

            return(new GetNodeDataMessage(keys));
        }
Пример #3
0
        private static ParityTraceAction DecodeAction(Rlp.DecoderContext context)
        {
            ParityTraceAction action = new ParityTraceAction();
            int sequenceLength       = context.ReadSequenceLength();

            if (context.ReadNumberOfItemsRemaining(context.Position + sequenceLength) == 3)
            {
                action.CallType     = "reward";
                action.RewardType   = context.DecodeString();
                action.Author       = context.DecodeAddress();
                action.Value        = context.DecodeUInt256();
                action.TraceAddress = Array.Empty <int>();
            }
            else
            {
                action.CallType       = context.DecodeString();
                action.From           = context.DecodeAddress();
                action.To             = context.DecodeAddress();
                action.Value          = context.DecodeUInt256();
                action.Gas            = context.DecodeLong();
                action.Input          = context.DecodeByteArray();
                action.Result         = new ParityTraceResult();
                action.Result.Output  = context.DecodeByteArray();
                action.Result.GasUsed = context.DecodeLong();
                action.TraceAddress   = context.DecodeArray(c => c.DecodeInt());
                int subtracesCount = context.DecodeInt();
                action.Subtraces = new List <ParityTraceAction>(subtracesCount);
                for (int i = 0; i < subtracesCount; i++)
                {
                    action.Subtraces.Add(DecodeAction(context));
                }
            }

            return(action);
        }
Пример #4
0
        public GetReceiptsMessage Deserialize(byte[] bytes)
        {
            Rlp.DecoderContext decoderContext = bytes.AsRlpContext();
            var hashes = decoderContext.DecodeArray(itemContext => itemContext.DecodeKeccak());

            return(new GetReceiptsMessage(hashes));
        }
        public NodeDataMessage Deserialize(byte[] bytes)
        {
            if (bytes.Length == 0 && bytes[0] == Rlp.OfEmptySequence[0])
            {
                return(new NodeDataMessage(null));
            }

            Rlp.DecoderContext decoderContext = bytes.AsRlpContext();

            var             data    = decoderContext.DecodeArray(itemContext => itemContext.DecodeByteArray());
            NodeDataMessage message = new NodeDataMessage(data);

            return(message);
        }
Пример #6
0
        public ReceiptsMessage Deserialize(byte[] bytes)
        {
            if (bytes.Length == 0 && bytes[0] == Rlp.OfEmptySequence[0])
            {
                return(new ReceiptsMessage(null));
            }

            Rlp.DecoderContext decoderContext = bytes.AsRlpContext();

            var data = decoderContext.DecodeArray(itemContext =>
                                                  itemContext.DecodeArray(nestedContext => Rlp.Decode <TxReceipt>(nestedContext)) ?? new TxReceipt[0]);
            ReceiptsMessage message = new ReceiptsMessage(data);

            return(message);
        }
Пример #7
0
        private Node[] DeserializeNodes(Rlp.DecoderContext context)
        {
            return(context.DecodeArray(ctx =>
            {
                int lastPosition = ctx.ReadSequenceLength() + ctx.Position;
                int count = ctx.ReadNumberOfItemsRemaining(lastPosition);
                var address = GetAddress(ctx.DecodeByteArray(), ctx.DecodeInt());
                if (count > 3)
                {
                    ctx.DecodeInt();
                }

                byte[] id = ctx.DecodeByteArray();
                return NodeFactory.CreateNode(new PublicKey(id), address);
            }));
        }
Пример #8
0
        public HelloMessage Deserialize(byte[] bytes)
        {
            Rlp.DecoderContext context = bytes.AsRlpContext();
            context.ReadSequenceLength();

            HelloMessage helloMessage = new HelloMessage();

            helloMessage.P2PVersion   = context.DecodeByte();
            helloMessage.ClientId     = context.DecodeString();
            helloMessage.Capabilities = context.DecodeArray(ctx =>
            {
                ctx.ReadSequenceLength();
                string protocolCode = ctx.DecodeString();
                int version         = ctx.DecodeByte();
                return(new Capability(protocolCode, version));
            }).ToList();

            helloMessage.ListenPort = context.DecodeInt();
            helloMessage.NodeId     = new PublicKey(context.DecodeByteArray());
            return(helloMessage);
        }
Пример #9
0
 public GetBlockBodiesMessage Deserialize(byte[] bytes)
 {
     Rlp.DecoderContext context = bytes.AsRlpContext();
     Keccak[]           hashes  = context.DecodeArray(ctx => context.DecodeKeccak());
     return(new GetBlockBodiesMessage(hashes));
 }