aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-22 20:23:11 +0800
committerobscuren <geffobscura@gmail.com>2014-12-22 20:23:11 +0800
commit4051c0333f43765a7414a4e0e8ac51e7148b0646 (patch)
tree87c3637424820a681b88723bc666f3d01c069e82 /cmd
parente42517754ac2912b6d3ca78a34b8aeadf8805906 (diff)
downloaddexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.tar
dexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.tar.gz
dexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.tar.bz2
dexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.tar.lz
dexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.tar.xz
dexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.tar.zst
dexon-4051c0333f43765a7414a4e0e8ac51e7148b0646.zip
Added whisper js api
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mist/assets/qml/browser.qml40
-rw-r--r--cmd/mist/assets/qml/views/whisper.qml2
-rw-r--r--cmd/mist/gui.go64
-rw-r--r--cmd/mist/ui_lib.go162
4 files changed, 145 insertions, 123 deletions
diff --git a/cmd/mist/assets/qml/browser.qml b/cmd/mist/assets/qml/browser.qml
index 26fef0377..867260507 100644
--- a/cmd/mist/assets/qml/browser.qml
+++ b/cmd/mist/assets/qml/browser.qml
@@ -59,15 +59,18 @@ Rectangle {
}
Component.onCompleted: {
- //webview.url = "http://etherian.io"
- webview.url = "file:///Users/jeffrey/test.html"
+ webview.url = "http://etherian.io"
}
signal messages(var messages, int id);
onMessages: {
// Bit of a cheat to get proper JSON
var m = JSON.parse(JSON.parse(JSON.stringify(messages)))
- webview.postEvent("messages", [m, id]);
+ webview.postEvent("messages", id, m);
+ }
+
+ function onShhMessage(message, id) {
+ webview.postEvent("shhChanged", id, message)
}
Item {
@@ -328,6 +331,33 @@ Rectangle {
require(1);
eth.uninstallFilter(data.args[0])
break;
+
+
+ case "shhNewFilter":
+ require(1);
+ var id = shh.watch(data.args[0], window);
+ postData(data._id, id);
+ break;
+
+ case "newIdentity":
+ postData(data._id, shh.newIdentity())
+ break
+
+ case "post":
+ require(1);
+ var params = data.args[0];
+ var fields = ["payload", "to", "from"];
+ for(var i = 0; i < fields.length; i++) {
+ params[fields[i]] = params[fields[i]] || "";
+ }
+ if(typeof params.payload === "object") { params.payload = params.payload.join(""); }
+ params.topics = params.topics || [];
+ params.priority = params.priority || 1000;
+ params.ttl = params.ttl || 100;
+
+ console.log(JSON.stringify(params))
+ shh.post(params.payload, params.to, params.from, params.topics, params.priority, params.ttl);
+ break;
}
} catch(e) {
console.log(data.call + ": " + e)
@@ -349,8 +379,8 @@ Rectangle {
function postData(seed, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _id: seed}))
}
- function postEvent(event, data) {
- webview.experimental.postMessage(JSON.stringify({data: data, _event: event}))
+ function postEvent(event, id, data) {
+ webview.experimental.postMessage(JSON.stringify({data: data, _id: id, _event: event}))
}
function onWatchedCb(data, id) {
diff --git a/cmd/mist/assets/qml/views/whisper.qml b/cmd/mist/assets/qml/views/whisper.qml
index 80d401301..ffe391666 100644
--- a/cmd/mist/assets/qml/views/whisper.qml
+++ b/cmd/mist/assets/qml/views/whisper.qml
@@ -24,7 +24,7 @@ Rectangle {
var t = shh.watch({}, root)
}
- function onMessage(message) {
+ function onShhMessage(message, i) {
whisperModel.insert(0, {from: message.from, payload: eth.toAscii(message.payload)})
}
diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go
index e858d7c61..1152f0dcd 100644
--- a/cmd/mist/gui.go
+++ b/cmd/mist/gui.go
@@ -43,38 +43,6 @@ import (
"gopkg.in/qml.v1"
)
-/*
-func LoadExtension(path string) (uintptr, error) {
- lib, err := ffi.NewLibrary(path)
- if err != nil {
- return 0, err
- }
-
- so, err := lib.Fct("sharedObject", ffi.Pointer, nil)
- if err != nil {
- return 0, err
- }
-
- ptr := so()
-
- err = lib.Close()
- if err != nil {
- return 0, err
- }
-
- return ptr.Interface().(uintptr), nil
-}
-*/
-/*
- vec, errr := LoadExtension("/Users/jeffrey/Desktop/build-libqmltest-Desktop_Qt_5_2_1_clang_64bit-Debug/liblibqmltest_debug.dylib")
- fmt.Printf("Fetched vec with addr: %#x\n", vec)
- if errr != nil {
- fmt.Println(errr)
- } else {
- context.SetVar("vec", (unsafe.Pointer)(vec))
- }
-*/
-
var guilogger = logger.NewLogger("GUI")
type Gui struct {
@@ -535,3 +503,35 @@ func (gui *Gui) privateKey() string {
func (gui *Gui) address() []byte {
return gui.eth.KeyManager().Address()
}
+
+/*
+func LoadExtension(path string) (uintptr, error) {
+ lib, err := ffi.NewLibrary(path)
+ if err != nil {
+ return 0, err
+ }
+
+ so, err := lib.Fct("sharedObject", ffi.Pointer, nil)
+ if err != nil {
+ return 0, err
+ }
+
+ ptr := so()
+
+ err = lib.Close()
+ if err != nil {
+ return 0, err
+ }
+
+ return ptr.Interface().(uintptr), nil
+}
+*/
+/*
+ vec, errr := LoadExtension("/Users/jeffrey/Desktop/build-libqmltest-Desktop_Qt_5_2_1_clang_64bit-Debug/liblibqmltest_debug.dylib")
+ fmt.Printf("Fetched vec with addr: %#x\n", vec)
+ if errr != nil {
+ fmt.Println(errr)
+ } else {
+ context.SetVar("vec", (unsafe.Pointer)(vec))
+ }
+*/
diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go
index fd4ffcb84..4a92f6479 100644
--- a/cmd/mist/ui_lib.go
+++ b/cmd/mist/ui_lib.go
@@ -225,6 +225,83 @@ func (self *UiLib) StartDebugger() {
dbWindow.Show()
}
+func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
+ object := mapToTxParams(params)
+
+ return self.JSXEth.Transact(
+ object["from"],
+ object["to"],
+ object["value"],
+ object["gas"],
+ object["gasPrice"],
+ object["data"],
+ )
+}
+
+func (self *UiLib) Compile(code string) (string, error) {
+ bcode, err := ethutil.Compile(code, false)
+ if err != nil {
+ return err.Error(), err
+ }
+
+ return ethutil.Bytes2Hex(bcode), err
+}
+
+func (self *UiLib) Call(params map[string]interface{}) (string, error) {
+ object := mapToTxParams(params)
+
+ return self.JSXEth.Execute(
+ object["to"],
+ object["value"],
+ object["gas"],
+ object["gasPrice"],
+ object["data"],
+ )
+}
+
+func (self *UiLib) AddLocalTransaction(to, data, gas, gasPrice, value string) int {
+ return self.miner.AddLocalTx(&miner.LocalTx{
+ To: ethutil.Hex2Bytes(to),
+ Data: ethutil.Hex2Bytes(data),
+ Gas: gas,
+ GasPrice: gasPrice,
+ Value: value,
+ }) - 1
+}
+
+func (self *UiLib) RemoveLocalTransaction(id int) {
+ self.miner.RemoveLocalTx(id)
+}
+
+func (self *UiLib) SetGasPrice(price string) {
+ self.miner.MinAcceptedGasPrice = ethutil.Big(price)
+}
+
+func (self *UiLib) ToggleMining() bool {
+ if !self.miner.Mining() {
+ self.miner.Start()
+
+ return true
+ } else {
+ self.miner.Stop()
+
+ return false
+ }
+}
+
+func (self *UiLib) ToHex(data string) string {
+ return "0x" + ethutil.Bytes2Hex([]byte(data))
+}
+
+func (self *UiLib) ToAscii(data string) string {
+ start := 0
+ if len(data) > 1 && data[0:2] == "0x" {
+ start = 2
+ }
+ return string(ethutil.Hex2Bytes(data[start:]))
+}
+
+/// Ethereum filter methods
func (self *UiLib) NewFilter(object map[string]interface{}) (id int) {
filter := qt.NewFilterFromMap(object, self.eth)
filter.MessageCallback = func(messages state.Messages) {
@@ -312,88 +389,3 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
return conv
}
-
-func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
- object := mapToTxParams(params)
-
- return self.JSXEth.Transact(
- object["from"],
- object["to"],
- object["value"],
- object["gas"],
- object["gasPrice"],
- object["data"],
- )
-}
-
-func (self *UiLib) Compile(code string) (string, error) {
- bcode, err := ethutil.Compile(code, false)
- if err != nil {
- return err.Error(), err
- }
-
- return ethutil.Bytes2Hex(bcode), err
-}
-
-func (self *UiLib) Call(params map[string]interface{}) (string, error) {
- object := mapToTxParams(params)
-
- return self.JSXEth.Execute(
- object["to"],
- object["value"],
- object["gas"],
- object["gasPrice"],
- object["data"],
- )
-}
-
-func (self *UiLib) AddLocalTransaction(to, data, gas, gasPrice, value string) int {
- return self.miner.AddLocalTx(&miner.LocalTx{
- To: ethutil.Hex2Bytes(to),
- Data: ethutil.Hex2Bytes(data),
- Gas: gas,
- GasPrice: gasPrice,
- Value: value,
- }) - 1
-}
-
-func (self *UiLib) RemoveLocalTransaction(id int) {
- self.miner.RemoveLocalTx(id)
-}
-
-func (self *UiLib) SetGasPrice(price string) {
- self.miner.MinAcceptedGasPrice = ethutil.Big(price)
-}
-
-func (self *UiLib) ToggleMining() bool {
- if !self.miner.Mining() {
- self.miner.Start()
-
- return true
- } else {
- self.miner.Stop()
-
- return false
- }
-}
-
-func (self *UiLib) ToHex(data string) string {
- return "0x" + ethutil.Bytes2Hex([]byte(data))
-}
-
-func (self *UiLib) ToAscii(data string) string {
- start := 0
- if len(data) > 1 && data[0:2] == "0x" {
- start = 2
- }
- return string(ethutil.Hex2Bytes(data[start:]))
-}
-
-/*
-// XXX Refactor me & MOVE
-func (self *Ethereum) InstallFilter(filter *core.Filter) (id int) {
- return self.filterManager.InstallFilter(filter)
-}
-func (self *Ethereum) UninstallFilter(id int) { self.filterManager.UninstallFilter(id) }
-func (self *Ethereum) GetFilter(id int) *core.Filter { return self.filterManager.GetFilter(id) }
-*/