public int GetLength(ChainLevelInfo item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (item == null) { rlpStream.EncodeNullObject(); return; } var(totalLength, logsLength) = GetContentLength(item, rlpBehaviors); bool isStorage = (rlpBehaviors & RlpBehaviors.Storage) != 0; bool isEip658receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts; rlpStream.StartSequence(totalLength); if (isEip658receipts) { rlpStream.Encode(item.StatusCode); } else { rlpStream.Encode(item.PostTransactionState); } if (isStorage) { rlpStream.Encode(item.BlockHash); rlpStream.Encode(item.BlockNumber); rlpStream.Encode(item.Index); rlpStream.Encode(item.Sender); rlpStream.Encode(item.Recipient); rlpStream.Encode(item.ContractAddress); rlpStream.Encode(item.GasUsed); rlpStream.Encode(item.GasUsedTotal); rlpStream.Encode(item.Bloom); rlpStream.StartSequence(logsLength); for (var i = 0; i < item.Logs.Length; i++) { rlpStream.Encode(item.Logs[i]); } if (_supportTxHash) { rlpStream.WriteByte(MarkTxHashByte); rlpStream.Encode(item.TxHash); } rlpStream.Encode(item.Error); } else { rlpStream.Encode(item.GasUsedTotal); rlpStream.Encode(item.Bloom); rlpStream.StartSequence(logsLength); for (var i = 0; i < item.Logs.Length; i++) { rlpStream.Encode(item.Logs[i]); } rlpStream.Encode(item.Error); } }
public void DecodeStructRef(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors, out TxReceiptStructRef item) { item = new TxReceiptStructRef(); if (decoderContext.IsNextItemNull()) { decoderContext.ReadByte(); return; } bool isStorage = (rlpBehaviors & RlpBehaviors.Storage) != 0; decoderContext.ReadSequenceLength(); Span <byte> firstItem = decoderContext.DecodeByteArraySpan(); if (firstItem.Length == 1) { item.StatusCode = firstItem[0]; } else { item.PostTransactionState = firstItem.Length == 0 ? new KeccakStructRef() : new KeccakStructRef(firstItem); } if (isStorage) { decoderContext.DecodeKeccakStructRef(out item.BlockHash); } if (isStorage) { item.BlockNumber = (long)decoderContext.DecodeUInt256(); } if (isStorage) { item.Index = decoderContext.DecodeInt(); } if (isStorage) { decoderContext.DecodeAddressStructRef(out item.Sender); } if (isStorage) { decoderContext.DecodeAddressStructRef(out item.Recipient); } if (isStorage) { decoderContext.DecodeAddressStructRef(out item.ContractAddress); } if (isStorage) { item.GasUsed = (long)decoderContext.DecodeUBigInt(); } item.GasUsedTotal = (long)decoderContext.DecodeUBigInt(); decoderContext.DecodeBloomStructRef(out item.BloomStruct); var peekPrefixAndContentLength = decoderContext.PeekPrefixAndContentLength(); var logsBytes = peekPrefixAndContentLength.ContentLength + peekPrefixAndContentLength.PrefixLength; item.Logs = decoderContext.Data.Slice(decoderContext.Position, logsBytes); decoderContext.SkipItem(); bool allowExtraData = (rlpBehaviors & RlpBehaviors.AllowExtraData) != 0; if (!allowExtraData) { if (isStorage && _supportTxHash) { // since txHash was added later and may not be in rlp, we provide special mark byte that it will be next if (decoderContext.PeekByte() == MarkTxHashByte) { decoderContext.ReadByte(); decoderContext.DecodeKeccakStructRef(out item.TxHash); } } // since error was added later we can only rely on it in cases where we read receipt only and no data follows, empty errors might not be serialized if (decoderContext.Position != decoderContext.Length) { item.Error = decoderContext.DecodeString(); } } }
public static T Decode <T>(byte[] bytes, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { return(Decode <T>(bytes.AsRlpContext(), rlpBehaviors)); }
public int GetLength(FaucetResponse item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
public void Encode(MemoryStream stream, DepositDetails item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new System.NotImplementedException(); }
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)); } }
public void Encode(RlpStream stream, DepositApproval item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new System.NotImplementedException(); }
public void Encode(MemoryStream stream, ParityLikeTxTrace item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new NotImplementedException(); }
public BlockHeader Decode(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (decoderContext.IsNextItemNull()) { return(null); } var headerRlp = decoderContext.PeekNextItem(); int headerSequenceLength = decoderContext.ReadSequenceLength(); int headerCheck = decoderContext.Position + headerSequenceLength; Keccak parentHash = decoderContext.DecodeKeccak(); Keccak ommersHash = decoderContext.DecodeKeccak(); Address beneficiary = decoderContext.DecodeAddress(); Keccak stateRoot = decoderContext.DecodeKeccak(); Keccak transactionsRoot = decoderContext.DecodeKeccak(); Keccak receiptsRoot = decoderContext.DecodeKeccak(); Bloom bloom = decoderContext.DecodeBloom(); UInt256 difficulty = decoderContext.DecodeUInt256(); UInt256 number = decoderContext.DecodeUInt256(); UInt256 gasLimit = decoderContext.DecodeUInt256(); UInt256 gasUsed = decoderContext.DecodeUInt256(); UInt256 timestamp = decoderContext.DecodeUInt256(); byte[] extraData = decoderContext.DecodeByteArray(); BlockHeader blockHeader = new BlockHeader( parentHash, ommersHash, beneficiary, difficulty, (long)number, (long)gasLimit, timestamp, extraData) { StateRoot = stateRoot, TxRoot = transactionsRoot, ReceiptsRoot = receiptsRoot, Bloom = bloom, GasUsed = (long)gasUsed, Hash = Keccak.Compute(headerRlp) }; if (decoderContext.PeekPrefixAndContentLength().ContentLength == Keccak.Size) { blockHeader.MixHash = decoderContext.DecodeKeccak(); blockHeader.Nonce = (ulong)decoderContext.DecodeUBigInt(); } else { blockHeader.AuRaStep = (long)decoderContext.DecodeUInt256(); blockHeader.AuRaSignature = decoderContext.DecodeByteArray(); } if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData) { decoderContext.Check(headerCheck); } return(blockHeader); }
public void Encode(MemoryStream stream, DataDeliveryReceiptRequest item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new System.NotImplementedException(); }
public void Encode(RlpStream stream, PaymentClaim item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new System.NotImplementedException(); }
public int GetLength(PaymentClaim item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
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(); 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 }); }
public int GetLength(Transaction item, RlpBehaviors rlpBehaviors) { return(Rlp.GetSequenceRlpLength(GetContentLength(item, false))); }
public int GetLength(ParityLikeTxTrace item, RlpBehaviors rlpBehaviors) { throw new NotImplementedException(); }
public Rlp Encode(Transaction item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { return(Rlp.Encode(item, false)); }
public void Encode(MemoryStream stream, DataHeaderProvider item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new System.NotImplementedException(); }
public int GetLength(DepositDetails item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
public int GetLength(DataHeaderProvider item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
public static T Decode <T>(Rlp oldRlp, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { return(Decode <T>(oldRlp.Bytes.AsRlpContext(), rlpBehaviors)); }
public int GetLength(BlockHeader?item, RlpBehaviors rlpBehaviors) { return(Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors))); }
public int GetLength(DataDeliveryReceiptToMerge item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
public BlockHeader?Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (rlpStream.IsNextItemNull()) { rlpStream.ReadByte(); return(null); } Span <byte> headerRlp = rlpStream.PeekNextItem(); int headerSequenceLength = rlpStream.ReadSequenceLength(); int headerCheck = rlpStream.Position + headerSequenceLength; Keccak? parentHash = rlpStream.DecodeKeccak(); Keccak? ommersHash = rlpStream.DecodeKeccak(); Address?beneficiary = rlpStream.DecodeAddress(); Keccak? stateRoot = rlpStream.DecodeKeccak(); Keccak? transactionsRoot = rlpStream.DecodeKeccak(); Keccak? receiptsRoot = rlpStream.DecodeKeccak(); Bloom? bloom = rlpStream.DecodeBloom(); UInt256 difficulty = rlpStream.DecodeUInt256(); UInt256 number = rlpStream.DecodeUInt256(); UInt256 gasLimit = rlpStream.DecodeUInt256(); UInt256 gasUsed = rlpStream.DecodeUInt256(); UInt256 timestamp = rlpStream.DecodeUInt256(); byte[]? extraData = rlpStream.DecodeByteArray(); BlockHeader blockHeader = new( parentHash, ommersHash, beneficiary, difficulty, (long)number, (long)gasLimit, timestamp, extraData) { StateRoot = stateRoot, TxRoot = transactionsRoot, ReceiptsRoot = receiptsRoot, Bloom = bloom, GasUsed = (long)gasUsed, Hash = Keccak.Compute(headerRlp) }; if (rlpStream.PeekPrefixAndContentLength().ContentLength == Keccak.Size) { blockHeader.MixHash = rlpStream.DecodeKeccak(); blockHeader.Nonce = (ulong)rlpStream.DecodeUBigInt(); } else { blockHeader.AuRaStep = (long)rlpStream.DecodeUInt256(); blockHeader.AuRaSignature = rlpStream.DecodeByteArray(); } if (blockHeader.Number >= Eip1559TransitionBlock) { blockHeader.BaseFee = rlpStream.DecodeUInt256(); } if ((rlpBehaviors & RlpBehaviors.AllowExtraData) != RlpBehaviors.AllowExtraData) { rlpStream.Check(headerCheck); } return(blockHeader); }
public static Keccak CalculateHash(BlockHeader header, RlpBehaviors behaviors = RlpBehaviors.None) { Rlp buffer = _headerDecoder.Encode(header, behaviors); return(Keccak.Compute(buffer.Bytes)); }
public void Encode(MemoryStream stream, DataAssetRules item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { throw new System.NotImplementedException(); }
public int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors) { return(Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors).Total)); }
public int GetLength(DataAssetRules item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }
public TxReceipt Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (rlpStream.IsNextItemNull()) { rlpStream.ReadByte(); return(null); } bool isStorage = (rlpBehaviors & RlpBehaviors.Storage) != 0; TxReceipt txReceipt = new TxReceipt(); rlpStream.ReadSequenceLength(); byte[] firstItem = rlpStream.DecodeByteArray(); if (firstItem.Length == 1) { txReceipt.StatusCode = firstItem[0]; } else { txReceipt.PostTransactionState = firstItem.Length == 0 ? null : new Keccak(firstItem); } if (isStorage) { txReceipt.BlockHash = rlpStream.DecodeKeccak(); } if (isStorage) { txReceipt.BlockNumber = (long)rlpStream.DecodeUInt256(); } if (isStorage) { txReceipt.Index = rlpStream.DecodeInt(); } if (isStorage) { txReceipt.Sender = rlpStream.DecodeAddress(); } if (isStorage) { txReceipt.Recipient = rlpStream.DecodeAddress(); } if (isStorage) { txReceipt.ContractAddress = rlpStream.DecodeAddress(); } if (isStorage) { txReceipt.GasUsed = (long)rlpStream.DecodeUBigInt(); } txReceipt.GasUsedTotal = (long)rlpStream.DecodeUBigInt(); txReceipt.Bloom = rlpStream.DecodeBloom(); int lastCheck = rlpStream.ReadSequenceLength() + rlpStream.Position; List <LogEntry> logEntries = new List <LogEntry>(); while (rlpStream.Position < lastCheck) { logEntries.Add(Rlp.Decode <LogEntry>(rlpStream, RlpBehaviors.AllowExtraData)); } bool allowExtraData = (rlpBehaviors & RlpBehaviors.AllowExtraData) != 0; if (!allowExtraData) { rlpStream.Check(lastCheck); } if (!allowExtraData) { if (isStorage && _supportTxHash) { // since txHash was added later and may not be in rlp, we provide special mark byte that it will be next if (rlpStream.PeekByte() == MarkTxHashByte) { rlpStream.ReadByte(); txReceipt.TxHash = rlpStream.DecodeKeccak(); } } // since error was added later we can only rely on it in cases where we read receipt only and no data follows, empty errors might not be serialized if (rlpStream.Position != rlpStream.Length) { txReceipt.Error = rlpStream.DecodeString(); } } txReceipt.Logs = logEntries.ToArray(); return(txReceipt); }
public int GetLength(ConsumerSession item, RlpBehaviors rlpBehaviors) { throw new System.NotImplementedException(); }