Exemplo n.º 1
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();

            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
            });
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        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;

                default:
                    // Ignore unknown keys - forwards compatibility
                    rlpStream.Position = readLength;
                    break;
                }
            }

            return(statusMessage);
        }
Exemplo n.º 5
0
        private static StatusMessage Deserialize(RlpStream rlpStream)
        {
            StatusMessage statusMessage = new StatusMessage();

            rlpStream.ReadSequenceLength();
            statusMessage.ProtocolVersion = rlpStream.DecodeByte();
            statusMessage.ChainId         = rlpStream.DecodeUInt256();
            statusMessage.TotalDifficulty = rlpStream.DecodeUInt256();
            statusMessage.BestHash        = rlpStream.DecodeKeccak();
            statusMessage.GenesisHash     = rlpStream.DecodeKeccak();
            return(statusMessage);
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public TransactionInfo Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var hash      = rlpStream.DecodeKeccak();
            var value     = rlpStream.DecodeUInt256();
            var gasPrice  = rlpStream.DecodeUInt256();
            var timestamp = rlpStream.DecodeUlong();
            var state     = (TransactionState)rlpStream.DecodeInt();

            return(new TransactionInfo(hash, value, gasPrice, timestamp, state));
        }
        private static NewBlockMessage Deserialize(RlpStream rlpStream)
        {
            NewBlockMessage message = new NewBlockMessage();

            rlpStream.ReadSequenceLength();
            message.Block           = Rlp.Decode <Block>(rlpStream);
            message.TotalDifficulty = rlpStream.DecodeUInt256();
            return(message);
        }
Exemplo n.º 10
0
        public Deposit Decode(RlpStream rlpStream,
                              RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            Keccak  id         = rlpStream.DecodeKeccak();
            uint    units      = rlpStream.DecodeUInt();
            uint    expiryTime = rlpStream.DecodeUInt();
            UInt256 value      = rlpStream.DecodeUInt256();

            return(new Deposit(id, units, expiryTime, value));
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
0
        private static StatusMessage Deserialize(RlpStream rlpStream)
        {
            StatusMessage statusMessage = new StatusMessage();

            rlpStream.ReadSequenceLength();
            statusMessage.ProtocolVersion = rlpStream.DecodeByte();
            statusMessage.ChainId         = rlpStream.DecodeUInt256();
            statusMessage.TotalDifficulty = rlpStream.DecodeUInt256();
            statusMessage.BestHash        = rlpStream.DecodeKeccak();
            statusMessage.GenesisHash     = rlpStream.DecodeKeccak();
            if (rlpStream.Position < rlpStream.Length)
            {
                rlpStream.ReadSequenceLength();
                byte[] forkHash = rlpStream.DecodeByteArray();
                long   next     = (long)rlpStream.DecodeUlong();
                ForkId forkId   = new(forkHash, next);
                statusMessage.ForkId = forkId;
            }

            return(statusMessage);
        }
Exemplo n.º 13
0
        private static AnnounceMessage Deserialize(RlpStream rlpStream)
        {
            AnnounceMessage announceMessage = new();

            rlpStream.ReadSequenceLength();
            announceMessage.HeadHash        = rlpStream.DecodeKeccak();
            announceMessage.HeadBlockNo     = rlpStream.DecodeLong();
            announceMessage.TotalDifficulty = rlpStream.DecodeUInt256();
            announceMessage.ReorgDepth      = rlpStream.DecodeLong();
            rlpStream.ReadSequenceLength();
            return(announceMessage);
        }
Exemplo n.º 14
0
        public UserOperationWithEntryPoint Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.SkipLength();

            UserOperationRpc userOperationRpc = new UserOperationRpc
            {
                Sender               = rlpStream.DecodeAddress() ?? Address.Zero,
                Nonce                = rlpStream.DecodeUInt256(),
                InitCode             = rlpStream.DecodeByteArray(),
                CallData             = rlpStream.DecodeByteArray(),
                CallGas              = rlpStream.DecodeUInt256(),
                VerificationGas      = rlpStream.DecodeUInt256(),
                PreVerificationGas   = rlpStream.DecodeUInt256(),
                MaxFeePerGas         = rlpStream.DecodeUInt256(),
                MaxPriorityFeePerGas = rlpStream.DecodeUInt256(),
                Paymaster            = rlpStream.DecodeAddress() ?? Address.Zero,
                PaymasterData        = rlpStream.DecodeByteArray(),
                Signature            = rlpStream.DecodeByteArray()
            };

            Address entryPoint = rlpStream.DecodeAddress() ?? Address.Zero;

            // TODO: Make instantiation simpler?
            return(new UserOperationWithEntryPoint(new UserOperation(userOperationRpc), entryPoint));
        }
Exemplo n.º 15
0
        public DataAssetRule?Decode(RlpStream rlpStream,
                                    RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            int sequenceLength = rlpStream.ReadSequenceLength();

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

            UInt256 value = rlpStream.DecodeUInt256();

            return(new DataAssetRule(value));
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        public DataRequest Decode(RlpStream rlpStream,
                                  RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            Keccak    assetId    = rlpStream.DecodeKeccak();
            uint      units      = rlpStream.DecodeUInt();
            UInt256   value      = rlpStream.DecodeUInt256();
            uint      expiryTime = rlpStream.DecodeUInt();
            var       salt       = rlpStream.DecodeByteArray();
            Address   provider   = rlpStream.DecodeAddress();
            Address   consumer   = rlpStream.DecodeAddress();
            Signature signature  = SignatureDecoder.DecodeSignature(rlpStream);

            return(new DataRequest(assetId, units, value, expiryTime, salt, provider, consumer, signature));
        }
Exemplo n.º 18
0
        public Deposit Decode(RlpStream rlpStream,
                              RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var id         = rlpStream.DecodeKeccak();
            var units      = rlpStream.DecodeUInt();
            var expiryTime = rlpStream.DecodeUInt();
            var value      = rlpStream.DecodeUInt256();

            return(new Deposit(id, units, expiryTime, value));
        }
Exemplo n.º 19
0
        private List <Vote> DecodeVotes(RlpStream rlpStream)
        {
            rlpStream.ReadSequenceLength();
            List <Vote> votes  = new List <Vote>();
            int         length = rlpStream.DecodeInt();

            for (int i = 0; i < length; i++)
            {
                Address signer    = rlpStream.DecodeAddress();
                long    block     = (long)rlpStream.DecodeUInt256();
                Address address   = rlpStream.DecodeAddress();
                bool    authorize = rlpStream.DecodeBool();
                Vote    vote      = new Vote(signer, block, address, authorize);
                votes.Add(vote);
            }
            return(votes);
        }
Exemplo n.º 20
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());
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        public ParityLikeTxTrace Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            ParityLikeTxTrace trace = new ParityLikeTxTrace();

            rlpStream.ReadSequenceLength();
            trace.BlockHash       = rlpStream.DecodeKeccak();
            trace.BlockNumber     = (long)rlpStream.DecodeUInt256();
            trace.TransactionHash = rlpStream.DecodeKeccak();
            Span <byte> txPosBytes = rlpStream.DecodeByteArraySpan();

            trace.TransactionPosition = txPosBytes.Length == 0 ? (int?)null : txPosBytes.ReadEthInt32();
            rlpStream.ReadSequenceLength();
            trace.Action       = DecodeAction(rlpStream);
            trace.StateChanges = DecodeStateDiff(rlpStream);
            // stateChanges

            return(trace);
        }
        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));
        }
        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));
        }
Exemplo n.º 25
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);
            }
        }
Exemplo n.º 26
0
        public Snapshot Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();

            // Block number
            long number = (long)rlpStream.DecodeUInt256();
            // Hash
            Keccak hash = rlpStream.DecodeKeccak();
            // Signers
            SortedList <Address, long> signers = DecodeSigners(rlpStream);
            // Votes
            List <Vote> votes = DecodeVotes(rlpStream);
            // Tally
            Dictionary <Address, Tally> tally = DecodeTally(rlpStream);
            Snapshot snapshot = new Snapshot(number, hash, signers, tally);

            snapshot.Votes = votes;

            return(snapshot);
        }
Exemplo n.º 27
0
        public DataRequest Decode(RlpStream rlpStream,
                                  RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            var sequenceLength = rlpStream.ReadSequenceLength();

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

            var assetId    = rlpStream.DecodeKeccak();
            var units      = rlpStream.DecodeUInt();
            var value      = rlpStream.DecodeUInt256();
            var expiryTime = rlpStream.DecodeUInt();
            var salt       = rlpStream.DecodeByteArray();
            var provider   = rlpStream.DecodeAddress();
            var consumer   = rlpStream.DecodeAddress();
            var signature  = SignatureDecoder.DecodeSignature(rlpStream);

            return(new DataRequest(assetId, units, value, expiryTime, salt, provider, consumer, signature));
        }
        public UserOperation Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.SkipLength();

            UserOperationRpc userOperationRpc = new UserOperationRpc
            {
                Sender               = rlpStream.DecodeAddress() ?? Address.Zero,
                Nonce                = rlpStream.DecodeUInt256(),
                InitCode             = rlpStream.DecodeByteArray(),
                CallData             = rlpStream.DecodeByteArray(),
                CallGas              = rlpStream.DecodeUInt256(),
                VerificationGas      = rlpStream.DecodeUInt256(),
                PreVerificationGas   = rlpStream.DecodeUInt256(),
                MaxFeePerGas         = rlpStream.DecodeUInt256(),
                MaxPriorityFeePerGas = rlpStream.DecodeUInt256(),
                Paymaster            = rlpStream.DecodeAddress() ?? Address.Zero,
                PaymasterData        = rlpStream.DecodeByteArray(),
                Signature            = rlpStream.DecodeByteArray()
            };

            return(new UserOperation(userOperationRpc));
        }
Exemplo n.º 29
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
            });
        }
Exemplo n.º 30
0
        public NdmConfig Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            try
            {
                rlpStream.ReadSequenceLength();
                bool    enabled                          = rlpStream.DecodeBool();
                string  id                               = rlpStream.DecodeString();
                string  initializerName                  = rlpStream.DecodeString();
                bool    storeConfigInDatabase            = rlpStream.DecodeBool();
                bool    verifyP2PSignature               = rlpStream.DecodeBool();
                string  persistence                      = rlpStream.DecodeString();
                bool    faucetEnabled                    = rlpStream.DecodeBool();
                string  faucetAddress                    = rlpStream.DecodeString();
                string  faucetHost                       = rlpStream.DecodeString();
                UInt256 faucetWeiRequestMaxValue         = rlpStream.DecodeUInt256();
                UInt256 faucetEthDailyRequestsTotalValue = rlpStream.DecodeUInt256();
                string  consumerAddress                  = rlpStream.DecodeString();
                string  contractAddress                  = rlpStream.DecodeString();
                string  providerName                     = rlpStream.DecodeString();
                string  providerAddress                  = rlpStream.DecodeString();
                string  providerColdWalletAddress        = rlpStream.DecodeString();
                UInt256 receiptRequestThreshold          = rlpStream.DecodeUInt256();
                UInt256 receiptsMergeThreshold           = rlpStream.DecodeUInt256();
                UInt256 paymentClaimThreshold            = rlpStream.DecodeUInt256();
                uint    blockConfirmations               = rlpStream.DecodeUInt();
                string  filesPath                        = rlpStream.DecodeString();
                ulong   fileMaxSize                      = rlpStream.DecodeUlong();
                string  pluginsPath                      = rlpStream.DecodeString();
                string  databasePath                     = rlpStream.DecodeString();
                bool    proxyEnabled                     = rlpStream.DecodeBool();
                var     jsonRpcUrlProxies                = rlpStream.DecodeArray(c => c.DecodeString());
                string  gasPriceType                     = rlpStream.DecodeString();
                UInt256 gasPrice                         = rlpStream.DecodeUInt256();
                uint    cancelTransactionGasPricePercentageMultiplier = rlpStream.DecodeUInt();
                bool    jsonRpcDataChannelEnabled = rlpStream.DecodeBool();
                UInt256 refundGasPrice            = rlpStream.DecodeUInt256();

                return(new NdmConfig
                {
                    Enabled = enabled,
                    Id = id,
                    InitializerName = initializerName,
                    StoreConfigInDatabase = storeConfigInDatabase,
                    VerifyP2PSignature = verifyP2PSignature,
                    Persistence = persistence,
                    FaucetEnabled = faucetEnabled,
                    FaucetAddress = faucetAddress == string.Empty ? null : faucetAddress,
                    FaucetHost = faucetHost == string.Empty ? null : faucetHost,
                    FaucetWeiRequestMaxValue = faucetWeiRequestMaxValue,
                    FaucetEthDailyRequestsTotalValue = faucetEthDailyRequestsTotalValue,
                    ConsumerAddress = consumerAddress == string.Empty ? null : consumerAddress,
                    ContractAddress = contractAddress == string.Empty ? null : contractAddress,
                    ProviderName = providerName,
                    ProviderAddress = providerAddress == string.Empty ? null : providerAddress,
                    ProviderColdWalletAddress = providerColdWalletAddress == string.Empty ? null : 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,
                    RefundGasPrice = refundGasPrice
                });
            }