diff --git a/eth/common/eth_types.nim b/eth/common/eth_types.nim index 63c436c..73fc487 100644 --- a/eth/common/eth_types.nim +++ b/eth/common/eth_types.nim @@ -147,9 +147,10 @@ type logs* : seq[Log] EthBlock* = object - header*: BlockHeader - txs*: seq[Transaction] - uncles*: seq[BlockHeader] + header* : BlockHeader + txs* : seq[Transaction] + uncles* : seq[BlockHeader] + withdrawals*: Option[seq[Withdrawal]] # EIP-4895 # TODO: Make BlockNumber a uint64 and deprecate either this or BlockHashOrNumber HashOrNum* = object diff --git a/eth/common/eth_types_rlp.nim b/eth/common/eth_types_rlp.nim index 48d35c3..9572161 100644 --- a/eth/common/eth_types_rlp.nim +++ b/eth/common/eth_types_rlp.nim @@ -400,6 +400,32 @@ proc readRecordType*(rlp: var Rlp, T: type BlockBody, wrappedInList: bool): Bloc proc read*(rlp: var Rlp, T: type BlockBody): T = rlp.readRecordType(BlockBody, true) +proc read*(rlp: var Rlp, T: type EthBlock): T = + let len = rlp.listLen + if len notin {3, 4}: + raise newException(UnsupportedRlpError, + "EthBlock elems should be 3 or 4, got " & $len) + + rlp.tryEnterList() + result.header = rlp.read(BlockHeader) + result.txs = rlp.read(seq[Transaction]) + result.uncles = rlp.read(seq[BlockHeader]) + + # EIP-4895 + result.withdrawals = + if len >= 4: + some(rlp.read(seq[Withdrawal])) + else: + none[seq[Withdrawal]]() + +proc append*(w: var RlpWriter, b: EthBlock) = + w.startList 3 + b.withdrawals.isSome.ord + w.append(b.header) + w.append(b.txs) + w.append(b.uncles) + if b.withdrawals.isSome: + w.append(b.withdrawals.unsafeGet) + proc append*(rlpWriter: var RlpWriter, id: NetworkId) = rlpWriter.append(id.uint)