fix missing withdrawals field in EthBlock

This commit is contained in:
jangko 2023-05-22 16:11:30 +07:00
parent 285da12bf3
commit e639dc1e14
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 30 additions and 3 deletions

View File

@ -150,6 +150,7 @@ type
header* : BlockHeader header* : BlockHeader
txs* : seq[Transaction] txs* : seq[Transaction]
uncles* : seq[BlockHeader] uncles* : seq[BlockHeader]
withdrawals*: Option[seq[Withdrawal]] # EIP-4895
# TODO: Make BlockNumber a uint64 and deprecate either this or BlockHashOrNumber # TODO: Make BlockNumber a uint64 and deprecate either this or BlockHashOrNumber
HashOrNum* = object HashOrNum* = object

View File

@ -400,6 +400,32 @@ proc readRecordType*(rlp: var Rlp, T: type BlockBody, wrappedInList: bool): Bloc
proc read*(rlp: var Rlp, T: type BlockBody): T = proc read*(rlp: var Rlp, T: type BlockBody): T =
rlp.readRecordType(BlockBody, true) 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) = proc append*(rlpWriter: var RlpWriter, id: NetworkId) =
rlpWriter.append(id.uint) rlpWriter.append(id.uint)