Skip to content

Commit

Permalink
Implement getStateKeyVal for JS bindings.
Browse files Browse the repository at this point in the history
Gives JS the option to 'loop' over contract key/val storage
  • Loading branch information
Maran committed Jun 4, 2014
1 parent 307fe4a commit 7843390
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ethereal/assets/ext/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ window.eth = {
postData({call: "getStorage", args: [address, storageAddress]}, cb);
},

getStateKeyVals: function(address, cb){
postData({call: "getStateKeyVals", args: [address]}, cb);
},

getKey: function(cb) {
postData({call: "getKey"}, cb);
},
Expand Down
9 changes: 7 additions & 2 deletions ethereal/assets/qml/webapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ApplicationWindow {
top: parent.top
}
*/

onTitleChanged: { window.title = title }
experimental.preferences.javascriptEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
Expand Down Expand Up @@ -97,6 +96,12 @@ ApplicationWindow {
var storage = stateObject.getStorage(data.args[1])
postData(data._seed, storage)

break
case "getStateKeyVals":
require(1);
var stateObject = eth.getStateObject(data.args[0]).stateKeyVal(true)
postData(data._seed,stateObject)

break
case "getBalance":
require(1);
Expand Down Expand Up @@ -188,7 +193,7 @@ ApplicationWindow {

WebView {
id: inspector
visible: false
visible: true
url: webview.experimental.remoteInspectorUrl
anchors {
left: root.left
Expand Down
2 changes: 2 additions & 0 deletions ethereal/ui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (gui *Gui) Start(assetPath string) {
Init: func(p *ethpub.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
}, {
Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
}, {
Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
}})

ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version))
Expand Down
6 changes: 5 additions & 1 deletion ethereum/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (self *JSEthereum) GetStateObject(addr string) otto.Value {
return self.toVal(self.PEthereum.GetStateObject(addr))
}

func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
return self.toVal(self.PEthereum.GetStateObject(addr).StateKeyVal(false))
}

func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
r, err := self.PEthereum.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
if err != nil {
Expand Down Expand Up @@ -105,7 +109,7 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
result, err := self.vm.ToValue(v)

if err != nil {
fmt.Println(err)
fmt.Println("Value unknown:", err)

return otto.UndefinedValue()
}
Expand Down

1 comment on commit 7843390

@obscuren
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit might needs to be changed or reversed. It has never been the intention to support the Each function throughout the project because it's very inefficient.

The JS bindings are also part of something more "official" that should be approved by multiple developers before implementing. I don't want to have a "Microsoft" type of situation where one program works in one client and doesn't in the other.

Please sign in to comment.