From f27bd687b9204f6bf93dbd2d459ddecd3be67406 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Thu, 21 Mar 2024 05:40:09 +0100 Subject: [PATCH] core/types: add inclusion list types --- core/types/block.go | 8 ++++---- core/types/gen_inclusion.go | 25 +++++++++++++++++++++++++ core/types/gen_inclusion_rlp.go | 32 ++++++++++++++++++++++++++++++++ core/types/inclusion_list.go | 4 ++-- 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 core/types/gen_inclusion.go create mode 100644 core/types/gen_inclusion_rlp.go diff --git a/core/types/block.go b/core/types/block.go index e003941e9d..8a89c9f37c 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -173,8 +173,8 @@ func (h *Header) EmptyReceipts() bool { type Body struct { Transactions []*Transaction Uncles []*Header - Withdrawals []*Withdrawal `rlp:"optional"` - InclusionListSummary []*InclusionListEntry + Withdrawals []*Withdrawal `rlp:"optional"` + InclusionListSummary []*InclusionListEntry `rlp:"optional"` } // Block represents an Ethereum block. @@ -216,8 +216,8 @@ type extblock struct { Header *Header Txs []*Transaction Uncles []*Header - Withdrawals []*Withdrawal `rlp:"optional"` - InclusionListSummary []*InclusionListEntry + Withdrawals []*Withdrawal `rlp:"optional"` + InclusionListSummary []*InclusionListEntry `rlp:"optional"` } // NewBlock creates a new block. The input data is copied, changes to header and to the diff --git a/core/types/gen_inclusion.go b/core/types/gen_inclusion.go new file mode 100644 index 0000000000..ca4372c292 --- /dev/null +++ b/core/types/gen_inclusion.go @@ -0,0 +1,25 @@ +// Code generated by rlpgen. DO NOT EDIT. + +package types + +import "github.com/ethereum/go-ethereum/rlp" +import "io" + +func (obj *InclusionList) EncodeRLP(_w io.Writer) error { + w := rlp.NewEncoderBuffer(_w) + _tmp0 := w.List() + _tmp1 := w.List() + for _, _tmp2 := range obj.List { + if _tmp2 == nil { + w.Write([]byte{0xC0}) + } else { + _tmp3 := w.List() + w.WriteBytes(_tmp2.Address[:]) + w.WriteUint64(_tmp2.Nonce) + w.ListEnd(_tmp3) + } + } + w.ListEnd(_tmp1) + w.ListEnd(_tmp0) + return w.Flush() +} diff --git a/core/types/gen_inclusion_rlp.go b/core/types/gen_inclusion_rlp.go new file mode 100644 index 0000000000..1352c57831 --- /dev/null +++ b/core/types/gen_inclusion_rlp.go @@ -0,0 +1,32 @@ +// Code generated by github.com/fjl/gencodec. DO NOT EDIT. + +package types + +import ( + "encoding/json" +) + +// MarshalJSON marshals as JSON. +func (i InclusionList) MarshalJSON() ([]byte, error) { + type InclusionList struct { + List []*InclusionListEntry + } + var enc InclusionList + enc.List = i.List + return json.Marshal(&enc) +} + +// UnmarshalJSON unmarshals from JSON. +func (i *InclusionList) UnmarshalJSON(input []byte) error { + type InclusionList struct { + List []*InclusionListEntry + } + var dec InclusionList + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + if dec.List != nil { + i.List = dec.List + } + return nil +} diff --git a/core/types/inclusion_list.go b/core/types/inclusion_list.go index 0c1895de49..f02723a462 100644 --- a/core/types/inclusion_list.go +++ b/core/types/inclusion_list.go @@ -23,8 +23,8 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) -//go:generate go run github.com/fjl/gencodec -type InclusionList gen_inclusion_rlp.go -//go:generate go run ../../rlp/rlpgen -type InclusionList -out gen_inculsion.go +//go:generate go run github.com/fjl/gencodec -type InclusionList -out gen_inclusion_rlp.go +//go:generate go run ../../rlp/rlpgen -type InclusionList -out gen_inclusion.go type InclusionListEntry struct { Address common.Address