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); } }
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)); }
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); }
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)); }
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); }
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); }
public DataStreamDisabledMessage Deserialize(byte[] bytes) { RlpStream context = bytes.AsRlpStream(); context.ReadSequenceLength(); Keccak?depositId = context.DecodeKeccak(); string client = context.DecodeString(); return(new DataStreamDisabledMessage(depositId, client)); }
public AddCapabilityMessage Deserialize(byte[] msgBytes) { RlpStream context = msgBytes.AsRlpStream(); context.ReadSequenceLength(); string protocolCode = context.DecodeString(); byte version = context.DecodeByte(); return(new AddCapabilityMessage(new Capability(protocolCode, version))); }
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); }
public RequestDepositApprovalMessage Deserialize(byte[] bytes) { RlpStream context = bytes.AsRlpStream(); context.ReadSequenceLength(); Keccak? dataAssetId = context.DecodeKeccak(); Address?consumer = context.DecodeAddress(); string kyc = context.DecodeString(); return(new RequestDepositApprovalMessage(dataAssetId, consumer, kyc)); }
public EnableDataStreamMessage Deserialize(byte[] bytes) { RlpStream context = bytes.AsRlpStream(); context.ReadSequenceLength(); Keccak?depositId = context.DecodeKeccak(); string client = context.DecodeString(); string?[] args = context.DecodeArray(c => c.DecodeString()); return(new EnableDataStreamMessage(depositId, client, args)); }
public DepositApproval Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { var sequenceLength = rlpStream.ReadSequenceLength(); if (sequenceLength == 0) { return(null); } var id = rlpStream.DecodeKeccak(); var assetId = rlpStream.DecodeKeccak(); var assetName = rlpStream.DecodeString(); var kyc = rlpStream.DecodeString(); var consumer = rlpStream.DecodeAddress(); var provider = rlpStream.DecodeAddress(); var timestamp = rlpStream.DecodeUlong(); var state = (DepositApprovalState)rlpStream.DecodeInt(); return(new DepositApproval(id, assetId, assetName, kyc, consumer, provider, timestamp, state)); }
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); } }
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)); }
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)); }
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); } }
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(); helloMessage.NodeId = new PublicKey(rlpStream.DecodeByteArray()); return(helloMessage); }
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)); }
public NetworkNode Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { rlpStream.ReadSequenceLength(); PublicKey publicKey = new PublicKey(rlpStream.DecodeByteArray()); string ip = rlpStream.DecodeString(); int port = (int)rlpStream.DecodeByteArraySpan().ReadEthUInt64(); rlpStream.SkipItem(); long reputation = 0L; try { reputation = rlpStream.DecodeLong(); } catch (RlpException) { // regression - old format } NetworkNode networkNode = new NetworkNode(publicKey, ip != string.Empty ? ip : null, port, reputation); return(networkNode); }
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 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 }); }
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)); } }
/// <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 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 proxyEnabled = rlpStream.DecodeBool(); var jsonRpcUrlProxies = rlpStream.DecodeArray(c => c.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, ProxyEnabled = proxyEnabled, JsonRpcUrlProxies = jsonRpcUrlProxies }); }