public TxReceipt Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (rlpStream.IsNextItemNull()) { rlpStream.ReadByte(); return(null); } TxReceipt txReceipt = new(); if (!rlpStream.IsSequenceNext()) { rlpStream.SkipLength(); txReceipt.TxType = (TxType)rlpStream.ReadByte(); } _ = rlpStream.ReadSequenceLength(); byte[] firstItem = rlpStream.DecodeByteArray(); if (firstItem.Length == 1 && (firstItem[0] == 0 || firstItem[0] == 1)) { txReceipt.StatusCode = firstItem[0]; txReceipt.GasUsedTotal = (long)rlpStream.DecodeUBigInt(); } else if (firstItem.Length >= 1 && firstItem.Length <= 4) { txReceipt.GasUsedTotal = (long)firstItem.ToUnsignedBigInteger(); txReceipt.SkipStateAndStatusInRlp = true; } else { txReceipt.PostTransactionState = firstItem.Length == 0 ? null : new Keccak(firstItem); txReceipt.GasUsedTotal = (long)rlpStream.DecodeUBigInt(); } txReceipt.Bloom = rlpStream.DecodeBloom(); int lastCheck = rlpStream.ReadSequenceLength() + rlpStream.Position; int numberOfReceipts = rlpStream.ReadNumberOfItemsRemaining(lastCheck); LogEntry[] entries = new LogEntry[numberOfReceipts]; for (int i = 0; i < numberOfReceipts; i++) { entries[i] = Rlp.Decode <LogEntry>(rlpStream, RlpBehaviors.AllowExtraData); } txReceipt.Logs = entries; return(txReceipt); }
public static T[] DecodeArray <T>(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (Decoders.ContainsKey(typeof(T))) { IRlpDecoder <T> decoder = (IRlpDecoder <T>)Decoders[typeof(T)]; int checkPosition = rlpStream.ReadSequenceLength() + rlpStream.Position; T[] result = new T[rlpStream.ReadNumberOfItemsRemaining(checkPosition)]; for (int i = 0; i < result.Length; i++) { result[i] = decoder.Decode(rlpStream, rlpBehaviors); } return(result); } throw new RlpException($"{nameof(Rlp)} does not support decoding {typeof(T).Name}"); }