Skip to content

Commit 606881b

Browse files
committed
refactor: internalise Header.MarshalJSON and UnmarshalJSON
1 parent 44f23c8 commit 606881b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

core/types/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
6060
}
6161

6262
//go:generate go run github.com/fjl/gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
63+
//go:generate go run ../../libevm/cmd/internalise -file gen_header_json.go Header.MarshalJSON Header.UnmarshalJSON
6364
//go:generate go run ../../rlp/rlpgen -type Header -out gen_header_rlp.go
6465
//go:generate go run ../../libevm/cmd/internalise -file gen_header_rlp.go Header.EncodeRLP
6566

core/types/block.libevm.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package types
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122
"io"
2223

@@ -34,8 +35,20 @@ type HeaderHooks interface {
3435
var _ interface {
3536
rlp.Encoder
3637
rlp.Decoder
38+
json.Marshaler
39+
json.Unmarshaler
3740
} = (*Header)(nil)
3841

42+
// MarshalJSON implements the [json.Marshaler] interface.
43+
func (h *Header) MarshalJSON() ([]byte, error) {
44+
return h.marshalJSON()
45+
}
46+
47+
// UnmarshalJSON implements the [json.Unmarshaler] interface.
48+
func (h *Header) UnmarshalJSON(b []byte) error {
49+
return h.unmarshalJSON(b)
50+
}
51+
3952
// EncodeRLP implements the [rlp.Encoder] interface.
4053
func (h *Header) EncodeRLP(w io.Writer) error {
4154
if r := registeredExtras; r.Registered() {

core/types/gen_header_json.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)