Skip to content

Commit

Permalink
Add BaseFee field in block structure (#255)
Browse files Browse the repository at this point in the history
* added baseFee in block header

* baseFee in block marshalling

* corrected implementation

* refactored and corrected implementation

* fix typo

* fix error string
  • Loading branch information
rachit77 committed Sep 6, 2023
1 parent c9c19bc commit b3ad0a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type Block struct {
Transactions []*Transaction
TransactionsHashes []Hash
Uncles []Hash
BaseFee *big.Int
}

func (b *Block) Copy() *Block {
Expand Down
4 changes: 4 additions & 0 deletions structs_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions structs_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

1 comment on commit b3ad0a0

@XanderShum
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keyword should be "baseFeePerGas" not "baseFee"

Please sign in to comment.