diff options
author | Maran <maran.hidskes@gmail.com> | 2014-04-09 22:07:36 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-04-09 22:07:36 +0800 |
commit | 52b63459e9aa39020894df44a586453444b70ee0 (patch) | |
tree | 02e1f578e188c2b897408dd2b1312118fcf3b357 /ethereum/ethereum.go | |
parent | 2edf133b4671287e58c1f8cdb22f0cd342f309f2 (diff) | |
parent | 1e94cb5286067da80c3227861a836c611f01e32b (diff) | |
download | go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.tar go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.tar.gz go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.tar.bz2 go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.tar.lz go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.tar.xz go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.tar.zst go-tangerine-52b63459e9aa39020894df44a586453444b70ee0.zip |
Merge branch 'develop' into feature/mnemonic
Diffstat (limited to 'ethereum/ethereum.go')
-rw-r--r-- | ethereum/ethereum.go | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go index 666c75117..c82e7dcd8 100644 --- a/ethereum/ethereum.go +++ b/ethereum/ethereum.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethminer" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/eth-go/ethwire" "github.com/ethereum/go-ethereum/utils" "log" "os" @@ -121,36 +121,22 @@ func main() { // Fake block mining. It broadcasts a new block every 5 seconds go func() { - pow := ðchain.EasyPow{} - data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) - keyRing := ethutil.NewValueFromBytes(data) - addr := keyRing.Get(1).Bytes() - - for { - txs := ethereum.TxPool().Flush() - // Create a new block which we're going to mine - block := ethereum.BlockChain().NewBlock(addr, txs) - log.Println("Mining on new block. Includes", len(block.Transactions()), "transactions") - - ethereum.StateManager().Prepare(block.State(), block.State()) - // Apply all transactions to the block - ethereum.StateManager().ApplyTransactions(block, block.Transactions()) - ethereum.StateManager().AccumelateRewards(block) - - // Search the nonce - block.Nonce = pow.Search(block) - - ethereum.StateManager().PrepareDefault(block) - err := ethereum.StateManager().ProcessBlock(block) - if err != nil { - log.Println(err) - } else { - log.Println("\n+++++++ MINED BLK +++++++\n", ethereum.BlockChain().CurrentBlock) - log.Printf("🔨 Mined block %x\n", block.Hash()) - ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val}) - } + + if StartMining { + log.Printf("Miner started\n") + + go func() { + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + keyRing := ethutil.NewValueFromBytes(data) + addr := keyRing.Get(1).Bytes() + + miner := ethminer.NewDefaultMiner(addr, ethereum) + miner.Start() + + }() } }() + } // Wait for shutdown |