Merge branch 'master' into feat/style-kindof

This commit is contained in:
Jonathan Rainville 2020-05-08 14:08:29 -04:00 committed by GitHub
commit b02d15a9bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 145 additions and 5 deletions

View File

@ -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

View File

@ -168,8 +168,13 @@ ApplicationWindow {
}
Item {
ColumnLayout {
anchors.fill: parent
RowLayout {
Layout.fillHeight: true
TextArea { id: accountResult; Layout.fillWidth: true; text: logic.accountResult; readOnly: true }
}
}
Item {

View File

@ -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

View File

@ -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".}

View File

@ -1 +1,2 @@
--threads:on
--tlsEmulation:off

View File

@ -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)