@@ -29,6 +29,7 @@ import (
29
29
"time"
30
30
31
31
"github.com/ethereum/go-ethereum/common"
32
+ "github.com/ethereum/go-ethereum/common/hexutil"
32
33
"github.com/ethereum/go-ethereum/crypto/sha3"
33
34
"github.com/ethereum/go-ethereum/rlp"
34
35
)
@@ -63,20 +64,12 @@ func (n BlockNonce) Uint64() uint64 {
63
64
64
65
// MarshalJSON implements json.Marshaler
65
66
func (n BlockNonce ) MarshalJSON () ([]byte , error ) {
66
- return [] byte ( fmt . Sprintf ( `"0x%x"` , n )), nil
67
+ return hexutil . Bytes ( n [:]). MarshalJSON ()
67
68
}
68
69
69
70
// UnmarshalJSON implements json.Unmarshaler
70
71
func (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 [:])
80
73
}
81
74
82
75
// Header represents a block header in the Ethereum blockchain.
@@ -106,12 +99,12 @@ type jsonHeader struct {
106
99
TxHash * common.Hash `json:"transactionsRoot"`
107
100
ReceiptHash * common.Hash `json:"receiptsRoot"`
108
101
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"`
115
108
MixDigest * common.Hash `json:"mixHash"`
116
109
Nonce * BlockNonce `json:"nonce"`
117
110
}
@@ -151,12 +144,12 @@ func (h *Header) MarshalJSON() ([]byte, error) {
151
144
TxHash : & h .TxHash ,
152
145
ReceiptHash : & h .ReceiptHash ,
153
146
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 ),
160
153
MixDigest : & h .MixDigest ,
161
154
Nonce : & h .Nonce ,
162
155
})
0 commit comments