diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-22 06:25:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-22 06:25:48 +0800 |
commit | 01b833146f3afa214586a1ffb710546a5e4cc90a (patch) | |
tree | 997bb8c4c4cb46368c4ff3c7687f1e767f010b63 /utils | |
parent | b902de20c7119ec521a28bba986a0cc9d14354c0 (diff) | |
download | dexon-01b833146f3afa214586a1ffb710546a5e4cc90a.tar.gz dexon-01b833146f3afa214586a1ffb710546a5e4cc90a.tar.zst dexon-01b833146f3afa214586a1ffb710546a5e4cc90a.zip |
Added mining stop and start
Diffstat (limited to 'utils')
-rw-r--r-- | utils/cmd.go | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/utils/cmd.go b/utils/cmd.go index f163575da..98005d7de 100644 --- a/utils/cmd.go +++ b/utils/cmd.go @@ -19,6 +19,8 @@ func DoRpc(ethereum *eth.Ethereum, RpcPort int) { } } +var miner ethminer.Miner + func DoMining(ethereum *eth.Ethereum) { // Set Mining status ethereum.Mining = true @@ -31,17 +33,37 @@ func DoMining(ethereum *eth.Ethereum) { addr := keyPair.Address() go func() { + ethutil.Config.Log.Infoln("Miner started") + + miner = ethminer.NewDefaultMiner(addr, ethereum) + // Give it some time to connect with peers time.Sleep(3 * time.Second) - /* - for ethereum.IsUpToDate() == false { - time.Sleep(5 * time.Second) - } - */ - ethutil.Config.Log.Infoln("Miner started") - - miner := ethminer.NewDefaultMiner(addr, ethereum) miner.Start() }() } + +func StopMining(ethereum *eth.Ethereum) bool { + if ethereum.Mining { + miner.Stop() + + ethutil.Config.Log.Infoln("Miner stopped") + + ethereum.Mining = false + + return true + } + + return false +} + +func StartMining(ethereum *eth.Ethereum) bool { + if !ethereum.Mining { + DoMining(ethereum) + + return true + } + + return false +} |