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 diff --git a/main.qml b/main.qml index 7b2114e338..550a5c9449 100644 --- a/main.qml +++ b/main.qml @@ -168,9 +168,14 @@ ApplicationWindow { } - Item { + ColumnLayout { + anchors.fill: parent - } + RowLayout { + Layout.fillHeight: true + TextArea { id: accountResult; Layout.fillWidth: true; text: logic.accountResult; readOnly: true } + } + } Item { diff --git a/nim_status_client.nimble b/nim_status_client.nimble index 0e1cf98831..3ac8680214 100644 --- a/nim_status_client.nimble +++ b/nim_status_client.nimble @@ -7,4 +7,4 @@ srcDir = "src" bin = "nim_status_client" [Deps] -Requires: "nim >= 1.0.0, nimqml >= 0.7.0" \ No newline at end of file +Requires: "nim >= 1.0.0, nimqml >= 0.7.0" diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 564734b4bc..3eeebe59d1 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -1,10 +1,23 @@ import NimQml import status +import libstatus +import json + + +var signalHandler: SignalCallback = proc(p0: cstring): void = + setupForeignThreadGc() + + var jsonSignal = ($p0).parseJson + if $jsonSignal["type"].getStr == "messages.new": + echo $p0 + + tearDownForeignThreadGc() QtObject: type ApplicationLogic* = ref object of QObject app: QApplication callResult: string + accountResult: string # Constructor proc newApplicationLogic*(app: QApplication): ApplicationLogic = @@ -13,10 +26,20 @@ 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}") + + result.accountResult = status.queryAccounts() + status.subscribeToTest() + + # ¯\_(ツ)_/¯ 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 +70,24 @@ 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 + + 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 = accountResult + self.accountResultChanged(accountResult) + + QtProperty[string] accountResult: + read = accountResult + write = setAccountResult + notify = callResultChanged diff --git a/src/libstatus.nim b/src/libstatus.nim index 2bfe1f245a..cd836ee047 100644 --- a/src/libstatus.nim +++ b/src/libstatus.nim @@ -11,3 +11,11 @@ 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".} + +type SignalCallback* = proc(eventMessage: cstring): void + +proc setSignalEventCallback*(callback: SignalCallback) {.importc: "SetSignalEventCallback".} 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 diff --git a/src/status.nim b/src/status.nim index 9e42123d8c..5e918910d7 100644 --- a/src/status.nim +++ b/src/status.nim @@ -11,6 +11,75 @@ proc recreateDir(dirname: string) = removeDir(dirname) createDir(dirname) +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 = "" + + var payload = %* { + "jsonrpc": "2.0", + "id": 3, + "method": "wakuext_startMessenger", + "params": [] + } + 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) + proc setupNewAccount*() = # Deleting directories recreateDir(datadir) @@ -269,3 +338,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)