@@ -29,6 +29,7 @@ import (
2929 "time"
3030
3131 "github.com/ethereum/go-ethereum/common"
32+ "github.com/ethereum/go-ethereum/common/hexutil"
3233 "github.com/ethereum/go-ethereum/crypto/sha3"
3334 "github.com/ethereum/go-ethereum/rlp"
3435)
@@ -63,20 +64,12 @@ func (n BlockNonce) Uint64() uint64 {
6364
6465// MarshalJSON implements json.Marshaler
6566func (n BlockNonce ) MarshalJSON () ([]byte , error ) {
66- return [] byte ( fmt . Sprintf ( `"0x%x"` , n )), nil
67+ return hexutil . Bytes ( n [:]). MarshalJSON ()
6768}
6869
6970// UnmarshalJSON implements json.Unmarshaler
7071func (n * BlockNonce ) UnmarshalJSON (input []byte ) error {
71- var b hexBytes
72- if err := b .UnmarshalJSON (input ); err != nil {
73- return err
74- }
75- if len (b ) != 8 {
76- return errBadNonceSize
77- }
78- copy ((* n )[:], b )
79- return nil
72+ return hexutil .UnmarshalJSON ("BlockNonce" , input , n [:])
8073}
8174
8275// Header represents a block header in the Ethereum blockchain.
@@ -106,12 +99,12 @@ type jsonHeader struct {
10699 TxHash * common.Hash `json:"transactionsRoot"`
107100 ReceiptHash * common.Hash `json:"receiptsRoot"`
108101 Bloom * Bloom `json:"logsBloom"`
109- Difficulty * hexBig `json:"difficulty"`
110- Number * hexBig `json:"number"`
111- GasLimit * hexBig `json:"gasLimit"`
112- GasUsed * hexBig `json:"gasUsed"`
113- Time * hexBig `json:"timestamp"`
114- Extra * hexBytes `json:"extraData"`
102+ Difficulty * hexutil. Big `json:"difficulty"`
103+ Number * hexutil. Big `json:"number"`
104+ GasLimit * hexutil. Big `json:"gasLimit"`
105+ GasUsed * hexutil. Big `json:"gasUsed"`
106+ Time * hexutil. Big `json:"timestamp"`
107+ Extra * hexutil. Bytes `json:"extraData"`
115108 MixDigest * common.Hash `json:"mixHash"`
116109 Nonce * BlockNonce `json:"nonce"`
117110}
@@ -151,12 +144,12 @@ func (h *Header) MarshalJSON() ([]byte, error) {
151144 TxHash : & h .TxHash ,
152145 ReceiptHash : & h .ReceiptHash ,
153146 Bloom : & h .Bloom ,
154- Difficulty : (* hexBig )(h .Difficulty ),
155- Number : (* hexBig )(h .Number ),
156- GasLimit : (* hexBig )(h .GasLimit ),
157- GasUsed : (* hexBig )(h .GasUsed ),
158- Time : (* hexBig )(h .Time ),
159- Extra : (* hexBytes )(& h .Extra ),
147+ Difficulty : (* hexutil . Big )(h .Difficulty ),
148+ Number : (* hexutil . Big )(h .Number ),
149+ GasLimit : (* hexutil . Big )(h .GasLimit ),
150+ GasUsed : (* hexutil . Big )(h .GasUsed ),
151+ Time : (* hexutil . Big )(h .Time ),
152+ Extra : (* hexutil . Bytes )(& h .Extra ),
160153 MixDigest : & h .MixDigest ,
161154 Nonce : & h .Nonce ,
162155 })
0 commit comments