public void Encode(RlpStream stream, DataAssetProvider item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new NotImplementedException();
 }
Example #2
0
 public static GetReceiptsMessage Deserialize(RlpStream rlpStream)
 {
     Keccak[] hashes = DeserializeHashes(rlpStream);
     return(new GetReceiptsMessage(hashes));
 }
Example #3
0
 protected static Keccak[] DeserializeHashes(RlpStream rlpStream)
 {
     Keccak[] hashes = rlpStream.DecodeArray(itemContext => itemContext.DecodeKeccak());
     return(hashes);
 }
Example #4
0
        public DepositDetails Decode(RlpStream rlpStream,
                                     RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            try
            {
                var sequenceLength = rlpStream.ReadSequenceLength();
                if (sequenceLength == 0)
                {
                    return(null);
                }

                var deposit                      = Nethermind.Core.Encoding.Rlp.Decode <Deposit>(rlpStream);
                var dataAsset                    = Nethermind.Core.Encoding.Rlp.Decode <DataAsset>(rlpStream);
                var consumer                     = rlpStream.DecodeAddress();
                var pepper                       = rlpStream.DecodeByteArray();
                var timestamp                    = rlpStream.DecodeUInt();
                var transactionHash              = rlpStream.DecodeKeccak();
                var confirmationTimestamp        = rlpStream.DecodeUInt();
                var rejected                     = rlpStream.DecodeBool();
                var earlyRefundTicket            = Nethermind.Core.Encoding.Rlp.Decode <EarlyRefundTicket>(rlpStream);
                var claimedRefundTransactionHash = rlpStream.DecodeKeccak();
                var refundClaimed                = rlpStream.DecodeBool();
                var kyc                   = rlpStream.DecodeString();
                var confirmations         = rlpStream.DecodeUInt();
                var requiredConfirmations = rlpStream.DecodeUInt();

                return(new DepositDetails(deposit, dataAsset, consumer, pepper, timestamp, transactionHash,
                                          confirmationTimestamp, rejected, earlyRefundTicket, claimedRefundTransactionHash, refundClaimed,
                                          kyc, confirmations, requiredConfirmations));
            }
            catch (Exception)
            {
                rlpStream.Position = 0;
                var sequenceLength = rlpStream.ReadSequenceLength();
                if (sequenceLength == 0)
                {
                    return(null);
                }

                var  deposit                      = Nethermind.Core.Encoding.Rlp.Decode <Deposit>(rlpStream);
                var  dataAsset                    = Nethermind.Core.Encoding.Rlp.Decode <DataAsset>(rlpStream);
                var  consumer                     = rlpStream.DecodeAddress();
                var  pepper                       = rlpStream.DecodeByteArray();
                var  transactionHash              = rlpStream.DecodeKeccak();
                var  confirmationTimestamp        = rlpStream.DecodeUInt();
                var  rejected                     = rlpStream.DecodeBool();
                var  earlyRefundTicket            = Nethermind.Core.Encoding.Rlp.Decode <EarlyRefundTicket>(rlpStream);
                var  claimedRefundTransactionHash = rlpStream.DecodeKeccak();
                var  refundClaimed                = rlpStream.DecodeBool();
                var  kyc                   = rlpStream.DecodeString();
                var  confirmations         = rlpStream.DecodeUInt();
                var  requiredConfirmations = rlpStream.DecodeUInt();
                uint timestamp             = 0;
                if (rlpStream.Position != rlpStream.Data.Length)
                {
                    timestamp = rlpStream.DecodeUInt();
                }

                return(new DepositDetails(deposit, dataAsset, consumer, pepper, timestamp, transactionHash,
                                          confirmationTimestamp, rejected, earlyRefundTicket, claimedRefundTransactionHash, refundClaimed,
                                          kyc, confirmations, requiredConfirmations));
            }
        }
Example #5
0
 public void Encode(RlpStream stream, FaucetResponse item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new System.NotImplementedException();
 }
 public void Encode(RlpStream stream, DepositDetails item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new System.NotImplementedException();
 }
Example #7
0
 public void Encode(RlpStream stream, EthRequest item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new NotImplementedException();
 }
Example #8
0
        public NewBlockHashesMessage Deserialize(byte[] bytes)
        {
            RlpStream rlpStream = bytes.AsRlpStream();

            return(Deserialize(rlpStream));
        }
Example #9
0
 public void Encode(RlpStream stream, DataAssetRule?item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new System.NotImplementedException();
 }
Example #10
0
 public Transaction[] DeserializeTxs(RlpStream rlpStream)
 {
     return(Rlp.DecodeArray <Transaction>(rlpStream));
 }
        private static StatusMessage Deserialize(RlpStream rlpStream)
        {
            StatusMessage statusMessage = new StatusMessage();

            (int prefixLength, int contentLength) = rlpStream.PeekPrefixAndContentLength();
            var totalLength = contentLength;

            rlpStream.Position += prefixLength;
            var readLength = prefixLength;

            while (totalLength > readLength)
            {
                (prefixLength, contentLength) = rlpStream.PeekPrefixAndContentLength();
                readLength         += prefixLength + contentLength;
                rlpStream.Position += prefixLength;
                string key = rlpStream.DecodeString();
                switch (key)
                {
                case StatusMessage.KeyNames.ProtocolVersion:
                    statusMessage.ProtocolVersion = rlpStream.DecodeByte();
                    break;

                case StatusMessage.KeyNames.ChainId:
                    statusMessage.ChainId = rlpStream.DecodeUInt256();
                    break;

                case StatusMessage.KeyNames.TotalDifficulty:
                    statusMessage.TotalDifficulty = rlpStream.DecodeUInt256();
                    break;

                case StatusMessage.KeyNames.BestHash:
                    statusMessage.BestHash = rlpStream.DecodeKeccak();
                    break;

                case StatusMessage.KeyNames.HeadBlockNo:
                    statusMessage.HeadBlockNo = rlpStream.DecodeLong();
                    break;

                case StatusMessage.KeyNames.GenesisHash:
                    statusMessage.GenesisHash = rlpStream.DecodeKeccak();
                    break;

                case StatusMessage.KeyNames.AnnounceType:
                    statusMessage.AnnounceType = rlpStream.DecodeByte();
                    break;

                case StatusMessage.KeyNames.ServeHeaders:
                    statusMessage.ServeHeaders = true;
                    rlpStream.SkipItem();
                    break;

                case StatusMessage.KeyNames.ServeChainSince:
                    statusMessage.ServeChainSince = rlpStream.DecodeLong();
                    break;

                case StatusMessage.KeyNames.ServeRecentChain:
                    statusMessage.ServeRecentChain = rlpStream.DecodeLong();
                    break;

                case StatusMessage.KeyNames.ServeStateSince:
                    statusMessage.ServeStateSince = rlpStream.DecodeLong();
                    break;

                case StatusMessage.KeyNames.ServeRecentState:
                    statusMessage.ServeRecentState = rlpStream.DecodeLong();
                    break;

                case StatusMessage.KeyNames.TxRelay:
                    statusMessage.TxRelay = true;
                    rlpStream.SkipItem();
                    break;

                case StatusMessage.KeyNames.BufferLimit:
                    statusMessage.BufferLimit = rlpStream.DecodeInt();
                    break;

                case StatusMessage.KeyNames.MaximumRechargeRate:
                    statusMessage.MaximumRechargeRate = rlpStream.DecodeInt();
                    break;

                case StatusMessage.KeyNames.MaximumRequestCosts:
                // todo
                default:
                    // Ignore unknown keys
                    rlpStream.Position = readLength;
                    break;
                }
            }

            return(statusMessage);
        }
 public void Encode(RlpStream stream, PaymentClaim item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new System.NotImplementedException();
 }
Example #13
0
 public TrieNode(NodeType nodeType, Rlp rlp)
 {
     NodeType   = nodeType;
     FullRlp    = rlp;
     _rlpStream = rlp.Bytes.AsRlpStream();
 }
Example #14
0
        private Dictionary <UInt256, ParityStateChange <byte[]> > DecodeStorageChange(RlpStream rlpStream)
        {
            int checkpoint = rlpStream.ReadSequenceLength();
            var change     = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            int itemsCount = rlpStream.ReadNumberOfItemsRemaining(rlpStream.Position + checkpoint);

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

            for (int i = 0; i < itemsCount; i = i + 2)
            {
                change[rlpStream.DecodeUInt256()] = DecodeByteChange(rlpStream);
            }

            return(change);
        }
 private static GetBlockBodiesMessage Deserialize(RlpStream rlpStream)
 {
     Keccak[] hashes = rlpStream.DecodeArray(ctx => rlpStream.DecodeKeccak(), false);
     return(new GetBlockBodiesMessage(hashes));
 }
Example #16
0
 /// <summary>
 /// Encodes the entry into an RLP stream.
 /// </summary>
 public void Encode(RlpStream rlpStream)
 {
     rlpStream.Encode(Key);
     EncodeValue(rlpStream);
 }
 private static NewBlockHashesMessage Deserialize(RlpStream rlpStream)
 {
     (Keccak, long)[] blockHashes = rlpStream.DecodeArray(ctx =>
Example #18
0
 protected abstract void EncodeValue(RlpStream rlpStream);
Example #19
0
    /// <summary>
    /// Deserializes a <see cref="NodeRecord"/> from an <see cref="RlpStream"/>.
    /// </summary>
    /// <param name="rlpStream">A stream to read the serialized data from.</param>
    /// <returns>A deserialized <see cref="NodeRecord"/></returns>
    public NodeRecord Deserialize(RlpStream rlpStream)
    {
        int startPosition   = rlpStream.Position;
        int recordRlpLength = rlpStream.ReadSequenceLength();

        NodeRecord nodeRecord = new();

        ReadOnlySpan <byte> sigBytes  = rlpStream.DecodeByteArraySpan();
        Signature           signature = new(sigBytes, 0);

        bool canVerify   = true;
        long enrSequence = rlpStream.DecodeLong();

        while (rlpStream.Position < startPosition + recordRlpLength)
        {
            string key = rlpStream.DecodeString();
            switch (key)
            {
            case EnrContentKey.Eth:
                _ = rlpStream.ReadSequenceLength();
                _ = rlpStream.ReadSequenceLength();
                byte[] forkHash  = rlpStream.DecodeByteArray();
                long   nextBlock = rlpStream.DecodeLong();
                nodeRecord.SetEntry(new EthEntry(forkHash, nextBlock));
                break;

            case EnrContentKey.Id:
                rlpStream.SkipItem();
                nodeRecord.SetEntry(IdEntry.Instance);
                break;

            case EnrContentKey.Ip:
                ReadOnlySpan <byte> ipBytes = rlpStream.DecodeByteArraySpan();
                IPAddress           address = new(ipBytes);
                nodeRecord.SetEntry(new IpEntry(address));
                break;

            case EnrContentKey.Tcp:
                int tcpPort = rlpStream.DecodeInt();
                nodeRecord.SetEntry(new TcpEntry(tcpPort));
                break;

            case EnrContentKey.Udp:
                int udpPort = rlpStream.DecodeInt();
                nodeRecord.SetEntry(new UdpEntry(udpPort));
                break;

            case EnrContentKey.Secp256K1:
                ReadOnlySpan <byte> keyBytes    = rlpStream.DecodeByteArraySpan();
                CompressedPublicKey reportedKey = new(keyBytes);
                nodeRecord.SetEntry(new Secp256K1Entry(reportedKey));
                break;

            // snap
            default:
                canVerify = false;
                rlpStream.SkipItem();
                nodeRecord.Snap = true;
                break;
            }
        }

        if (!canVerify)
        {
            rlpStream.Position = startPosition;
            rlpStream.ReadSequenceLength();
            rlpStream.SkipItem(); // signature
            int       noSigContentLength    = rlpStream.Length - rlpStream.Position;
            int       noSigSequenceLength   = Rlp.LengthOfSequence(noSigContentLength);
            byte[]    originalContent       = new byte[noSigSequenceLength];
            RlpStream originalContentStream = new (originalContent);
            originalContentStream.StartSequence(noSigContentLength);
            originalContentStream.Write(rlpStream.Read(noSigContentLength));
            rlpStream.Position            = startPosition;
            nodeRecord.OriginalContentRlp = originalContentStream.Data !;
        }

        nodeRecord.EnrSequence = enrSequence;
        nodeRecord.Signature   = signature;

        return(nodeRecord);
    }
        public GetBlockHeadersMessage Deserialize(byte[] bytes)
        {
            RlpStream rlpStream = bytes.AsRlpStream();

            return(Deserialize(rlpStream));
        }
Example #21
0
        public NdmConfig Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var enabled                          = rlpStream.DecodeBool();
            var id                               = rlpStream.DecodeString();
            var initializerName                  = rlpStream.DecodeString();
            var storeConfigInDatabase            = rlpStream.DecodeBool();
            var verifyP2PSignature               = rlpStream.DecodeBool();
            var persistence                      = rlpStream.DecodeString();
            var faucetEnabled                    = rlpStream.DecodeBool();
            var faucetAddress                    = rlpStream.DecodeString();
            var faucetHost                       = rlpStream.DecodeString();
            var faucetWeiRequestMaxValue         = rlpStream.DecodeUInt256();
            var faucetEthDailyRequestsTotalValue = rlpStream.DecodeUInt256();
            var consumerAddress                  = rlpStream.DecodeString();
            var contractAddress                  = rlpStream.DecodeString();
            var providerName                     = rlpStream.DecodeString();
            var providerAddress                  = rlpStream.DecodeString();
            var providerColdWalletAddress        = rlpStream.DecodeString();
            var receiptRequestThreshold          = rlpStream.DecodeUInt256();
            var receiptsMergeThreshold           = rlpStream.DecodeUInt256();
            var paymentClaimThreshold            = rlpStream.DecodeUInt256();
            var blockConfirmations               = rlpStream.DecodeUInt();
            var filesPath                        = rlpStream.DecodeString();
            var fileMaxSize                      = rlpStream.DecodeUlong();
            var pluginsPath                      = rlpStream.DecodeString();
            var databasePath                     = rlpStream.DecodeString();
            var proxyEnabled                     = rlpStream.DecodeBool();
            var jsonRpcUrlProxies                = rlpStream.DecodeArray(c => c.DecodeString());
            var gasPriceType                     = rlpStream.DecodeString();
            var gasPrice                         = rlpStream.DecodeUInt256();
            var cancelTransactionGasPricePercentageMultiplier = rlpStream.DecodeUInt();
            var jsonRpcDataChannelEnabled = rlpStream.DecodeBool();

            return(new NdmConfig
            {
                Enabled = enabled,
                Id = id,
                InitializerName = initializerName,
                StoreConfigInDatabase = storeConfigInDatabase,
                VerifyP2PSignature = verifyP2PSignature,
                Persistence = persistence,
                FaucetEnabled = faucetEnabled,
                FaucetAddress = faucetAddress,
                FaucetHost = faucetHost,
                FaucetWeiRequestMaxValue = faucetWeiRequestMaxValue,
                FaucetEthDailyRequestsTotalValue = faucetEthDailyRequestsTotalValue,
                ConsumerAddress = consumerAddress,
                ContractAddress = contractAddress,
                ProviderName = providerName,
                ProviderAddress = providerAddress,
                ProviderColdWalletAddress = providerColdWalletAddress,
                ReceiptRequestThreshold = receiptRequestThreshold,
                ReceiptsMergeThreshold = receiptsMergeThreshold,
                PaymentClaimThreshold = paymentClaimThreshold,
                BlockConfirmations = blockConfirmations,
                FilesPath = filesPath,
                FileMaxSize = fileMaxSize,
                PluginsPath = pluginsPath,
                DatabasePath = databasePath,
                ProxyEnabled = proxyEnabled,
                JsonRpcUrlProxies = jsonRpcUrlProxies,
                GasPriceType = gasPriceType,
                GasPrice = gasPrice,
                CancelTransactionGasPricePercentageMultiplier = cancelTransactionGasPricePercentageMultiplier,
                JsonRpcDataChannelEnabled = jsonRpcDataChannelEnabled
            });
        }
Example #22
0
 public TrieNode(NodeType nodeType, byte[] rlp)
 {
     NodeType   = nodeType;
     FullRlp    = rlp;
     _rlpStream = rlp.AsRlpStream();
 }
Example #23
0
 protected override void EncodeValue(RlpStream rlpStream)
 {
     rlpStream.Encode(Value);
 }
 public void Encode(RlpStream stream, NetworkNode item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     throw new NotImplementedException();
 }