aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ethereal/gui.go18
-rw-r--r--utils/cmd.go8
2 files changed, 24 insertions, 2 deletions
diff --git a/ethereal/gui.go b/ethereal/gui.go
index ad701a584..cfe5e2269 100644
--- a/ethereal/gui.go
+++ b/ethereal/gui.go
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethlog"
+ "github.com/ethereum/eth-go/ethminer"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
@@ -40,6 +41,8 @@ type Gui struct {
Session string
clientIdentity *ethwire.SimpleClientIdentity
config *ethutil.ConfigManager
+
+ miner *ethminer.Miner
}
// Create GUI, but doesn't start it
@@ -124,6 +127,7 @@ func (gui *Gui) ToggleMining() {
txt = "Start mining"
} else {
utils.StartMining(gui.eth)
+ gui.miner = utils.GetMiner()
txt = "Stop mining"
}
@@ -280,12 +284,15 @@ func (gui *Gui) update() {
objectChan = make(chan ethutil.React, 1)
peerChan = make(chan ethutil.React, 1)
chainSyncChan = make(chan ethutil.React, 1)
+ miningChan = make(chan ethutil.React, 1)
)
reactor.Subscribe("newBlock", blockChan)
reactor.Subscribe("newTx:pre", txChan)
reactor.Subscribe("newTx:post", txChan)
reactor.Subscribe("chainSync", chainSyncChan)
+ reactor.Subscribe("miner:start", miningChan)
+ reactor.Subscribe("miner:stop", miningChan)
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
if nameReg != nil {
@@ -354,7 +361,18 @@ func (gui *Gui) update() {
gui.setPeerInfo()
case <-peerUpdateTicker.C:
gui.setPeerInfo()
+ case msg := <-miningChan:
+ if msg.Event == "miner:start" {
+ gui.miner = msg.Resource.(*ethminer.Miner)
+ } else {
+ gui.miner = nil
+ }
+
case <-generalUpdateTicker.C:
+ if gui.miner != nil {
+ pow := gui.miner.GetPow()
+ fmt.Println("HashRate from miner", pow.GetHashrate())
+ }
lastBlockLabel.Set("text", "#"+gui.eth.BlockChain().CurrentBlock.Number.String())
}
}
diff --git a/utils/cmd.go b/utils/cmd.go
index 1e1599582..f4d613c29 100644
--- a/utils/cmd.go
+++ b/utils/cmd.go
@@ -234,7 +234,11 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
}
}
-var miner ethminer.Miner
+var miner *ethminer.Miner
+
+func GetMiner() *ethminer.Miner {
+ return miner
+}
func StartMining(ethereum *eth.Ethereum) bool {
if !ethereum.Mining {
@@ -263,7 +267,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
}
func StopMining(ethereum *eth.Ethereum) bool {
- if ethereum.Mining {
+ if ethereum.Mining && miner != nil {
miner.Stop()
logger.Infoln("Miner stopped")
ethereum.Mining = false