Skip to content

Commit 75df148

Browse files
committed
Fixed miner channel
2 parents 2b9f168 + 4572d49 commit 75df148

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed

ethereal/assets/qml/wallet.qml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -419,42 +419,54 @@ ApplicationWindow {
419419
}
420420
}
421421

422+
Label {
423+
y: 6
424+
id: lastBlockLabel
425+
objectName: "lastBlockLabel"
426+
visible: true
427+
text: ""
428+
font.pixelSize: 10
429+
anchors.right: peerGroup.left
430+
anchors.rightMargin: 5
431+
}
432+
422433
ProgressBar {
423434
id: syncProgressIndicator
424435
visible: false
425436
objectName: "syncProgressIndicator"
426437
y: 3
427438
width: 140
428439
indeterminate: true
429-
anchors.right: peerLabel.left
440+
anchors.right: peerGroup.left
430441
anchors.rightMargin: 5
431442
}
432443

433-
Label {
434-
y: 7
435-
anchors.right: peerImage.left
436-
anchors.rightMargin: 5
437-
id: peerLabel
438-
font.pixelSize: 8
439-
text: "0 / 0"
440-
}
441-
Image {
442-
y: 7
443-
id: peerImage
444-
anchors.right: parent.right
445-
width: 10; height: 10
446-
MouseArea {
447-
onDoubleClicked: peerWindow.visible = true
448-
anchors.fill: parent
449-
}
450-
source: "../network.png"
451-
}
444+
RowLayout {
445+
id: peerGroup
446+
y: 7
447+
anchors.right: parent.right
448+
MouseArea {
449+
onDoubleClicked: peerWindow.visible = true
450+
anchors.fill: parent
451+
}
452+
453+
Label {
454+
id: peerLabel
455+
font.pixelSize: 8
456+
text: "0 / 0"
457+
}
458+
Image {
459+
id: peerImage
460+
width: 10; height: 10
461+
source: "../network.png"
462+
}
463+
}
452464
}
453465

454466
Window {
455467
id: popup
456468
visible: false
457-
flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
469+
//flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
458470
property var block
459471
width: root.width
460472
height: 300
@@ -589,7 +601,7 @@ ApplicationWindow {
589601

590602
Window {
591603
id: addPeerWin
592-
flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
604+
//flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
593605
visible: false
594606
minimumWidth: 230
595607
maximumWidth: 230
@@ -756,7 +768,7 @@ ApplicationWindow {
756768
// ******************************************
757769
Window {
758770
id: peerWindow
759-
flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
771+
//flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
760772
height: 200
761773
width: 700
762774
Rectangle {

ethereal/debugger.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type DebuggerWindow struct {
1717

1818
vm *ethchain.Vm
1919
Db *Debugger
20+
21+
state *ethchain.State
2022
}
2123

2224
func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
@@ -53,6 +55,7 @@ func (self *DebuggerWindow) SetCode(code string) {
5355
func (self *DebuggerWindow) SetData(data string) {
5456
self.win.Set("dataText", data)
5557
}
58+
5659
func (self *DebuggerWindow) SetAsm(data []byte) {
5760
self.win.Root().Call("clearAsm")
5861

ethereal/gui.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
270270
gui.win.Root().Call("setWalletValue", str)
271271
}
272272

273+
func (self *Gui) getObjectByName(objectName string) qml.Object {
274+
return self.win.Root().ObjectByName(objectName)
275+
}
276+
273277
// Simple go routine function that updates the list of peers in the GUI
274278
func (gui *Gui) update() {
275279
reactor := gui.eth.Reactor()
@@ -280,26 +284,32 @@ func (gui *Gui) update() {
280284
objectChan = make(chan ethutil.React, 1)
281285
peerChan = make(chan ethutil.React, 1)
282286
chainSyncChan = make(chan ethutil.React, 1)
287+
miningChan = make(chan ethutil.React, 1)
283288
)
284289

285290
reactor.Subscribe("newBlock", blockChan)
286291
reactor.Subscribe("newTx:pre", txChan)
287292
reactor.Subscribe("newTx:post", txChan)
288293
reactor.Subscribe("chainSync", chainSyncChan)
294+
reactor.Subscribe("miner:start", miningChan)
295+
reactor.Subscribe("miner:stop", miningChan)
289296

290297
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
291298
if nameReg != nil {
292299
reactor.Subscribe("object:"+string(nameReg.Address()), objectChan)
293300
}
294301
reactor.Subscribe("peerList", peerChan)
295302

296-
ticker := time.NewTicker(5 * time.Second)
303+
peerUpdateTicker := time.NewTicker(5 * time.Second)
304+
generalUpdateTicker := time.NewTicker(1 * time.Second)
297305

298306
state := gui.eth.StateManager().TransState()
299307

300308
unconfirmedFunds := new(big.Int)
301309
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount)))
302-
gui.win.Root().ObjectByName("syncProgressIndicator").Set("visible", !gui.eth.IsUpToDate())
310+
gui.getObjectByName("syncProgressIndicator").Set("visible", !gui.eth.IsUpToDate())
311+
312+
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
303313

304314
for {
305315
select {
@@ -349,12 +359,21 @@ func (gui *Gui) update() {
349359
gui.loadAddressBook()
350360
case <-peerChan:
351361
gui.setPeerInfo()
352-
case <-ticker.C:
362+
case <-peerUpdateTicker.C:
363+
gui.setPeerInfo()
364+
case msg := <-miningChan:
365+
if msg.Event == "miner:start" {
366+
gui.miner = msg.Resource.(*ethminer.Miner)
367+
} else {
368+
gui.miner = nil
369+
}
370+
371+
case <-generalUpdateTicker.C:
353372
if gui.miner != nil {
354373
pow := gui.miner.GetPow()
355374
fmt.Println("HashRate from miner", pow.GetHashrate())
356375
}
357-
gui.setPeerInfo()
376+
lastBlockLabel.Set("text", "#"+gui.eth.BlockChain().CurrentBlock.Number.String())
358377
}
359378
}
360379
}

utils/cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
234234
}
235235
}
236236

237-
var miner ethminer.Miner
237+
var miner *ethminer.Miner
238238

239239
func GetMiner() *ethminer.Miner {
240-
return &miner
240+
return miner
241241
}
242242

243243
func StartMining(ethereum *eth.Ethereum) bool {
@@ -267,7 +267,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
267267
}
268268

269269
func StopMining(ethereum *eth.Ethereum) bool {
270-
if ethereum.Mining {
270+
if ethereum.Mining && miner != nil {
271271
miner.Stop()
272272
logger.Infoln("Miner stopped")
273273
ethereum.Mining = false

0 commit comments

Comments
 (0)