public DataAssetProvider Decode(RlpStream rlpStream,
                                 RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     try
     {
         rlpStream.ReadSequenceLength();
         Address address = rlpStream.DecodeAddress();
         string  name    = rlpStream.DecodeString();
         return(new DataAssetProvider(address, name));
     }
     catch (Exception e)
     {
         throw new RlpException($"{nameof(DataAssetProvider)} cannot be deserialized from", e);
     }
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public DataAssetProvider Decode(RlpStream rlpStream,
                                        RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var address = rlpStream.DecodeAddress();
            var name    = rlpStream.DecodeString();

            return(new DataAssetProvider(address, name));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// We pay a high code quality tax for the performance optimization on RLP.
        /// Adding more RLP decoders is costly (time wise) but the path taken saves a lot of allocations and GC.
        /// Shall we consider code generation for this? We could potentially generate IL from attributes for each
        /// RLP serializable item and keep it as a compiled call available at runtime.
        /// It would be slightly slower but still much faster than what we would get from using dynamic serializers.
        /// </summary>
        public AccessList?Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (rlpStream.IsNextItemNull())
            {
                rlpStream.ReadByte();
                return(null);
            }

            int length = rlpStream.PeekNextRlpLength();
            int check  = rlpStream.Position + length;

            rlpStream.SkipLength();

            AccessListBuilder accessListBuilder = new();

            while (rlpStream.Position < check)
            {
                rlpStream.SkipLength();
                Address address = rlpStream.DecodeAddress();
                if (address == null)
                {
                    throw new RlpException("Invalid tx access list format - address is null");
                }

                accessListBuilder.AddAddress(address);

                if (rlpStream.Position < check)
                {
                    int storageCheck = rlpStream.Position + rlpStream.PeekNextRlpLength();
                    rlpStream.SkipLength();
                    while (rlpStream.Position < storageCheck)
                    {
                        UInt256 index = rlpStream.DecodeUInt256();
                        accessListBuilder.AddStorage(index);
                    }
                }
            }

            if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData)
            {
                rlpStream.Check(check);
            }

            return(accessListBuilder.ToAccessList());
        }
Ejemplo n.º 6
0
        private Dictionary <Address, ParityAccountStateChange> DecodeStateDiff(RlpStream rlpStream)
        {
            var accountStateChange = new Dictionary <Address, ParityAccountStateChange>();
            int checkpoint         = rlpStream.ReadSequenceLength();
            int items = rlpStream.ReadNumberOfItemsRemaining(rlpStream.Position + checkpoint);

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

            for (int i = 0; i < items; i = i + 2)
            {
                accountStateChange[rlpStream.DecodeAddress()] = DecodeAccountStateChange(rlpStream);
            }

            return(accountStateChange);
        }
        public FaucetRequestDetails Decode(RlpStream rlpStream,
                                           RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var host            = rlpStream.DecodeString();
            var address         = rlpStream.DecodeAddress();
            var value           = rlpStream.DecodeUInt256();
            var date            = DateTimeOffset.FromUnixTimeSeconds(rlpStream.DecodeLong()).UtcDateTime;
            var transactionHash = rlpStream.DecodeKeccak();

            return(new FaucetRequestDetails(host, address, value, date, transactionHash));
        }
        public FaucetRequestDetails Decode(RlpStream rlpStream,
                                           RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            int sequenceLength = rlpStream.ReadSequenceLength();

            if (sequenceLength == 0)
            {
                return(FaucetRequestDetails.Empty);
            }

            string   host            = rlpStream.DecodeString();
            Address  address         = rlpStream.DecodeAddress();
            UInt256  value           = rlpStream.DecodeUInt256();
            DateTime date            = DateTimeOffset.FromUnixTimeSeconds(rlpStream.DecodeLong()).UtcDateTime;
            Keccak   transactionHash = rlpStream.DecodeKeccak();

            return(new FaucetRequestDetails(host, address, value, date, transactionHash));
        }
Ejemplo n.º 9
0
        public EthRequest Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            try
            {
                rlpStream.ReadSequenceLength();
                Keccak   id              = rlpStream.DecodeKeccak();
                string   host            = rlpStream.DecodeString();
                Address  address         = rlpStream.DecodeAddress();
                UInt256  value           = rlpStream.DecodeUInt256();
                DateTime requestedAt     = DateTimeOffset.FromUnixTimeSeconds(rlpStream.DecodeLong()).UtcDateTime;
                Keccak   transactionHash = rlpStream.DecodeKeccak();

                return(new EthRequest(id, host, address, value, requestedAt, transactionHash));
            }
            catch (Exception e)
            {
                throw new RlpException($"{nameof(EthRequest)} cannot be deserialized from", e);
            }
        }
Ejemplo n.º 10
0
        public DepositDetails Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            Deposit           deposit                   = Serialization.Rlp.Rlp.Decode <Deposit>(rlpStream);
            DataAsset         dataAsset                 = Serialization.Rlp.Rlp.Decode <DataAsset>(rlpStream);
            Address           consumer                  = rlpStream.DecodeAddress();
            var               pepper                    = rlpStream.DecodeByteArray();
            uint              timestamp                 = rlpStream.DecodeUInt();
            var               transactions              = Serialization.Rlp.Rlp.DecodeArray <TransactionInfo>(rlpStream);
            uint              confirmationTimestamp     = rlpStream.DecodeUInt();
            bool              rejected                  = rlpStream.DecodeBool();
            bool              cancelled                 = rlpStream.DecodeBool();
            EarlyRefundTicket earlyRefundTicket         = Serialization.Rlp.Rlp.Decode <EarlyRefundTicket>(rlpStream);
            var               claimedRefundTransactions = Serialization.Rlp.Rlp.DecodeArray <TransactionInfo>(rlpStream);
            bool              refundClaimed             = rlpStream.DecodeBool();
            bool              refundCancelled           = rlpStream.DecodeBool();
            string            kyc                   = rlpStream.DecodeString();
            uint              confirmations         = rlpStream.DecodeUInt();
            uint              requiredConfirmations = rlpStream.DecodeUInt();

            return(new DepositDetails(deposit, dataAsset, consumer, pepper, timestamp, transactions,
                                      confirmationTimestamp, rejected, cancelled, earlyRefundTicket, claimedRefundTransactions,
                                      refundClaimed, refundCancelled, kyc, confirmations, requiredConfirmations));
        }
Ejemplo n.º 11
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 transaction              = Nethermind.Core.Encoding.Rlp.Decode <TransactionInfo>(rlpStream);
                var confirmationTimestamp    = rlpStream.DecodeUInt();
                var rejected                 = rlpStream.DecodeBool();
                var earlyRefundTicket        = Nethermind.Core.Encoding.Rlp.Decode <EarlyRefundTicket>(rlpStream);
                var claimedRefundTransaction = Nethermind.Core.Encoding.Rlp.Decode <TransactionInfo>(rlpStream);
                var refundClaimed            = rlpStream.DecodeBool();
                var kyc                   = rlpStream.DecodeString();
                var confirmations         = rlpStream.DecodeUInt();
                var requiredConfirmations = rlpStream.DecodeUInt();

                return(new DepositDetails(deposit, dataAsset, consumer, pepper, timestamp, transaction,
                                          confirmationTimestamp, rejected, earlyRefundTicket, claimedRefundTransaction, 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  transaction              = Nethermind.Core.Encoding.Rlp.Decode <TransactionInfo>(rlpStream);
                var  confirmationTimestamp    = rlpStream.DecodeUInt();
                var  rejected                 = rlpStream.DecodeBool();
                var  earlyRefundTicket        = Nethermind.Core.Encoding.Rlp.Decode <EarlyRefundTicket>(rlpStream);
                var  claimedRefundTransaction = Nethermind.Core.Encoding.Rlp.Decode <TransactionInfo>(rlpStream);
                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, transaction,
                                          confirmationTimestamp, rejected, earlyRefundTicket, claimedRefundTransaction, refundClaimed, kyc,
                                          confirmations, requiredConfirmations));
            }
        }