diff options
author | Maran <maran.hidskes@gmail.com> | 2014-03-24 17:56:42 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-03-24 17:56:42 +0800 |
commit | a30f5730b384bf99d23f6e83b356e27a14f961d1 (patch) | |
tree | 4a885f1f0425840a110b70328a3603c257a6d9c4 | |
parent | 6724d27c0c897f116cac3163230f043e80304f91 (diff) | |
download | dexon-a30f5730b384bf99d23f6e83b356e27a14f961d1.tar.gz dexon-a30f5730b384bf99d23f6e83b356e27a14f961d1.tar.zst dexon-a30f5730b384bf99d23f6e83b356e27a14f961d1.zip |
Reimplement new miner creation
-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 3f5e4a8f5..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") - // Apply all transactions to the block - ethereum.StateManager().ApplyTransactions(block, block.Transactions()) - - ethereum.StateManager().Prepare(block.State(), block.State()) - ethereum.StateManager().AccumelateRewards(block) - - // Search the nonce - block.Nonce = pow.Search(block) - ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val}) - - 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()) - } + + 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 |