@@ -19,6 +19,7 @@ package types
19
19
20
20
import (
21
21
"encoding/binary"
22
+ "github.com/ethereum/go-ethereum/params"
22
23
"io"
23
24
"math/big"
24
25
"sort"
@@ -65,24 +66,46 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
65
66
}
66
67
67
68
//go:generate gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
69
+ type AuraHeader struct {
70
+ ParentHash common.Hash `json:"parentHash" gencodec:"required"`
71
+ UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
72
+ Coinbase common.Address `json:"miner" gencodec:"required"`
73
+ Root common.Hash `json:"stateRoot" gencodec:"required"`
74
+ TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
75
+ ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
76
+ Bloom Bloom `json:"logsBloom" gencodec:"required"`
77
+ Difficulty * big.Int `json:"difficulty" gencodec:"required"`
78
+ Number * big.Int `json:"number" gencodec:"required"`
79
+ GasLimit uint64 `json:"gasLimit" gencodec:"required"`
80
+ GasUsed uint64 `json:"gasUsed" gencodec:"required"`
81
+ Time * big.Int `json:"timestamp" gencodec:"required"`
82
+ Extra []byte `json:"extraData" gencodec:"required"`
83
+ Signature1 []byte `json:"signature1,omitempty"`
84
+ Signature2 []byte `json:"signature2,omitempty"`
85
+ }
68
86
69
87
// Header represents a block header in the Ethereum blockchain.
70
88
type Header struct {
71
- ParentHash common.Hash `json:"parentHash" gencodec:"required"`
72
- UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
73
- Coinbase common.Address `json:"miner" gencodec:"required"`
74
- Root common.Hash `json:"stateRoot" gencodec:"required"`
75
- TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
76
- ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
77
- Bloom Bloom `json:"logsBloom" gencodec:"required"`
78
- Difficulty * big.Int `json:"difficulty" gencodec:"required"`
79
- Number * big.Int `json:"number" gencodec:"required"`
80
- GasLimit uint64 `json:"gasLimit" gencodec:"required"`
81
- GasUsed uint64 `json:"gasUsed" gencodec:"required"`
82
- Time * big.Int `json:"timestamp" gencodec:"required"`
83
- Extra []byte `json:"extraData" gencodec:"required"`
84
- MixDigest common.Hash `json:"mixHash" gencodec:"required"`
85
- Nonce BlockNonce `json:"nonce" gencodec:"required"`
89
+ ParentHash common.Hash `json:"parentHash" gencodec:"required"`
90
+ UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
91
+ Coinbase common.Address `json:"miner" gencodec:"required"`
92
+ Root common.Hash `json:"stateRoot" gencodec:"required"`
93
+ TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
94
+ ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
95
+ Bloom Bloom `json:"logsBloom" gencodec:"required"`
96
+ Difficulty * big.Int `json:"difficulty" gencodec:"required"`
97
+ Number * big.Int `json:"number" gencodec:"required"`
98
+ GasLimit uint64 `json:"gasLimit" gencodec:"required"`
99
+ GasUsed uint64 `json:"gasUsed" gencodec:"required"`
100
+ Time * big.Int `json:"timestamp" gencodec:"required"`
101
+ Extra []byte `json:"extraData" gencodec:"required"`
102
+ MixDigest common.Hash `json:"mixHash" gencodec:"required"`
103
+ Nonce BlockNonce `json:"nonce" gencodec:"required"`
104
+ Signatures params.Signatures `json:"signature,omitempty"`
105
+ }
106
+
107
+ func (h * Header ) MixDig () common.Hash {
108
+ return common.Hash {}
86
109
}
87
110
88
111
// field type overrides for gencodec
@@ -96,10 +119,108 @@ type headerMarshaling struct {
96
119
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
97
120
}
98
121
122
+ // DecodeRLP decodes the Ethereum
123
+ func (h * Header ) DecodeRLP (s * rlp.Stream ) error {
124
+
125
+ var aura AuraHeader
126
+
127
+ // Try decoding as aura header first
128
+ if err := s .Decode (& aura ); err != nil {
129
+ return err
130
+ //return s.Decode(h)
131
+ }
132
+ //Aura decoded fine, now convert to header
133
+ h .ParentHash = aura .ParentHash
134
+ h .UncleHash = aura .UncleHash
135
+ h .Coinbase = aura .Coinbase
136
+ h .Root = aura .Root
137
+ h .TxHash = aura .TxHash
138
+ h .ReceiptHash = aura .ReceiptHash
139
+ h .Bloom = aura .Bloom
140
+ h .Difficulty = aura .Difficulty
141
+ h .Number = aura .Number
142
+ h .GasLimit = aura .GasLimit
143
+ h .GasUsed = aura .GasUsed
144
+ h .Time = aura .Time
145
+ h .Extra = aura .Extra
146
+ h .MixDigest = common.Hash {}
147
+ h .Nonce = BlockNonce {}
148
+ h .Signatures = append (h .Signatures , aura .Signature1 )
149
+ h .Signatures = append (h .Signatures , aura .Signature2 )
150
+ return nil
151
+ }
152
+
153
+ // EncodeRLP serializes b into the Ethereum RLP block format.
154
+ func (header * Header ) EncodeRLP (w io.Writer ) error {
155
+ if false && header .Signatures != nil {
156
+ return rlp .Encode (w , []interface {}{
157
+ header .ParentHash ,
158
+ header .UncleHash ,
159
+ header .Coinbase ,
160
+ header .Root ,
161
+ header .TxHash ,
162
+ header .ReceiptHash ,
163
+ header .Bloom ,
164
+ header .Difficulty ,
165
+ header .Number ,
166
+ header .GasLimit ,
167
+ header .GasUsed ,
168
+ header .Time ,
169
+ header .Extra ,
170
+ // Yes, this is butt-ugly
171
+ header .Signatures [0 ],
172
+ header .Signatures [1 ],
173
+ })
174
+ } else {
175
+ return rlp .Encode (w , []interface {}{
176
+ header .ParentHash ,
177
+ header .UncleHash ,
178
+ header .Coinbase ,
179
+ header .Root ,
180
+ header .TxHash ,
181
+ header .ReceiptHash ,
182
+ header .Bloom ,
183
+ header .Difficulty ,
184
+ header .Number ,
185
+ header .GasLimit ,
186
+ header .GasUsed ,
187
+ header .Time ,
188
+ header .Extra , // Yes, this will panic if extra is too short
189
+ header .MixDigest ,
190
+ header .Nonce ,
191
+ })
192
+ }
193
+ }
194
+
99
195
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
100
196
// RLP encoding.
101
- func (h * Header ) Hash () common.Hash {
102
- return rlpHash (h )
197
+ func (header * Header ) Hash () (h common.Hash ) {
198
+ //if header.Signatures == nil{
199
+ // return rlpHash(h)
200
+ //}
201
+ hw := sha3 .NewKeccak256 ()
202
+
203
+ rlp .Encode (hw , []interface {}{
204
+ header .ParentHash ,
205
+ header .UncleHash ,
206
+ header .Coinbase ,
207
+ header .Root ,
208
+ header .TxHash ,
209
+ header .ReceiptHash ,
210
+ header .Bloom ,
211
+ header .Difficulty ,
212
+ header .Number ,
213
+ header .GasLimit ,
214
+ header .GasUsed ,
215
+ header .Time ,
216
+ header .Extra ,
217
+ // Yes, this is butt-ugly
218
+ //header.Signatures[0],
219
+ //header.Signatures[1],
220
+ })
221
+ hw .Sum (h [:0 ])
222
+ return h
223
+
103
224
}
104
225
105
226
// Size returns the approximate memory used by all internal contents. It is used
@@ -288,9 +409,11 @@ func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
288
409
func (b * Block ) Difficulty () * big.Int { return new (big.Int ).Set (b .header .Difficulty ) }
289
410
func (b * Block ) Time () * big.Int { return new (big.Int ).Set (b .header .Time ) }
290
411
291
- func (b * Block ) NumberU64 () uint64 { return b .header .Number .Uint64 () }
292
- func (b * Block ) MixDigest () common.Hash { return b .header .MixDigest }
293
- func (b * Block ) Nonce () uint64 { return binary .BigEndian .Uint64 (b .header .Nonce [:]) }
412
+ func (b * Block ) NumberU64 () uint64 { return b .header .Number .Uint64 () }
413
+ func (b * Block ) MixDigest () common.Hash {
414
+ return common.Hash {}
415
+ }
416
+ func (b * Block ) Nonce () uint64 { return 0 }
294
417
func (b * Block ) Bloom () Bloom { return b .header .Bloom }
295
418
func (b * Block ) Coinbase () common.Address { return b .header .Coinbase }
296
419
func (b * Block ) Root () common.Hash { return b .header .Root }
0 commit comments