コード例 #1
0
        public ProviderSession Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            _ = rlpStream.ReadSequenceLength();
            var id                     = rlpStream.DecodeKeccak();
            var depositId              = rlpStream.DecodeKeccak();
            var dataAssetId            = rlpStream.DecodeKeccak();
            var consumerAddress        = rlpStream.DecodeAddress();
            var consumerNodeId         = new PublicKey(rlpStream.DecodeByteArray());
            var providerAddress        = rlpStream.DecodeAddress();
            var providerNodeId         = new PublicKey(rlpStream.DecodeByteArray());
            var state                  = (SessionState)rlpStream.DecodeInt();
            var startUnitsFromProvider = rlpStream.DecodeUInt();
            var startUnitsFromConsumer = rlpStream.DecodeUInt();
            var startTimestamp         = rlpStream.DecodeUlong();
            var finishTimestamp        = rlpStream.DecodeUlong();
            var consumedUnits          = rlpStream.DecodeUInt();
            var unpaidUnits            = rlpStream.DecodeUInt();
            var paidUnits              = rlpStream.DecodeUInt();
            var settledUnits           = rlpStream.DecodeUInt();
            var graceUnits             = rlpStream.DecodeUInt();
            var dataAvailability       = (DataAvailability)rlpStream.DecodeInt();

            return(new ProviderSession(id, depositId, dataAssetId, consumerAddress, consumerNodeId, providerAddress,
                                       providerNodeId, state, startUnitsFromProvider, startUnitsFromConsumer, startTimestamp, finishTimestamp,
                                       consumedUnits, unpaidUnits, paidUnits, settledUnits, graceUnits, dataAvailability));
        }
コード例 #2
0
        public DataAsset Decode(RlpStream rlpStream,
                                RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var id                 = rlpStream.DecodeKeccak();
            var name               = rlpStream.DecodeString();
            var description        = rlpStream.DecodeString();
            var unitPrice          = rlpStream.DecodeUInt256();
            var unitType           = (DataAssetUnitType)rlpStream.DecodeInt();
            var minUnits           = rlpStream.DecodeUInt();
            var maxUnits           = rlpStream.DecodeUInt();
            var rules              = Nethermind.Core.Encoding.Rlp.Decode <DataAssetRules>(rlpStream);
            var provider           = Nethermind.Core.Encoding.Rlp.Decode <DataAssetProvider>(rlpStream);
            var file               = rlpStream.DecodeString();
            var queryType          = (QueryType)rlpStream.DecodeInt();
            var state              = (DataAssetState)rlpStream.DecodeInt();
            var termsAndConditions = rlpStream.DecodeString();
            var kycRequired        = rlpStream.DecodeBool();
            var plugin             = rlpStream.DecodeString();

            return(new DataAsset(id, name, description, unitPrice, unitType, minUnits, maxUnits,
                                 rules, provider, file, queryType, state, termsAndConditions, kycRequired, plugin));
        }
コード例 #3
0
        public DataAsset Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            try
            {
                rlpStream.ReadSequenceLength();
                Keccak            id                 = rlpStream.DecodeKeccak();
                string            name               = rlpStream.DecodeString();
                string            description        = rlpStream.DecodeString();
                UInt256           unitPrice          = rlpStream.DecodeUInt256();
                DataAssetUnitType unitType           = (DataAssetUnitType)rlpStream.DecodeInt();
                uint              minUnits           = rlpStream.DecodeUInt();
                uint              maxUnits           = rlpStream.DecodeUInt();
                DataAssetRules    rules              = Serialization.Rlp.Rlp.Decode <DataAssetRules>(rlpStream);
                DataAssetProvider provider           = Serialization.Rlp.Rlp.Decode <DataAssetProvider>(rlpStream);
                string            file               = rlpStream.DecodeString();
                QueryType         queryType          = (QueryType)rlpStream.DecodeInt();
                DataAssetState    state              = (DataAssetState)rlpStream.DecodeInt();
                string            termsAndConditions = rlpStream.DecodeString();
                bool              kycRequired        = rlpStream.DecodeBool();
                string            plugin             = rlpStream.DecodeString();

                return(new DataAsset(id, name, description, unitPrice, unitType, minUnits, maxUnits,
                                     rules, provider, file, queryType, state, termsAndConditions, kycRequired, plugin));
            }
            catch (Exception e)
            {
                throw new RlpException($"{nameof(DataAsset)} could not be deserialized", e);
            }
        }
コード例 #4
0
        public PingMessage Deserialize(byte[] msg)
        {
            (PingMessage Message, byte[] Mdc, byte[] Data)results = PrepareForDeserialization <PingMessage>(msg);

            RlpStream rlp = results.Data.AsRlpStream();

            rlp.ReadSequenceLength();
            int version = rlp.DecodeInt();

            rlp.ReadSequenceLength();
            byte[]     sourceAddress = rlp.DecodeByteArray();
            IPEndPoint source        = GetAddress(sourceAddress, rlp.DecodeInt());

            rlp.DecodeInt(); // UDP port
            rlp.ReadSequenceLength();
            byte[]     destinationAddress = rlp.DecodeByteArray();
            IPEndPoint destination        = GetAddress(destinationAddress, rlp.DecodeInt());

            rlp.DecodeInt(); // UDP port

            long expireTime = rlp.DecodeLong();

            PingMessage message = results.Message;

            message.SourceAddress      = source;
            message.DestinationAddress = destination;
            message.Mdc            = results.Mdc;
            message.Version        = version;
            message.ExpirationTime = expireTime;

            return(message);
        }
コード例 #5
0
        public ConsumerSession Decode(RlpStream rlpStream,
                                      RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            Keccak           id                        = rlpStream.DecodeKeccak();
            Keccak           depositId                 = rlpStream.DecodeKeccak();
            Keccak           dataAssetId               = rlpStream.DecodeKeccak();
            Address          consumerAddress           = rlpStream.DecodeAddress();
            PublicKey        consumerNodeId            = new PublicKey(rlpStream.DecodeByteArray());
            Address          providerAddress           = rlpStream.DecodeAddress();
            PublicKey        providerNodeId            = new PublicKey(rlpStream.DecodeByteArray());
            SessionState     state                     = (SessionState)rlpStream.DecodeInt();
            uint             startUnitsFromProvider    = rlpStream.DecodeUInt();
            uint             startUnitsFromConsumer    = rlpStream.DecodeUInt();
            ulong            startTimestamp            = rlpStream.DecodeUlong();
            ulong            finishTimestamp           = rlpStream.DecodeUlong();
            uint             consumedUnits             = rlpStream.DecodeUInt();
            uint             unpaidUnits               = rlpStream.DecodeUInt();
            uint             paidUnits                 = rlpStream.DecodeUInt();
            uint             settledUnits              = rlpStream.DecodeUInt();
            uint             consumedUnitsFromProvider = rlpStream.DecodeUInt();
            DataAvailability dataAvailability          = (DataAvailability)rlpStream.DecodeInt();

            return(new ConsumerSession(id, depositId, dataAssetId, consumerAddress, consumerNodeId, providerAddress,
                                       providerNodeId, state, startUnitsFromProvider, startUnitsFromConsumer, startTimestamp, finishTimestamp,
                                       consumedUnits, unpaidUnits, paidUnits, settledUnits, consumedUnitsFromProvider, dataAvailability));
        }
コード例 #6
0
        public DisconnectMessage Deserialize(byte[] bytes)
        {
            if (bytes.Length == 1)
            {
                return(new DisconnectMessage((DisconnectReason)bytes[0]));
            }

            if (bytes.SequenceEqual(breach1))
            {
                return(new DisconnectMessage(DisconnectReason.Breach1));
            }

            if (bytes.SequenceEqual(breach2))
            {
                return(new DisconnectMessage(DisconnectReason.Breach2));
            }

            RlpStream rlpStream = bytes.AsRlpStream();

            rlpStream.ReadSequenceLength();
            int reason = rlpStream.DecodeInt();
            DisconnectMessage disconnectMessage = new DisconnectMessage(reason);

            return(disconnectMessage);
        }
コード例 #7
0
        public PaymentClaim Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            _ = rlpStream.ReadSequenceLength();
            var id              = rlpStream.DecodeKeccak();
            var depositId       = rlpStream.DecodeKeccak();
            var assetId         = rlpStream.DecodeKeccak();
            var assetName       = rlpStream.DecodeString();
            var units           = rlpStream.DecodeUInt();
            var claimedUnits    = rlpStream.DecodeUInt();
            var unitsRange      = Nethermind.Serialization.Rlp.Rlp.Decode <UnitsRange>(rlpStream);
            var value           = rlpStream.DecodeUInt256();
            var claimedValue    = rlpStream.DecodeUInt256();
            var expiryTime      = rlpStream.DecodeUInt();
            var pepper          = rlpStream.DecodeByteArray();
            var provider        = rlpStream.DecodeAddress();
            var consumer        = rlpStream.DecodeAddress();
            var transactions    = Rlp.DecodeArray <TransactionInfo>(rlpStream);
            var transactionCost = rlpStream.DecodeUInt256();
            var timestamp       = rlpStream.DecodeUlong();
            var status          = (PaymentClaimStatus)rlpStream.DecodeInt();
            var signature       = SignatureDecoder.DecodeSignature(rlpStream);
            var paymentClaim    = new PaymentClaim(id, depositId, assetId, assetName, units, claimedUnits, unitsRange,
                                                   value, claimedValue, expiryTime, pepper, provider, consumer, signature, timestamp, transactions,
                                                   status);

            if (status == PaymentClaimStatus.Claimed)
            {
                paymentClaim.SetTransactionCost(transactionCost);
            }

            return(paymentClaim);
        }
コード例 #8
0
        private static ParityTraceAction DecodeAction(RlpStream rlpStream)
        {
            ParityTraceAction action = new ParityTraceAction();
            int sequenceLength       = rlpStream.ReadSequenceLength();

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

            return(action);
        }
コード例 #9
0
        public HelloMessage Deserialize(byte[] bytes)
        {
            RlpStream rlpStream = bytes.AsRlpStream();

            rlpStream.ReadSequenceLength();

            HelloMessage helloMessage = new HelloMessage();

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

            helloMessage.ListenPort = rlpStream.DecodeInt();

            byte[] publicKeyBytes = rlpStream.DecodeByteArray();
            if (publicKeyBytes.Length != PublicKey.LengthInBytes && publicKeyBytes.Length != PublicKey.PrefixedLengthInBytes)
            {
                throw new NetworkingException($"Client {helloMessage.ClientId} sent an invalid public key format (length was {publicKeyBytes.Length})", NetworkExceptionType.HandshakeOrInit);
            }
            else
            {
                helloMessage.NodeId = new PublicKey(publicKeyBytes);
            }

            return(helloMessage);
        }
コード例 #10
0
        private Dictionary <Address, Tally> DecodeTally(RlpStream rlpStream)
        {
            rlpStream.ReadSequenceLength();
            Dictionary <Address, Tally> tally = new Dictionary <Address, Tally>();
            int length = rlpStream.DecodeInt();

            for (int i = 0; i < length; i++)
            {
                Address address   = rlpStream.DecodeAddress();
                int     votes     = rlpStream.DecodeInt();
                bool    authorize = rlpStream.DecodeBool();
                Tally   tallyItem = new Tally(authorize);
                tallyItem.Votes = votes;
                tally[address]  = tallyItem;
            }
            return(tally);
        }
コード例 #11
0
        public FaucetResponse Decode(RlpStream rlpStream,
                                     RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            FaucetRequestStatus  status  = (FaucetRequestStatus)rlpStream.DecodeInt();
            FaucetRequestDetails request = Serialization.Rlp.Rlp.Decode <FaucetRequestDetails>(rlpStream);

            return(new FaucetResponse(status, request));
        }
        public DataAssetStateChangedMessage Deserialize(byte[] bytes)
        {
            RlpStream context = bytes.AsRlpStream();

            context.ReadSequenceLength();
            Keccak?        dataAssetId = context.DecodeKeccak();
            DataAssetState state       = (DataAssetState)context.DecodeInt();

            return(new DataAssetStateChangedMessage(dataAssetId, state));
        }
コード例 #13
0
        public DataAvailabilityMessage Deserialize(byte[] bytes)
        {
            RlpStream context = bytes.AsRlpStream();

            context.ReadSequenceLength();
            Keccak?          depositId = context.DecodeKeccak();
            DataAvailability reason    = (DataAvailability)context.DecodeInt();

            return(new DataAvailabilityMessage(depositId, reason));
        }
コード例 #14
0
        public static ContractCodesMessage Deserialize(RlpStream rlpStream)
        {
            ContractCodesMessage contractCodesMessage = new ContractCodesMessage();

            rlpStream.ReadSequenceLength();
            contractCodesMessage.RequestId   = rlpStream.DecodeLong();
            contractCodesMessage.BufferValue = rlpStream.DecodeInt();
            contractCodesMessage.Codes       = rlpStream.DecodeArray(stream => stream.DecodeByteArray());
            return(contractCodesMessage);
        }
コード例 #15
0
        private static BlockBodiesMessage Deserialize(RlpStream rlpStream)
        {
            BlockBodiesMessage blockBodiesMessage = new BlockBodiesMessage();

            rlpStream.ReadSequenceLength();
            blockBodiesMessage.RequestId   = rlpStream.DecodeLong();
            blockBodiesMessage.BufferValue = rlpStream.DecodeInt();
            blockBodiesMessage.EthMessage  = Eth.V62.BlockBodiesMessageSerializer.Deserialize(rlpStream);
            return(blockBodiesMessage);
        }
コード例 #16
0
    public PingMsg Deserialize(byte[] msgBytes)
    {
        (PublicKey FarPublicKey, byte[] Mdc, byte[] Data)results = PrepareForDeserialization(msgBytes);
        RlpStream rlp = results.Data.AsRlpStream();

        rlp.ReadSequenceLength();
        int version = rlp.DecodeInt();

        rlp.ReadSequenceLength();
        ReadOnlySpan <byte> sourceAddress = rlp.DecodeByteArraySpan();

        // TODO: please note that we decode only one field for port and if the UDP is different from TCP then
        // our discovery messages will not be routed correctly (the fix will not be part of this commit)
        rlp.DecodeInt();               // UDP port
        int tcpPort = rlp.DecodeInt(); // we assume here that UDP and TCP port are same

        IPEndPoint source = GetAddress(sourceAddress, tcpPort);

        rlp.ReadSequenceLength();
        ReadOnlySpan <byte> destinationAddress = rlp.DecodeByteArraySpan();
        IPEndPoint          destination        = GetAddress(destinationAddress, rlp.DecodeInt());

        rlp.DecodeInt(); // UDP port

        long    expireTime = rlp.DecodeLong();
        PingMsg msg        = new(results.FarPublicKey, expireTime, source, destination, results.Mdc);

        msg.Version = version;
        if (version == 4)
        {
            if (!rlp.HasBeenRead)
            {
                long enrSequence = rlp.DecodeLong();
                msg.EnrSequence = enrSequence;
            }
        }
        else
        {
            // what do we do when receive version 5?
        }

        return(msg);
    }
コード例 #17
0
    public PongMsg Deserialize(byte[] msgBytes)
    {
        (PublicKey FarPublicKey, byte[] Mdc, byte[] Data)results = PrepareForDeserialization(msgBytes);

        RlpStream rlp = results.Data.AsRlpStream();

        rlp.ReadSequenceLength();
        rlp.ReadSequenceLength();

        // GetAddress(rlp.DecodeByteArray(), rlp.DecodeInt());
        rlp.DecodeByteArraySpan();
        rlp.DecodeInt(); // UDP port (we ignore and take it from Netty)
        rlp.DecodeInt(); // TCP port
        byte[] token          = rlp.DecodeByteArray();
        long   expirationTime = rlp.DecodeLong();

        PongMsg msg = new(results.FarPublicKey, expirationTime, token);

        return(msg);
    }
コード例 #18
0
        public static GetBlockHeadersMessage Deserialize(RlpStream rlpStream)
        {
            GetBlockHeadersMessage message = new();

            rlpStream.ReadSequenceLength();
            byte[] startingBytes = rlpStream.DecodeByteArray();
            if (startingBytes.Length == 32)
            {
                message.StartBlockHash = new Keccak(startingBytes);
            }
            else
            {
                message.StartBlockNumber = (long)new UInt256(startingBytes, true);
            }

            message.MaxHeaders = rlpStream.DecodeInt();
            message.Skip       = rlpStream.DecodeInt();
            message.Reverse    = rlpStream.DecodeByte();
            return(message);
        }
コード例 #19
0
        public TransactionInfo Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            try
            {
                Keccak           hash      = rlpStream.DecodeKeccak();
                UInt256          value     = rlpStream.DecodeUInt256();
                UInt256          gasPrice  = rlpStream.DecodeUInt256();
                ulong            gasLimit  = rlpStream.DecodeUlong();
                ulong            timestamp = rlpStream.DecodeUlong();
                TransactionType  type      = (TransactionType)rlpStream.DecodeInt();
                TransactionState state     = (TransactionState)rlpStream.DecodeInt();

                return(new TransactionInfo(hash, value, gasPrice, gasLimit, timestamp, type, state));
            }
            catch (Exception e)
            {
                throw new RlpException($"{nameof(TransactionInfo)} could not be decoded", e);
            }
        }
コード例 #20
0
        public HelperTrieProofsMessage Deserialize(RlpStream rlpStream)
        {
            HelperTrieProofsMessage message = new HelperTrieProofsMessage();

            rlpStream.ReadSequenceLength();
            message.RequestId   = rlpStream.DecodeLong();
            message.BufferValue = rlpStream.DecodeInt();
            rlpStream.ReadSequenceLength();
            message.ProofNodes    = rlpStream.DecodeArray(stream => stream.DecodeByteArray());
            message.AuxiliaryData = rlpStream.DecodeArray(stream => stream.DecodeByteArray());
            return(message);
        }
コード例 #21
0
        private static GetBlockHeadersMessage Deserialize(RlpStream rlpStream)
        {
            GetBlockHeadersMessage message = new GetBlockHeadersMessage();

            rlpStream.ReadSequenceLength();
            byte[] startingBytes = rlpStream.DecodeByteArray();
            if (startingBytes.Length == 32)
            {
                message.StartingBlockHash = new Keccak(startingBytes);
            }
            else
            {
                UInt256.CreateFromBigEndian(out UInt256 result, startingBytes);
                message.StartingBlockNumber = (long)result;
            }

            message.MaxHeaders = rlpStream.DecodeInt();
            message.Skip       = rlpStream.DecodeInt();
            message.Reverse    = rlpStream.DecodeByte();
            return(message);
        }
コード例 #22
0
        public ReceiptsMessage Deserialize(RlpStream rlpStream)
        {
            ReceiptsMessage receiptsMessage = new ReceiptsMessage();

            Eth.V63.ReceiptsMessageSerializer ethSerializer = new Eth.V63.ReceiptsMessageSerializer(_specProvider);

            rlpStream.ReadSequenceLength();
            receiptsMessage.RequestId   = rlpStream.DecodeLong();
            receiptsMessage.BufferValue = rlpStream.DecodeInt();
            receiptsMessage.EthMessage  = ethSerializer.Deserialize(rlpStream);
            return(receiptsMessage);
        }
コード例 #23
0
 public AuthEip8Message Deserialize(byte[] data)
 {
     RlpStream rlpStream = data.AsRlpStream();
     AuthEip8Message authMessage = new AuthEip8Message();
     rlpStream.ReadSequenceLength();
     byte[] sigAllBytes = rlpStream.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(rlpStream.DecodeByteArray());
     authMessage.Nonce = rlpStream.DecodeByteArray();
     int version = rlpStream.DecodeInt();
     return authMessage;
 }
コード例 #24
0
        public DepositApproval Decode(RlpStream rlpStream,
                                      RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            Keccak  assetId            = rlpStream.DecodeKeccak();
            string  assetName          = rlpStream.DecodeString();
            string  kyc                = rlpStream.DecodeString();
            Address consumer           = rlpStream.DecodeAddress();
            Address provider           = rlpStream.DecodeAddress();
            ulong   timestamp          = rlpStream.DecodeUlong();
            DepositApprovalState state = (DepositApprovalState)rlpStream.DecodeInt();

            return(new DepositApproval(assetId, assetName, kyc, consumer, provider, timestamp, state));
        }
コード例 #25
0
        public PongMessage Deserialize(byte[] msg)
        {
            (PongMessage Message, byte[] Mdc, byte[] Data)results = PrepareForDeserialization <PongMessage>(msg);

            RlpStream rlp = results.Data.AsRlpStream();

            rlp.ReadSequenceLength();
            rlp.ReadSequenceLength();

            // GetAddress(rlp.DecodeByteArray(), rlp.DecodeInt());
            rlp.DecodeByteArray();
            rlp.DecodeInt(); // UDP port (we ignore and take it from Netty)
            rlp.DecodeInt(); // TCP port
            byte[] token          = rlp.DecodeByteArray();
            long   expirationTime = rlp.DecodeLong();

            PongMessage message = results.Message;

            message.PingMdc        = token;
            message.ExpirationTime = expirationTime;

            return(message);
        }
コード例 #26
0
        public PingMessage Deserialize(byte[] msg)
        {
            (PingMessage Message, byte[] Mdc, byte[] Data)results = PrepareForDeserialization <PingMessage>(msg);

            RlpStream rlp = results.Data.AsRlpStream();

            rlp.ReadSequenceLength();
            int version = rlp.DecodeInt();

            rlp.ReadSequenceLength();
            ReadOnlySpan <byte> sourceAddress = rlp.DecodeByteArraySpan();

            // TODO: please note that we decode only one field for port and if the UDP is different from TCP then
            // our discovery messages will not be routed correctly (the fix will not be part of this commit)
            rlp.DecodeInt();               // UDP port
            int tcpPort = rlp.DecodeInt(); // we assume here that UDP and TCP port are same

            IPEndPoint source = GetAddress(sourceAddress, tcpPort);

            rlp.ReadSequenceLength();
            ReadOnlySpan <byte> destinationAddress = rlp.DecodeByteArraySpan();
            IPEndPoint          destination        = GetAddress(destinationAddress, rlp.DecodeInt());

            rlp.DecodeInt(); // UDP port

            long expireTime = rlp.DecodeLong();

            PingMessage message = results.Message;

            message.SourceAddress      = source;
            message.DestinationAddress = destination;
            message.Mdc            = results.Mdc;
            message.Version        = version;
            message.ExpirationTime = expireTime;

            return(message);
        }
コード例 #27
0
        private SortedList <Address, long> DecodeSigners(RlpStream rlpStream)
        {
            rlpStream.ReadSequenceLength();
            SortedList <Address, long> signers = new SortedList <Address, long>(AddressComparer.Instance);
            int length = rlpStream.DecodeInt();

            for (int i = 0; i < length; i++)
            {
                Address signer   = rlpStream.DecodeAddress();
                long    signedAt = (long)rlpStream.DecodeUInt256();
                signers.Add(signer, signedAt);
            }

            return(signers);
        }
コード例 #28
0
        public FaucetResponse Decode(RlpStream rlpStream,
                                     RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var status  = (FaucetRequestStatus)rlpStream.DecodeInt();
            var request = Nethermind.Core.Encoding.Rlp.Decode <FaucetRequestDetails>(rlpStream);

            return(new FaucetResponse(status, request));
        }
コード例 #29
0
        public AuthEip8Message Deserialize(byte[] msgBytes)
        {
            RlpStream       rlpStream   = msgBytes.AsRlpStream();
            AuthEip8Message authMessage = new();

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

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

            return(authMessage);
        }
コード例 #30
0
        public DataDeliveryReceipt Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            try
            {
                rlpStream.ReadSequenceLength();
                StatusCodes statusCode    = (StatusCodes)rlpStream.DecodeInt();
                uint        consumedUnits = rlpStream.DecodeUInt();
                uint        unpaidUnits   = rlpStream.DecodeUInt();
                Signature   signature     = SignatureDecoder.DecodeSignature(rlpStream);

                return(new DataDeliveryReceipt(statusCode, consumedUnits, unpaidUnits, signature));
            }
            catch (Exception e)
            {
                throw new RlpException($"{nameof(DataDeliveryReceiptDecoder)} could not be decoded", e);
            }
        }