Skip to content

Commit 27735bb

Browse files
committed
State dumps from gui
1 parent 2eab964 commit 27735bb

File tree

10 files changed

+158
-26
lines changed

10 files changed

+158
-26
lines changed

ethereal/assets/ext/ethereum.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ window.eth = {
66

77
test: function() {
88
var t = undefined;
9-
navigator.qt.onmessage = function(d) { t = d; }
9+
postData({call: "test"})
10+
navigator.qt.onmessage = function(d) {console.log("onmessage called"); t = d; }
1011
for(;;) {
1112
if(t !== undefined) {
1213
return t
1314
}
1415
}
1516
},
1617

17-
mutan: function(code) {
18+
mutan: function(code, cb) {
19+
postData({call: "mutan", args: [code]}, cb)
1820
},
1921

2022
toHex: function(str) {
@@ -281,3 +283,13 @@ navigator.qt.onmessage = function(ev) {
281283
}
282284
}
283285
}
286+
287+
eth.on("chain:changed", function() {
288+
})
289+
290+
eth.on("messages", { /* filters */}, function(messages){
291+
})
292+
293+
eth.on("pending:changed", function() {
294+
})
295+

ethereal/assets/ext/test.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
eth.getBlock("f70097659f329a09642a27f11338d9269de64f1d4485786e36bfc410832148cd", function(block) {
3333
console.log(block)
3434
})
35+
36+
eth.mutan("var a = 10", function(code) {
37+
console.log("code", code)
38+
});
3539
}
3640
</script>
3741

ethereal/assets/qml/views/chain.qml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,57 @@ Rectangle {
2525

2626
model: blockModel
2727

28-
onDoubleClicked: {
29-
popup.visible = true
30-
popup.setDetails(blockModel.get(row))
28+
itemDelegate: Item {
29+
Text {
30+
anchors {
31+
left: parent.left
32+
right: parent.right
33+
leftMargin: 10
34+
verticalCenter: parent.verticalCenter
35+
}
36+
color: styleData.textColor
37+
elide: styleData.elideMode
38+
text: styleData.value
39+
font.pixelSize: 11
40+
MouseArea {
41+
acceptedButtons: Qt.RightButton
42+
propagateComposedEvents: true
43+
anchors.fill: parent
44+
onClicked: {
45+
blockTable.selection.clear()
46+
blockTable.selection.select(styleData.row)
47+
48+
contextMenu.row = styleData.row;
49+
contextMenu.popup()
50+
}
51+
}
52+
}
53+
54+
}
55+
56+
Menu {
57+
id: contextMenu
58+
property var row;
59+
MenuItem {
60+
text: "Details"
61+
onTriggered: {
62+
popup.visible = true
63+
popup.setDetails(blockModel.get(this.row))
64+
}
65+
}
66+
67+
MenuSeparator{}
68+
69+
MenuItem {
70+
text: "Dump State"
71+
onTriggered: {
72+
generalFileDialog.show(false, function(path) {
73+
var hash = blockModel.get(this.row).hash;
74+
75+
gui.dumpState(hash, path);
76+
});
77+
}
78+
}
3179
}
3280
}
3381

ethereal/assets/qml/wallet.qml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ ApplicationWindow {
4949
text: "Import App"
5050
shortcut: "Ctrl+o"
5151
onTriggered: {
52-
generalFileDialog.callback = importApp;
53-
generalFileDialog.open()
52+
generalFileDialog.show(true, importApp)
5453
}
5554
}
5655

@@ -62,10 +61,9 @@ ApplicationWindow {
6261
MenuItem {
6362
text: "Add plugin"
6463
onTriggered: {
65-
generalFileDialog.callback = function(path) {
64+
generalFileDialog.show(true, function(path) {
6665
addPlugin(path, {canClose: true})
67-
}
68-
generalFileDialog.open()
66+
})
6967
}
7068
}
7169

@@ -75,20 +73,18 @@ ApplicationWindow {
7573
text: "Import key"
7674
shortcut: "Ctrl+i"
7775
onTriggered: {
78-
generalFileDialog.callback = function(path) {
79-
ui.importKey(path)
80-
}
81-
generalFileDialog.open()
76+
generalFileDialog.show(true, function(path) {
77+
gui.importKey(path)
78+
})
8279
}
8380
}
8481

8582
MenuItem {
8683
text: "Export keys"
8784
shortcut: "Ctrl+e"
8885
onTriggered: {
89-
generalFileDialog.callback = function(path) {
90-
}
91-
generalFileDialog.open()
86+
generalFileDialog.show(false, function(path) {
87+
})
9288
}
9389
}
9490
}
@@ -111,10 +107,19 @@ ApplicationWindow {
111107
MenuItem {
112108
text: "Run JS file"
113109
onTriggered: {
114-
generalFileDialog.callback = function(path) {
110+
generalFileDialog.show(true, function(path) {
115111
eth.evalJavascriptFile(path)
116-
}
117-
generalFileDialog.open()
112+
})
113+
}
114+
}
115+
116+
MenuItem {
117+
text: "Dump state"
118+
onTriggered: {
119+
generalFileDialog.show(false, function(path) {
120+
// Empty hash for latest
121+
gui.dumpState("", path)
122+
})
118123
}
119124
}
120125
}
@@ -396,8 +401,15 @@ ApplicationWindow {
396401
id: generalFileDialog
397402
property var callback;
398403
onAccepted: {
399-
var path = this.fileUrl.toString()
400-
callback.call(this, path)
404+
var path = this.fileUrl.toString();
405+
callback.call(this, path);
406+
}
407+
408+
function show(selectExisting, callback) {
409+
generalFileDialog.callback = callback;
410+
generalFileDialog.selectExisting = selectExisting;
411+
412+
this.open();
401413
}
402414
}
403415

ethereal/assets/qml/webapp.qml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ApplicationWindow {
7878
}
7979
}
8080

81+
8182
WebView {
8283
objectName: "webView"
8384
id: webview
@@ -127,6 +128,8 @@ ApplicationWindow {
127128
this.cleanPath = false;
128129
}
129130
}
131+
132+
130133
experimental.preferences.javascriptEnabled: true
131134
experimental.preferences.navigatorQtObjectEnabled: true
132135
experimental.preferences.developerExtrasEnabled: true
@@ -251,9 +254,13 @@ ApplicationWindow {
251254

252255
break
253256

254-
case "debug":
255-
console.log(data.args[0]);
256-
break;
257+
case "mutan":
258+
require(1)
259+
260+
var code = eth.compileMutan(data.args[0])
261+
postData(data._seed, "0x"+code)
262+
263+
break;
257264
}
258265
} catch(e) {
259266
console.log(data.call + ": " + e)
@@ -262,6 +269,11 @@ ApplicationWindow {
262269
}
263270
}
264271

272+
function post(seed, data) {
273+
console.log("data", data)
274+
postData(data._seed, data)
275+
}
276+
265277
function require(args, num) {
266278
if(args.length < num) {
267279
throw("required argument count of "+num+" got "+args.length);

ethereal/ext_app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type AppContainer interface {
2121
NewBlock(*ethchain.Block)
2222
NewWatcher(chan bool)
2323
Messages(ethstate.Messages, string)
24+
Post(string, int)
2425
}
2526

2627
type ExtApplication struct {

ethereal/gui.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"math/big"
7+
"os"
78
"strconv"
89
"strings"
910
"time"
@@ -155,6 +156,40 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
155156
return gui.win, nil
156157
}
157158

159+
func (self *Gui) DumpState(hash, path string) {
160+
var stateDump []byte
161+
162+
if len(hash) == 0 {
163+
stateDump = self.eth.StateManager().CurrentState().Dump()
164+
} else {
165+
var block *ethchain.Block
166+
if hash[0] == '#' {
167+
i, _ := strconv.Atoi(hash[1:])
168+
block = self.eth.BlockChain().GetBlockByNumber(uint64(i))
169+
} else {
170+
block = self.eth.BlockChain().GetBlock(ethutil.Hex2Bytes(hash))
171+
}
172+
173+
if block == nil {
174+
logger.Infof("block err: not found %s\n", hash)
175+
return
176+
}
177+
178+
stateDump = block.State().Dump()
179+
}
180+
181+
file, err := os.OpenFile(path[7:], os.O_CREATE|os.O_RDWR, os.ModePerm)
182+
if err != nil {
183+
logger.Infoln("dump err: ", err)
184+
return
185+
}
186+
defer file.Close()
187+
188+
logger.Infof("dumped state (%s) to %s\n", hash, path)
189+
190+
file.Write(stateDump)
191+
}
192+
158193
// The done handler will be called by QML when all views have been loaded
159194
func (gui *Gui) Done() {
160195
gui.qmlDone = true

ethereal/html_container.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"encoding/json"
55
"errors"
6+
"fmt"
67
"io/ioutil"
78
"net/url"
89
"os"
@@ -139,3 +140,8 @@ func (self *HtmlApplication) Messages(messages ethstate.Messages, id string) {
139140
func (app *HtmlApplication) Destroy() {
140141
app.engine.Destroy()
141142
}
143+
144+
func (app *HtmlApplication) Post(data string, seed int) {
145+
fmt.Println("about to call 'post'")
146+
app.webView.Call("post", seed, data)
147+
}

ethereal/qml_container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ func (app *QmlApplication) Engine() *qml.Engine {
6464
func (app *QmlApplication) Window() *qml.Window {
6565
return app.win
6666
}
67+
68+
func (app *QmlApplication) Post(data string, s int) {}

ethereum/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func main() {
7171
}
7272

7373
// Leave the Println. This needs clean output for piping
74-
fmt.Println(block.State().Dump())
74+
fmt.Printf("%s\n", block.State().Dump())
7575

7676
os.Exit(0)
7777
}

0 commit comments

Comments
 (0)