diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-04 04:48:05 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-04 04:48:05 +0800 |
commit | d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2 (patch) | |
tree | e4054e8c8b26f388d3455c2890a36b9834cbdeab /core/types | |
parent | 08fd0715f9504edcc81029ffebee794b06fe4653 (diff) | |
download | dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.tar dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.tar.gz dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.tar.bz2 dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.tar.lz dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.tar.xz dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.tar.zst dexon-d4d505c868fcd0f692ec3573bd6cfcb1c5230fe2.zip |
Fixed genesis
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/core/types/block.go b/core/types/block.go index 358d0bc2d..18a21e8c6 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -2,6 +2,7 @@ package types import ( "bytes" + "encoding/binary" "fmt" "math/big" "sort" @@ -40,7 +41,7 @@ type Header struct { // Extra data Extra string // Nonce - Nonce uint64 + Nonce []byte // Mix digest for quick checking to prevent DOS MixDigest ethutil.Bytes // SeedHash used for light client verification @@ -63,7 +64,7 @@ func (self *Header) rlpData(withNonce bool) []interface{} { self.Time, self.Extra} if withNonce { - fields = append(fields, self.Nonce, self.MixDigest, self.SeedHash) + fields = append(fields, self.SeedHash, self.MixDigest, self.Nonce) } return fields @@ -100,18 +101,23 @@ func NewBlock(parentHash []byte, coinbase []byte, root []byte, difficulty *big.I ParentHash: parentHash, Coinbase: coinbase, Difficulty: difficulty, - Nonce: nonce, Time: uint64(time.Now().Unix()), Extra: extra, GasUsed: new(big.Int), GasLimit: new(big.Int), } + header.setNonce(nonce) block := &Block{header: header, Reward: new(big.Int)} return block } +func (self *Header) setNonce(nonce uint64) { + self.Nonce = make([]byte, 8) + binary.BigEndian.PutUint64(self.Nonce, nonce) +} + func NewBlockWithHeader(header *Header) *Block { return &Block{header: header} } @@ -191,11 +197,17 @@ 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) MixDigest() []byte { return self.header.MixDigest } -func (self *Block) SeedHash() []byte { return self.header.SeedHash } -func (self *Block) Nonce() uint64 { return self.header.Nonce } +func (self *Block) Number() *big.Int { return self.header.Number } +func (self *Block) NumberU64() uint64 { return self.header.Number.Uint64() } +func (self *Block) MixDigest() []byte { return self.header.MixDigest } +func (self *Block) SeedHash() []byte { return self.header.SeedHash } +func (self *Block) Nonce() uint64 { + return binary.BigEndian.Uint64(self.header.Nonce) +} +func (self *Block) SetNonce(nonce uint64) { + self.header.setNonce(nonce) +} + 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) } @@ -267,11 +279,10 @@ func (self *Header) String() string { GasUsed: %v Time: %v Extra: %v - Nonce: %d - MixDigest: %x SeedHash: %x - -`, self.ParentHash, self.UncleHash, self.Coinbase, self.Root, self.TxHash, self.ReceiptHash, self.Bloom, self.Difficulty, self.Number, self.GasLimit, self.GasUsed, self.Time, self.Extra, self.Nonce, self.MixDigest, self.SeedHash) + MixDigest: %x + Nonce: %x`, + self.ParentHash, self.UncleHash, self.Coinbase, self.Root, self.TxHash, self.ReceiptHash, self.Bloom, self.Difficulty, self.Number, self.GasLimit, self.GasUsed, self.Time, self.Extra, self.SeedHash, self.MixDigest, self.Nonce) } type Blocks []*Block |