Skip to content

Commit 7843390

Browse files
author
Maran
committed
Implement getStateKeyVal for JS bindings.
Gives JS the option to 'loop' over contract key/val storage
1 parent 307fe4a commit 7843390

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

ethereal/assets/ext/ethereum.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ window.eth = {
3232
postData({call: "getStorage", args: [address, storageAddress]}, cb);
3333
},
3434

35+
getStateKeyVals: function(address, cb){
36+
postData({call: "getStateKeyVals", args: [address]}, cb);
37+
},
38+
3539
getKey: function(cb) {
3640
postData({call: "getKey"}, cb);
3741
},

ethereal/assets/qml/webapp.qml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ ApplicationWindow {
3434
top: parent.top
3535
}
3636
*/
37-
3837
onTitleChanged: { window.title = title }
3938
experimental.preferences.javascriptEnabled: true
4039
experimental.preferences.navigatorQtObjectEnabled: true
@@ -97,6 +96,12 @@ ApplicationWindow {
9796
var storage = stateObject.getStorage(data.args[1])
9897
postData(data._seed, storage)
9998

99+
break
100+
case "getStateKeyVals":
101+
require(1);
102+
var stateObject = eth.getStateObject(data.args[0]).stateKeyVal(true)
103+
postData(data._seed,stateObject)
104+
100105
break
101106
case "getBalance":
102107
require(1);
@@ -188,7 +193,7 @@ ApplicationWindow {
188193

189194
WebView {
190195
id: inspector
191-
visible: false
196+
visible: true
192197
url: webview.experimental.remoteInspectorUrl
193198
anchors {
194199
left: root.left

ethereal/ui/gui.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func (gui *Gui) Start(assetPath string) {
6565
Init: func(p *ethpub.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
6666
}, {
6767
Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
68+
}, {
69+
Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
6870
}})
6971

7072
ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version))

ethereum/repl.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func (self *JSEthereum) GetStateObject(addr string) otto.Value {
7878
return self.toVal(self.PEthereum.GetStateObject(addr))
7979
}
8080

81+
func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
82+
return self.toVal(self.PEthereum.GetStateObject(addr).StateKeyVal(false))
83+
}
84+
8185
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
8286
r, err := self.PEthereum.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
8387
if err != nil {
@@ -105,7 +109,7 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
105109
result, err := self.vm.ToValue(v)
106110

107111
if err != nil {
108-
fmt.Println(err)
112+
fmt.Println("Value unknown:", err)
109113

110114
return otto.UndefinedValue()
111115
}

0 commit comments

Comments
 (0)