aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/block_chain.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-10 23:00:06 +0800
committerobscuren <geffobscura@gmail.com>2014-10-10 23:00:06 +0800
commite02c0fa8088943bc995d290e58a7226f4a0ece91 (patch)
tree1bc2ac212b46d3892dd2720304efb2ab97e43528 /ethchain/block_chain.go
parent9b494c68698cbcaa4d8d6e0f2b964d29db815da5 (diff)
downloaddexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.tar
dexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.tar.gz
dexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.tar.bz2
dexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.tar.lz
dexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.tar.xz
dexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.tar.zst
dexon-e02c0fa8088943bc995d290e58a7226f4a0ece91.zip
Added generic big to 256 method. Implemented new iterator
Diffstat (limited to 'ethchain/block_chain.go')
-rw-r--r--ethchain/block_chain.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go
index 113e313ac..a5dcec438 100644
--- a/ethchain/block_chain.go
+++ b/ethchain/block_chain.go
@@ -40,13 +40,11 @@ func (bc *BlockChain) Genesis() *Block {
func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
var root interface{}
- var lastBlockTime int64
hash := ZeroHash256
if bc.CurrentBlock != nil {
root = bc.CurrentBlock.state.Trie.Root
hash = bc.LastBlockHash
- lastBlockTime = bc.CurrentBlock.Time
}
block := CreateBlock(
@@ -61,15 +59,7 @@ func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
parent := bc.CurrentBlock
if parent != nil {
- diff := new(big.Int)
-
- adjust := new(big.Int).Rsh(parent.Difficulty, 10)
- if block.Time >= lastBlockTime+5 {
- diff.Sub(parent.Difficulty, adjust)
- } else {
- diff.Add(parent.Difficulty, adjust)
- }
- block.Difficulty = diff
+ block.Difficulty = CalcDifficulty(block, parent)
block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1)
block.GasLimit = block.CalcGasLimit(bc.CurrentBlock)
@@ -78,6 +68,19 @@ func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
return block
}
+func CalcDifficulty(block, parent *Block) *big.Int {
+ diff := new(big.Int)
+
+ adjust := new(big.Int).Rsh(parent.Difficulty, 10)
+ if block.Time >= parent.Time+5 {
+ diff.Sub(parent.Difficulty, adjust)
+ } else {
+ diff.Add(parent.Difficulty, adjust)
+ }
+
+ return diff
+}
+
func (bc *BlockChain) Reset() {
AddTestNetFunds(bc.genesisBlock)