mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
changes to core/types/block
- add HeaderHash and ParentHeaderHash public fields to allow block mocking for blockpool tests - Hash() and ParentHash() checks these fields, if unset falls back to orig - HashNoNonce() just returns self.header.HashNoNonce() - better implement with interfaces, so this may be temporary
This commit is contained in:
parent
9b203faa23
commit
254fc1fe3f
1 changed files with 25 additions and 10 deletions
|
|
@ -67,10 +67,13 @@ func (self *Header) HashNoNonce() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
header *Header
|
// Preset Hash for mock
|
||||||
uncles []*Header
|
HeaderHash []byte
|
||||||
transactions Transactions
|
ParentHeaderHash []byte
|
||||||
Td *big.Int
|
header *Header
|
||||||
|
uncles []*Header
|
||||||
|
transactions Transactions
|
||||||
|
Td *big.Int
|
||||||
|
|
||||||
receipts Receipts
|
receipts Receipts
|
||||||
Reward *big.Int
|
Reward *big.Int
|
||||||
|
|
@ -189,23 +192,35 @@ func (self *Block) RlpDataForStorage() interface{} {
|
||||||
// Header accessors (add as you need them)
|
// Header accessors (add as you need them)
|
||||||
func (self *Block) Number() *big.Int { return self.header.Number }
|
func (self *Block) Number() *big.Int { return self.header.Number }
|
||||||
func (self *Block) NumberU64() uint64 { return self.header.Number.Uint64() }
|
func (self *Block) NumberU64() uint64 { return self.header.Number.Uint64() }
|
||||||
func (self *Block) ParentHash() []byte { return self.header.ParentHash }
|
|
||||||
func (self *Block) Bloom() []byte { return self.header.Bloom }
|
func (self *Block) Bloom() []byte { return self.header.Bloom }
|
||||||
func (self *Block) Coinbase() []byte { return self.header.Coinbase }
|
func (self *Block) Coinbase() []byte { return self.header.Coinbase }
|
||||||
func (self *Block) Time() int64 { return int64(self.header.Time) }
|
func (self *Block) Time() int64 { return int64(self.header.Time) }
|
||||||
func (self *Block) GasLimit() *big.Int { return self.header.GasLimit }
|
func (self *Block) GasLimit() *big.Int { return self.header.GasLimit }
|
||||||
func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
|
func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
|
||||||
func (self *Block) Hash() []byte { return self.header.Hash() }
|
|
||||||
func (self *Block) Trie() *ptrie.Trie { return ptrie.New(self.header.Root, ethutil.Config.Db) }
|
func (self *Block) Trie() *ptrie.Trie { return ptrie.New(self.header.Root, ethutil.Config.Db) }
|
||||||
|
func (self *Block) SetRoot(root []byte) { self.header.Root = root }
|
||||||
func (self *Block) State() *state.StateDB { return state.New(self.Trie()) }
|
func (self *Block) State() *state.StateDB { return state.New(self.Trie()) }
|
||||||
func (self *Block) Size() ethutil.StorageSize { return ethutil.StorageSize(len(ethutil.Encode(self))) }
|
func (self *Block) Size() ethutil.StorageSize { return ethutil.StorageSize(len(ethutil.Encode(self))) }
|
||||||
func (self *Block) SetRoot(root []byte) { self.header.Root = root }
|
|
||||||
|
|
||||||
// Implement block.Pow
|
// Implement pow.Block
|
||||||
func (self *Block) Difficulty() *big.Int { return self.header.Difficulty }
|
func (self *Block) Difficulty() *big.Int { return self.header.Difficulty }
|
||||||
func (self *Block) N() []byte { return self.header.Nonce }
|
func (self *Block) N() []byte { return self.header.Nonce }
|
||||||
func (self *Block) HashNoNonce() []byte {
|
func (self *Block) HashNoNonce() []byte { return self.header.HashNoNonce() }
|
||||||
return crypto.Sha3(ethutil.Encode(self.header.rlpData(false)))
|
|
||||||
|
func (self *Block) Hash() []byte {
|
||||||
|
if self.HeaderHash != nil {
|
||||||
|
return self.HeaderHash
|
||||||
|
} else {
|
||||||
|
return self.header.Hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Block) ParentHash() []byte {
|
||||||
|
if self.ParentHeaderHash != nil {
|
||||||
|
return self.ParentHeaderHash
|
||||||
|
} else {
|
||||||
|
return self.header.ParentHash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Block) String() string {
|
func (self *Block) String() string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue