Example #1
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);
        }
Example #2
0
        public AckEip8Message Deserialize(byte[] bytes)
        {
            Rlp.DecoderContext context         = bytes.AsRlpContext();
            AckEip8Message     authEip8Message = new AckEip8Message();

            context.ReadSequenceLength();
            authEip8Message.EphemeralPublicKey = new PublicKey(context.DecodeByteArray());
            authEip8Message.Nonce = context.DecodeByteArray();
            return(authEip8Message);
        }
Example #3
0
        public NetworkNode Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            context.ReadSequenceLength();

            var publicKey   = new PublicKey(context.DecodeByteArray());
            var ip          = System.Text.Encoding.UTF8.GetString(context.DecodeByteArray());
            var port        = context.DecodeByteArray().ToInt32();
            var description = System.Text.Encoding.UTF8.GetString(context.DecodeByteArray());
            var reputation  = context.DecodeByteArray().ToInt64();

            var networkNode = new NetworkNode(publicKey, ip != string.Empty ? ip : null, port, description != string.Empty ? description : null, reputation);

            return(networkNode);
        }
        public AuthEip8Message Deserialize(byte[] data)
        {
            // TODO: this would not be compatible with future versions... ? if the length of prefixes changes
            Rlp.DecoderContext context     = data.AsRlpContext();
            AuthEip8Message    authMessage = new AuthEip8Message();

            context.ReadSequenceLength();
            byte[]    sigAllBytes = context.DecodeByteArray();
            Signature signature   = new Signature(sigAllBytes.Slice(0, 64), sigAllBytes[64]); // since Signature class is Ethereum style it expects V as the 64th byte, hence we use RecoveryID constructor

            authMessage.Signature = signature;
            authMessage.PublicKey = new PublicKey(context.DecodeByteArray());
            authMessage.Nonce     = context.DecodeByteArray();
            int version = context.DecodeInt();

            return(authMessage);
        }
        private static HiMessage Deserialize(Rlp.DecoderContext context)
        {
            context.ReadSequenceLength();
            var protocolVersion = context.DecodeByte();
            var providerAddress = context.DecodeAddress();
            var consumerAddress = context.DecodeAddress();
            var nodeId          = new PublicKey(context.DecodeByteArray());
            var signature       = SignatureDecoder.DecodeSignature(context);

            return(new HiMessage(protocolVersion, providerAddress, consumerAddress,
                                 nodeId, signature));
        }
Example #6
0
        public byte[] Get(UInt256 index)
        {
            byte[] key   = GetKey(index);
            byte[] value = Get(key);
            if (value == null)
            {
                return(new byte[] { 0 });
            }

            Rlp.DecoderContext rlp = value.AsRlpContext();
            return(rlp.DecodeByteArray());
        }
Example #7
0
        private ParityStateChange <byte[]> DecodeByteChange(Rlp.DecoderContext context)
        {
            int sequenceLength = context.ReadSequenceLength();

            if (sequenceLength == 0)
            {
                return(null);
            }

            ParityStateChange <byte[]> change = new ParityStateChange <byte[]>(context.DecodeByteArray(), context.DecodeByteArray());

            return(change);
        }
        public FindNodeMessage Deserialize(byte[] msg)
        {
            var results = PrepareForDeserialization <FindNodeMessage>(msg);

            Rlp.DecoderContext context = results.Data.AsRlpContext();

            context.ReadSequenceLength();
            var searchedNodeId = context.DecodeByteArray();
            var expireTime     = context.DecodeLong();

            var message = results.Message;

            message.SearchedNodeId = searchedNodeId;
            message.ExpirationTime = expireTime;

            return(message);
        }
Example #9
0
        public ParityLikeTxTrace Decode(Rlp.DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            ParityLikeTxTrace trace = new ParityLikeTxTrace();

            context.ReadSequenceLength();
            trace.BlockHash       = context.DecodeKeccak();
            trace.BlockNumber     = context.DecodeUInt256();
            trace.TransactionHash = context.DecodeKeccak();
            byte[] txPosBytes = context.DecodeByteArray();
            trace.TransactionPosition = txPosBytes.Length == 0 ? (int?)null : txPosBytes.ToInt32();
            context.ReadSequenceLength();
            trace.Action       = DecodeAction(context);
            trace.StateChanges = DecodeStateDiff(context);
            // stateChanges

            return(trace);
        }
        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);
        }
Example #11
0
        public GetBlockHeadersMessage Deserialize(byte[] bytes)
        {
            GetBlockHeadersMessage message = new GetBlockHeadersMessage();

            Rlp.DecoderContext context = bytes.AsRlpContext();
            context.ReadSequenceLength();
            int position = context.Position;

            byte[] startingBytes = context.DecodeByteArray();
            context.Position = position;
            if (startingBytes.Length == 32)
            {
                message.StartingBlockHash = context.DecodeKeccak();
            }
            else
            {
                message.StartingBlockNumber = (long)context.DecodeUInt256();
            }

            message.MaxHeaders = context.DecodeInt();
            message.Skip       = context.DecodeInt();
            message.Reverse    = context.DecodeByte();
            return(message);
        }