diff options
author | obscuren <geffobscura@gmail.com> | 2014-03-05 17:42:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-03-05 17:42:51 +0800 |
commit | 92f2abdf769f52ea8e5e6d02bf326744e926f5b4 (patch) | |
tree | 234bcf5278e6804736f7392095733ef133e7fe03 /ethchain/block_chain.go | |
parent | 5b1613d65b0c3471b80990120022b5a745ecab86 (diff) | |
download | go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.gz go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.bz2 go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.lz go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.xz go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.zst go-tangerine-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.zip |
Partially refactored server/txpool/block manager/block chain
The Ethereum structure now complies to a EthManager interface which is
being used by the tx pool, block manager and block chain in order to
gain access to each other. It's become simpeler.
TODO: BlockManager => StateManager
Diffstat (limited to 'ethchain/block_chain.go')
-rw-r--r-- | ethchain/block_chain.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go index 026fc1cea..2865e0a21 100644 --- a/ethchain/block_chain.go +++ b/ethchain/block_chain.go @@ -9,6 +9,7 @@ import ( ) type BlockChain struct { + Ethereum EthManager // The famous, the fabulous Mister GENESIIIIIIS (block) genesisBlock *Block // Last known total difficulty @@ -20,7 +21,7 @@ type BlockChain struct { LastBlockHash []byte } -func NewBlockChain() *BlockChain { +func NewBlockChain(ethereum EthManager) *BlockChain { bc := &BlockChain{} bc.genesisBlock = NewBlockFromData(ethutil.Encode(Genesis)) @@ -129,6 +130,21 @@ func (bc *BlockChain) GetChain(hash []byte, amount int) []*Block { return blocks } +func AddTestNetFunds(block *Block) { + for _, addr := range []string{ + "8a40bfaa73256b60764c1bf40675a99083efb075", // Gavin + "e6716f9544a56c530d868e4bfbacb172315bdead", // Jeffrey + "1e12515ce3e0f817a4ddef9ca55788a1d66bd2df", // Vit + "1a26338f0d905e295fccb71fa9ea849ffa12aaf4", // Alex + } { + //log.Println("2^200 Wei to", addr) + codedAddr := ethutil.FromHex(addr) + addr := block.state.GetAccount(codedAddr) + addr.Amount = ethutil.BigPow(2, 200) + block.state.UpdateAccount(codedAddr, addr) + } +} + func (bc *BlockChain) setLastBlock() { data, _ := ethutil.Config.Db.Get([]byte("LastBlock")) if len(data) != 0 { @@ -139,10 +155,21 @@ func (bc *BlockChain) setLastBlock() { bc.LastBlockNumber = info.Number log.Printf("[CHAIN] Last known block height #%d\n", bc.LastBlockNumber) + } else { + AddTestNetFunds(bc.genesisBlock) + + bc.genesisBlock.state.trie.Sync() + // Prepare the genesis block + bc.Add(bc.genesisBlock) + + //log.Printf("root %x\n", bm.bc.genesisBlock.State().Root) + //bm.bc.genesisBlock.PrintHash() } // Set the last know difficulty (might be 0x0 as initial value, Genesis) bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) + + log.Printf("Last block: %x\n", bc.CurrentBlock.Hash()) } func (bc *BlockChain) SetTotalDifficulty(td *big.Int) { |