From dc99dfb99d5aab11074828bc86e39216c90c0314 Mon Sep 17 00:00:00 2001 From: emizzle Date: Fri, 8 May 2020 21:07:50 +1000 Subject: [PATCH 1/9] feat: Connect to peer and call private RPC --- src/applicationLogic.nim | 9 ++++++++- src/libstatus.nim | 6 ++++++ src/status.nim | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 564734b4bc..710ef78a0b 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -14,9 +14,12 @@ QtObject: result.setup() status.setupNewAccount() + discard status.addPeer("enode://2c8de3cbb27a3d30cbb5b3e003bc722b126f5aef82e2052aaef032ca94e0c7ad219e533ba88c70585ebd802de206693255335b100307645ab5170e88620d2a81@47.244.221.14:443") + echo status.callPrivateRPC("{\"jsonrpc\":\"2.0\", \"method\":\"wakuext_requestMessages\", \"params\":[{\"topics\": [\"0x7998f3c8\"]}], \"id\": 1}") # ¯\_(ツ)_/¯ dunno what is this proc setup(self: ApplicationLogic) = + # discard status.onMessage(self.onMessage) self.QObject.setup # ¯\_(ツ)_/¯ seems to be a method for garbage collection @@ -47,5 +50,9 @@ QtObject: notify = callResultChanged proc onSend*(self: ApplicationLogic, inputJSON: string) {.slot.} = - self.setCallResult(status.callRPC(inputJSON)) + self.setCallResult(status.callPrivateRPC(inputJSON)) echo "Done!: ", self.callResult + + # proc onMessage*(self: ApplicationLogic, message: string) {.slot.} = + # self.setCallResult(message) + # echo "Received message: ", message diff --git a/src/libstatus.nim b/src/libstatus.nim index 2bfe1f245a..29ce3c8661 100644 --- a/src/libstatus.nim +++ b/src/libstatus.nim @@ -11,3 +11,9 @@ proc multiAccountStoreDerivedAccounts*(paramsJSON: cstring): cstring {.importc: proc saveAccountAndLogin*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring): cstring {.importc: "SaveAccountAndLogin".} proc callRPC*(inputJSON: cstring): cstring {.importc: "CallRPC".} + +proc callPrivateRPC*(inputJSON: cstring): cstring {.importc: "CallPrivateRPC".} + +proc addPeer*(peer: cstring): cstring {.importc: "AddPeer".} + +# proc setSignalEventCallback*(callback: proc): void {.importc: "SetSignalEventCallback".} diff --git a/src/status.nim b/src/status.nim index 9e42123d8c..3cc6aa5819 100644 --- a/src/status.nim +++ b/src/status.nim @@ -269,3 +269,12 @@ proc setupNewAccount*() = proc callRPC*(inputJSON: string): string = return $libstatus.callRPC(inputJSON) + +proc callPrivateRPC*(inputJSON: string): string = + return $libstatus.callPrivateRPC(inputJSON) + +proc addPeer*(peer: string): string = + return $libstatus.addPeer(peer) + +# proc onMessage*(callback: proc(message: string)): void = +# $libstatus.setSignalEventCallback(callback) From a4b69c4e5e204d1bf10459664502ae36fca8aa28 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 8 May 2020 10:51:32 -0400 Subject: [PATCH 2/9] fix: fix README for Linux --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f1695a5b79..fe63dc19a3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Experiments calling status-go from nim, inspired in [nim-stratus](https://github ``` # linux -??? apt-get install nim ??? +apt-get install nim # macos brew install nim @@ -26,6 +26,12 @@ export PATH=$PATH:/path/to/Qt/5.14.2/clang_64/bin ### 3. Clone and build DOtherside +For Linux: +``` +sudo apt-get install build-essential libgl1-mesa-dev +sudo apt-get install doxygen +``` + ``` git clone https://github.com/filcuc/DOtherSide cd DOtherSide From c95e7db18749eeec3631a4acf46dbc6752700f4e Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 7 May 2020 14:20:18 -0400 Subject: [PATCH 3/9] feat: subscribing to signals --- nim_status_client.nimble | 18 +++++++++--------- src/applicationLogic.nim | 12 ++++++++++++ src/libstatus.nim | 4 +++- src/status.nim | 3 +++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/nim_status_client.nimble b/nim_status_client.nimble index 0e1cf98831..198903cff3 100644 --- a/nim_status_client.nimble +++ b/nim_status_client.nimble @@ -1,10 +1,10 @@ -[Package] -version = "0.1.0" -author = "Richard Ramos" -description = "A new awesome nimble package" -license = "MIT" -srcDir = "src" -bin = "nim_status_client" +# Package -[Deps] -Requires: "nim >= 1.0.0, nimqml >= 0.7.0" \ No newline at end of file +version = "0.1.0" +author = "Your Name" +description = "Example .nimble file." +license = "MIT" + +# Deps + +requires "nim >= 0.10.0" \ No newline at end of file diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 710ef78a0b..94cd27aca7 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -1,5 +1,12 @@ import NimQml import status +import libstatus + + +var signalHandler: SignalCallback = proc(p0: cstring): void = + setupForeignThreadGc() + echo $p0 + tearDownForeignThreadGc() QtObject: type ApplicationLogic* = ref object of QObject @@ -17,6 +24,11 @@ QtObject: discard status.addPeer("enode://2c8de3cbb27a3d30cbb5b3e003bc722b126f5aef82e2052aaef032ca94e0c7ad219e533ba88c70585ebd802de206693255335b100307645ab5170e88620d2a81@47.244.221.14:443") echo status.callPrivateRPC("{\"jsonrpc\":\"2.0\", \"method\":\"wakuext_requestMessages\", \"params\":[{\"topics\": [\"0x7998f3c8\"]}], \"id\": 1}") + # Experiment + status.setSignalHandler(signalHandler) + + + # ¯\_(ツ)_/¯ dunno what is this proc setup(self: ApplicationLogic) = # discard status.onMessage(self.onMessage) diff --git a/src/libstatus.nim b/src/libstatus.nim index 29ce3c8661..cd836ee047 100644 --- a/src/libstatus.nim +++ b/src/libstatus.nim @@ -16,4 +16,6 @@ proc callPrivateRPC*(inputJSON: cstring): cstring {.importc: "CallPrivateRPC".} proc addPeer*(peer: cstring): cstring {.importc: "AddPeer".} -# proc setSignalEventCallback*(callback: proc): void {.importc: "SetSignalEventCallback".} +type SignalCallback* = proc(eventMessage: cstring): void + +proc setSignalEventCallback*(callback: SignalCallback) {.importc: "SetSignalEventCallback".} diff --git a/src/status.nim b/src/status.nim index 3cc6aa5819..a0ad7c16c5 100644 --- a/src/status.nim +++ b/src/status.nim @@ -11,6 +11,9 @@ proc recreateDir(dirname: string) = removeDir(dirname) createDir(dirname) +proc setSignalHandler*(something: SignalCallback) = + libstatus.setSignalEventCallback(something) + proc setupNewAccount*() = # Deleting directories recreateDir(datadir) From d5d4c03003b9dbb07e28592701f230a64aee292e Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 7 May 2020 16:02:22 -0400 Subject: [PATCH 4/9] test --- src/applicationLogic.nim | 5 +++-- src/status.nim | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 94cd27aca7..517119ebc0 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -20,12 +20,13 @@ QtObject: result.callResult = "Use this tool to call JSONRPC methods" result.setup() + status.setSignalHandler(signalHandler) + status.setupNewAccount() discard status.addPeer("enode://2c8de3cbb27a3d30cbb5b3e003bc722b126f5aef82e2052aaef032ca94e0c7ad219e533ba88c70585ebd802de206693255335b100307645ab5170e88620d2a81@47.244.221.14:443") echo status.callPrivateRPC("{\"jsonrpc\":\"2.0\", \"method\":\"wakuext_requestMessages\", \"params\":[{\"topics\": [\"0x7998f3c8\"]}], \"id\": 1}") - # Experiment - status.setSignalHandler(signalHandler) + status.subscribeToTest() diff --git a/src/status.nim b/src/status.nim index a0ad7c16c5..9413e8bd0b 100644 --- a/src/status.nim +++ b/src/status.nim @@ -14,6 +14,51 @@ proc recreateDir(dirname: string) = proc setSignalHandler*(something: SignalCallback) = libstatus.setSignalEventCallback(something) +proc subscribeToTest*() = + var payload = %* { + "jasonrpc": "2.0", + "id": 2, + "method": "waku_generateSymKeyFromPassword", + "params": ["test"] + } + var result = $libstatus.callPrivateRPC($payload) + let keyId = $result.parseJson()["result"] + + var topic = "0x9c22ff5f"; #sha3 of test + + payload = %* { + "jsonrpc": "2.0", + "id": 3, + "method": "wakuext_loadFilters", + "params": [ + [{ + "chatId": "test", + "symKeyId": keyId, + "topic": topic, + "discovery": false, + "negotiated": false, + "listen": true + }] + ] + } + + result = $libstatus.callPrivateRPC($payload) + echo result; + + payload = %* { + "jsonrpc": "2.0", + "id": 3, + "method": "wakuext_startMessenger", + "params": [] + } + result = $libstatus.callPrivateRPC($payload) + + + + + + + proc setupNewAccount*() = # Deleting directories recreateDir(datadir) From 8a464eb0d8b3c77c6d5c0945ba40a1aa11ae5cfe Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 7 May 2020 16:04:16 -0400 Subject: [PATCH 5/9] test --- nim_status_client.nimble | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nim_status_client.nimble b/nim_status_client.nimble index 198903cff3..3ac8680214 100644 --- a/nim_status_client.nimble +++ b/nim_status_client.nimble @@ -1,10 +1,10 @@ -# Package +[Package] +version = "0.1.0" +author = "Richard Ramos" +description = "A new awesome nimble package" +license = "MIT" +srcDir = "src" +bin = "nim_status_client" -version = "0.1.0" -author = "Your Name" -description = "Example .nimble file." -license = "MIT" - -# Deps - -requires "nim >= 0.10.0" \ No newline at end of file +[Deps] +Requires: "nim >= 1.0.0, nimqml >= 0.7.0" From a5d2f25b01966a70680caf2b35fdfc76e6d58073 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 8 May 2020 08:42:43 -0400 Subject: [PATCH 6/9] Getting messages from #test --- src/applicationLogic.nim | 7 +++- src/status.nim | 81 ++++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 517119ebc0..8483e57b72 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -1,11 +1,16 @@ import NimQml import status import libstatus +import json var signalHandler: SignalCallback = proc(p0: cstring): void = setupForeignThreadGc() - echo $p0 + + var jsonSignal = ($p0).parseJson + if $jsonSignal["type"].getStr == "messages.new": + echo $p0 + tearDownForeignThreadGc() QtObject: diff --git a/src/status.nim b/src/status.nim index 9413e8bd0b..ecf460dabf 100644 --- a/src/status.nim +++ b/src/status.nim @@ -15,37 +15,9 @@ proc setSignalHandler*(something: SignalCallback) = libstatus.setSignalEventCallback(something) proc subscribeToTest*() = + var result = "" + var payload = %* { - "jasonrpc": "2.0", - "id": 2, - "method": "waku_generateSymKeyFromPassword", - "params": ["test"] - } - var result = $libstatus.callPrivateRPC($payload) - let keyId = $result.parseJson()["result"] - - var topic = "0x9c22ff5f"; #sha3 of test - - payload = %* { - "jsonrpc": "2.0", - "id": 3, - "method": "wakuext_loadFilters", - "params": [ - [{ - "chatId": "test", - "symKeyId": keyId, - "topic": topic, - "discovery": false, - "negotiated": false, - "listen": true - }] - ] - } - - result = $libstatus.callPrivateRPC($payload) - echo result; - - payload = %* { "jsonrpc": "2.0", "id": 3, "method": "wakuext_startMessenger", @@ -53,8 +25,53 @@ proc subscribeToTest*() = } result = $libstatus.callPrivateRPC($payload) - - + payload = %* { + "jsonrpc": "2.0", + "id": 3, + "method": "wakuext_loadFilters", + "params": [ + [{ + "ChatID":"test", + "OneToOne":false + }] + ] + } + result = $libstatus.callPrivateRPC($payload) + + + payload = %* { + "jsonrpc": "2.0", + "id": 4, + "method": "wakuext_saveChat", + "params": [ + { + "lastClockValue":0, + "color":"#51d0f0", + "name":"test", + "lastMessage":nil, + "active":true, + "id":"test", + "unviewedMessagesCount":0, + "chatType":2, + "timestamp":1588940692659 + } + ] + } + result = $libstatus.callPrivateRPC($payload) + + + + payload = %* { + "jsonrpc": "2.0", + "id": 3, + "method": "wakuext_chatMessages", + "params": [ + "test", nil, 20 + ] + } + result = $libstatus.callPrivateRPC($payload) + + From 5a174f260a19314578ad7f9ad5ad91180378216d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 May 2020 11:44:07 -0400 Subject: [PATCH 7/9] add missing flag --- src/nim_status_client.nim.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nim_status_client.nim.cfg b/src/nim_status_client.nim.cfg index aed303eef8..6a6fa07699 100644 --- a/src/nim_status_client.nim.cfg +++ b/src/nim_status_client.nim.cfg @@ -1 +1,2 @@ --threads:on +--tlsEmulation:off From aba191841bb1e6ffa4e91bfe34f699b89335e91a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 May 2020 11:25:16 -0400 Subject: [PATCH 8/9] display account --- main.qml | 10 ++++++++-- src/applicationLogic.nim | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/main.qml b/main.qml index bab1e79bec..5194eb9da1 100644 --- a/main.qml +++ b/main.qml @@ -21,6 +21,7 @@ ApplicationWindow { id: tabBar width: 50 height: width *2 + spacing + currentIndex: 0 transformOrigin: Item.Top Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.fillHeight: true @@ -141,9 +142,14 @@ ApplicationWindow { } - Item { + ColumnLayout { + anchors.fill: parent - } + RowLayout { + Layout.fillHeight: true + TextArea { id: accountsResult; Layout.fillWidth: true; text: logic.accountsResult; readOnly: true } + } + } Item { diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 8483e57b72..7e6d954c58 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -17,6 +17,7 @@ QtObject: type ApplicationLogic* = ref object of QObject app: QApplication callResult: string + accountResult: string # Constructor proc newApplicationLogic*(app: QApplication): ApplicationLogic = @@ -58,6 +59,7 @@ QtObject: proc setCallResult(self: ApplicationLogic, callResult: string) {.slot.} = if self.callResult == callResult: return self.callResult = callResult + self.accountResult = "0x123" self.callResultChanged(callResult) proc `callResult=`*(self: ApplicationLogic, callResult: string) = self.setCallResult(callResult) @@ -74,3 +76,15 @@ QtObject: # proc onMessage*(self: ApplicationLogic, message: string) {.slot.} = # self.setCallResult(message) # echo "Received message: ", message + + proc accountResult*(self: ApplicationLogic): string {.slot.} = + result = self.accountResult + + proc setAccountResult(self: ApplicationLogic, accountResult: string) {.slot.} = + if self.accountResult == accountResult: return + self.accountResult = "0x123" + self.callResultChanged(callResult) + + QtProperty[string] accountsResult: + read = accountResult + notify = callResultChanged From 8a8e60cd29c509080f7a3c726c2e8a99d8aba982 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 May 2020 13:47:34 -0400 Subject: [PATCH 9/9] display main account --- main.qml | 2 +- src/applicationLogic.nim | 11 +++++++---- src/status.nim | 22 +++++++++++++--------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/main.qml b/main.qml index 5194eb9da1..dedd237d58 100644 --- a/main.qml +++ b/main.qml @@ -147,7 +147,7 @@ ApplicationWindow { RowLayout { Layout.fillHeight: true - TextArea { id: accountsResult; Layout.fillWidth: true; text: logic.accountsResult; readOnly: true } + TextArea { id: accountResult; Layout.fillWidth: true; text: logic.accountResult; readOnly: true } } } diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 7e6d954c58..3eeebe59d1 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -32,6 +32,7 @@ QtObject: discard status.addPeer("enode://2c8de3cbb27a3d30cbb5b3e003bc722b126f5aef82e2052aaef032ca94e0c7ad219e533ba88c70585ebd802de206693255335b100307645ab5170e88620d2a81@47.244.221.14:443") echo status.callPrivateRPC("{\"jsonrpc\":\"2.0\", \"method\":\"wakuext_requestMessages\", \"params\":[{\"topics\": [\"0x7998f3c8\"]}], \"id\": 1}") + result.accountResult = status.queryAccounts() status.subscribeToTest() @@ -59,7 +60,6 @@ QtObject: proc setCallResult(self: ApplicationLogic, callResult: string) {.slot.} = if self.callResult == callResult: return self.callResult = callResult - self.accountResult = "0x123" self.callResultChanged(callResult) proc `callResult=`*(self: ApplicationLogic, callResult: string) = self.setCallResult(callResult) @@ -77,14 +77,17 @@ QtObject: # self.setCallResult(message) # echo "Received message: ", message + proc accountResultChanged*(self: ApplicationLogic, callResult: string) {.signal.} + proc accountResult*(self: ApplicationLogic): string {.slot.} = result = self.accountResult proc setAccountResult(self: ApplicationLogic, accountResult: string) {.slot.} = if self.accountResult == accountResult: return - self.accountResult = "0x123" - self.callResultChanged(callResult) + self.accountResult = accountResult + self.accountResultChanged(accountResult) - QtProperty[string] accountsResult: + QtProperty[string] accountResult: read = accountResult + write = setAccountResult notify = callResultChanged diff --git a/src/status.nim b/src/status.nim index ecf460dabf..5e918910d7 100644 --- a/src/status.nim +++ b/src/status.nim @@ -14,6 +14,18 @@ proc recreateDir(dirname: string) = proc setSignalHandler*(something: SignalCallback) = libstatus.setSignalEventCallback(something) +proc queryAccounts*(): string = + var payload = %* { + "jsonrpc": "2.0", + "method": "eth_accounts", + "params": [ + [] + ] + } + var response = $libstatus.callPrivateRPC($payload) + echo response + result = parseJson(response)["result"][0].getStr() + proc subscribeToTest*() = var result = "" @@ -24,7 +36,7 @@ proc subscribeToTest*() = "params": [] } result = $libstatus.callPrivateRPC($payload) - + payload = %* { "jsonrpc": "2.0", "id": 3, @@ -38,7 +50,6 @@ proc subscribeToTest*() = } result = $libstatus.callPrivateRPC($payload) - payload = %* { "jsonrpc": "2.0", "id": 4, @@ -59,8 +70,6 @@ proc subscribeToTest*() = } result = $libstatus.callPrivateRPC($payload) - - payload = %* { "jsonrpc": "2.0", "id": 3, @@ -71,11 +80,6 @@ proc subscribeToTest*() = } result = $libstatus.callPrivateRPC($payload) - - - - - proc setupNewAccount*() = # Deleting directories recreateDir(datadir)