diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-06 00:10:42 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-06 00:10:42 +0800 |
commit | 6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2 (patch) | |
tree | b898711590694cfaa6f10dbc2a4c8591232954ef /core/types | |
parent | b0854fbff5c3d588134f577918a39d08002235dc (diff) | |
download | go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.gz go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.bz2 go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.lz go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.xz go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.tar.zst go-tangerine-6abf8ef78f1474fdeb7a6a6ce084bf994cc055f2.zip |
Merge
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/core/types/block.go b/core/types/block.go index b59044bfc..7e19d003f 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -67,10 +67,13 @@ func (self *Header) HashNoNonce() []byte { } type Block struct { - header *Header - uncles []*Header - transactions Transactions - Td *big.Int + // Preset Hash for mock + HeaderHash []byte + ParentHeaderHash []byte + header *Header + uncles []*Header + transactions Transactions + Td *big.Int receipts Receipts Reward *big.Int @@ -99,41 +102,19 @@ func NewBlockWithHeader(header *Header) *Block { } func (self *Block) DecodeRLP(s *rlp.Stream) error { - if _, err := s.List(); err != nil { - return err - } - - var header Header - if err := s.Decode(&header); err != nil { - return err - } - - var transactions []*Transaction - if err := s.Decode(&transactions); err != nil { - return err + var extblock struct { + Header *Header + Txs []*Transaction + Uncles []*Header + TD *big.Int // optional } - - var uncleHeaders []*Header - if err := s.Decode(&uncleHeaders); err != nil { - return err - } - - var tdBytes []byte - if err := s.Decode(&tdBytes); err != nil { - // If this block comes from the network that's fine. If loaded from disk it should be there - // Blocks don't store their Td when propagated over the network - } else { - self.Td = ethutil.BigD(tdBytes) - } - - if err := s.ListEnd(); err != nil { + if err := s.Decode(&extblock); err != nil { return err } - - self.header = &header - self.uncles = uncleHeaders - self.transactions = transactions - + self.header = extblock.Header + self.uncles = extblock.Uncles + self.transactions = extblock.Txs + self.Td = extblock.TD return nil } @@ -189,23 +170,35 @@ func (self *Block) RlpDataForStorage() interface{} { // Header accessors (add as you need them) func (self *Block) Number() *big.Int { return self.header.Number } 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) Coinbase() []byte { return self.header.Coinbase } func (self *Block) Time() int64 { return int64(self.header.Time) } func (self *Block) GasLimit() *big.Int { return self.header.GasLimit } 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) SetRoot(root []byte) { self.header.Root = root } 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) 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) N() []byte { return self.header.Nonce } -func (self *Block) HashNoNonce() []byte { - return crypto.Sha3(ethutil.Encode(self.header.rlpData(false))) +func (self *Block) HashNoNonce() []byte { return self.header.HashNoNonce() } + +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 { |