@@ -27,7 +27,7 @@ type Header struct {
2727 // Receipt sha
2828 ReceiptHash common.Hash
2929 // Bloom
30- Bloom [ 256 ] byte
30+ Bloom Bloom
3131 // Difficulty for the current block
3232 Difficulty * big.Int
3333 // The block number
@@ -73,28 +73,30 @@ func (self *Header) RlpData() interface{} {
7373 return self .rlpData (true )
7474}
7575
76- func (self * Header ) Hash () [] byte {
77- return crypto .Sha3 (common .Encode (self .rlpData (true )))
76+ func (self * Header ) Hash () common. Hash {
77+ return common . BytesToHash ( crypto .Sha3 (common .Encode (self .rlpData (true ) )))
7878}
7979
80- func (self * Header ) HashNoNonce () [] byte {
81- return crypto .Sha3 (common .Encode (self .rlpData (false )))
80+ func (self * Header ) HashNoNonce () common. Hash {
81+ return common . BytesToHash ( crypto .Sha3 (common .Encode (self .rlpData (false ) )))
8282}
8383
8484type Block struct {
85- // Preset Hash for mock
86- HeaderHash []byte
87- ParentHeaderHash []byte
88- header * Header
89- uncles []* Header
90- transactions Transactions
91- Td * big.Int
85+ // Preset Hash for mock (Tests)
86+ HeaderHash common.Hash
87+ ParentHeaderHash common.Hash
88+ // ^^^^ ignore ^^^^
89+
90+ header * Header
91+ uncles []* Header
92+ transactions Transactions
93+ Td * big.Int
9294
9395 receipts Receipts
9496 Reward * big.Int
9597}
9698
97- func NewBlock (parentHash [] byte , coinbase [] byte , root [] byte , difficulty * big.Int , nonce uint64 , extra string ) * Block {
99+ func NewBlock (parentHash common. Hash , coinbase common. Address , root common. Hash , difficulty * big.Int , nonce uint64 , extra string ) * Block {
98100 header := & Header {
99101 Root : root ,
100102 ParentHash : parentHash ,
@@ -113,8 +115,7 @@ func NewBlock(parentHash []byte, coinbase []byte, root []byte, difficulty *big.I
113115}
114116
115117func (self * Header ) setNonce (nonce uint64 ) {
116- self .Nonce = make ([]byte , 8 )
117- binary .BigEndian .PutUint64 (self .Nonce , nonce )
118+ binary .BigEndian .PutUint64 (self .Nonce [:], nonce )
118119}
119120
120121func NewBlockWithHeader (header * Header ) * Block {
@@ -148,7 +149,7 @@ func (self *Block) Uncles() []*Header {
148149
149150func (self * Block ) SetUncles (uncleHeaders []* Header ) {
150151 self .uncles = uncleHeaders
151- self .header .UncleHash = crypto .Sha3 (common .Encode (uncleHeaders ))
152+ self .header .UncleHash = common . BytesToHash ( crypto .Sha3 (common .Encode (uncleHeaders ) ))
152153}
153154
154155func (self * Block ) Transactions () Transactions {
@@ -196,23 +197,23 @@ func (self *Block) RlpDataForStorage() interface{} {
196197}
197198
198199// Header accessors (add as you need them)
199- func (self * Block ) Number () * big.Int { return self .header .Number }
200- func (self * Block ) NumberU64 () uint64 { return self .header .Number .Uint64 () }
201- func (self * Block ) MixDigest () [] byte { return self .header .MixDigest }
200+ func (self * Block ) Number () * big.Int { return self .header .Number }
201+ func (self * Block ) NumberU64 () uint64 { return self .header .Number .Uint64 () }
202+ func (self * Block ) MixDigest () common. Hash { return self .header .MixDigest }
202203func (self * Block ) Nonce () uint64 {
203- return binary .BigEndian .Uint64 (self .header .Nonce )
204+ return binary .BigEndian .Uint64 (self .header .Nonce [:] )
204205}
205206func (self * Block ) SetNonce (nonce uint64 ) {
206207 self .header .setNonce (nonce )
207208}
208209
209- func (self * Block ) Bloom () [] byte { return self .header .Bloom }
210- func (self * Block ) Coinbase () [] byte { return self .header .Coinbase }
210+ func (self * Block ) Bloom () Bloom { return self .header .Bloom }
211+ func (self * Block ) Coinbase () common. Address { return self .header .Coinbase }
211212func (self * Block ) Time () int64 { return int64 (self .header .Time ) }
212213func (self * Block ) GasLimit () * big.Int { return self .header .GasLimit }
213214func (self * Block ) GasUsed () * big.Int { return self .header .GasUsed }
214- func (self * Block ) Root () [] byte { return self .header .Root }
215- func (self * Block ) SetRoot (root [] byte ) { self .header .Root = root }
215+ func (self * Block ) Root () common. Hash { return self .header .Root }
216+ func (self * Block ) SetRoot (root common. Hash ) { self .header .Root = root }
216217func (self * Block ) Size () common.StorageSize { return common .StorageSize (len (common .Encode (self ))) }
217218func (self * Block ) GetTransaction (i int ) * Transaction {
218219 if len (self .transactions ) > i {
@@ -228,19 +229,19 @@ func (self *Block) GetUncle(i int) *Header {
228229}
229230
230231// Implement pow.Block
231- func (self * Block ) Difficulty () * big.Int { return self .header .Difficulty }
232- func (self * Block ) HashNoNonce () [] byte { return self .header .HashNoNonce () }
232+ func (self * Block ) Difficulty () * big.Int { return self .header .Difficulty }
233+ func (self * Block ) HashNoNonce () common. Hash { return self .header .HashNoNonce () }
233234
234- func (self * Block ) Hash () [] byte {
235- if self .HeaderHash != nil {
235+ func (self * Block ) Hash () common. Hash {
236+ if ( self .HeaderHash != common. Hash {}) {
236237 return self .HeaderHash
237238 } else {
238239 return self .header .Hash ()
239240 }
240241}
241242
242- func (self * Block ) ParentHash () [] byte {
243- if self .ParentHeaderHash != nil {
243+ func (self * Block ) ParentHash () common. Hash {
244+ if ( self .ParentHeaderHash != common. Hash {}) {
244245 return self .ParentHeaderHash
245246 } else {
246247 return self .header .ParentHash
0 commit comments