From b3ad0a00664bb7b4402b34214242af12a06d621a Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia <54906134+rachit77@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:18:57 +0530 Subject: [PATCH] Add BaseFee field in block structure (#255) * added baseFee in block header * baseFee in block marshalling * corrected implementation * refactored and corrected implementation * fix typo * fix error string --- structs.go | 1 + structs_marshal.go | 4 ++++ structs_unmarshal.go | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/structs.go b/structs.go index 699d5899..c5b0c156 100644 --- a/structs.go +++ b/structs.go @@ -148,6 +148,7 @@ type Block struct { Transactions []*Transaction TransactionsHashes []Hash Uncles []Hash + BaseFee *big.Int } func (b *Block) Copy() *Block { diff --git a/structs_marshal.go b/structs_marshal.go index b88e079e..a8f2ec11 100644 --- a/structs_marshal.go +++ b/structs_marshal.go @@ -66,6 +66,10 @@ func (t *Block) MarshalJSON() ([]byte, error) { o.Set("mixHash", a.NewString("0x"+hex.EncodeToString(t.MixHash[:]))) o.Set("nonce", a.NewString("0x"+hex.EncodeToString(t.Nonce[:]))) + if t.BaseFee != nil { + o.Set("baseFee", a.NewString(fmt.Sprintf("0x%x", t.BaseFee))) + } + // uncles if len(t.Uncles) != 0 { uncles := a.NewArray() diff --git a/structs_unmarshal.go b/structs_unmarshal.go index a3f28c0b..66c14d9c 100644 --- a/structs_unmarshal.go +++ b/structs_unmarshal.go @@ -67,6 +67,11 @@ func (b *Block) UnmarshalJSON(buf []byte) error { if b.ExtraData, err = decodeBytes(b.ExtraData[:0], v, "extraData"); err != nil { return err } + if b.BaseFee, err = decodeBigInt(b.BaseFee, v, "baseFee"); err != nil { + if err.Error() != "field 'baseFee' not found" { + return err + } + } b.TransactionsHashes = b.TransactionsHashes[:0] b.Transactions = b.Transactions[:0]