feat: use nim-status instead of libstatus

This commit is contained in:
Richard Ramos 2020-07-15 13:34:14 -04:00 committed by Iuri Matias
parent 1e39cf4821
commit 74a38c671d
10 changed files with 34 additions and 77 deletions

3
.gitmodules vendored
View File

@ -58,3 +58,6 @@
[submodule "vendor/edn.nim"]
path = vendor/edn.nim
url = https://github.com/rosado/edn.nim.git
[submodule "vendor/nim-status"]
path = vendor/nim-status
url = https://github.com/status-im/nim-status

View File

@ -8,7 +8,8 @@ import app/onboarding/core as onboarding
import app/login/core as login
import signals/core as signals
import status/libstatus/[types, libstatus]
import status/libstatus/types
import nim_status
import status/status as statuslib
var signalsQObjPointer: pointer
@ -130,7 +131,7 @@ proc mainProc() =
signal_handler(signalsQObjPointer, p0, "receiveSignal")
tearDownForeignThreadGc()
libstatus.setSignalEventCallback(callback)
nim_status.setSignalEventCallback(callback)
# Qt main event loop is entered here
# The termination of the loop will be performed when exit() or quit() is called

View File

@ -1,6 +1,6 @@
import json, os, nimcrypto, uuids, json_serialization, chronicles, strutils
import libstatus, core
import nim_status, core
import utils as utils
import types as types
import accounts/constants
@ -38,14 +38,14 @@ proc generateAddresses*(n = 5): seq[GeneratedAccount] =
"bip39Passphrase": "",
"paths": [PATH_WALLET_ROOT, PATH_EIP_1581, PATH_WHISPER, PATH_DEFAULT_WALLET]
}
let generatedAccounts = $libstatus.multiAccountGenerateAndDeriveAddresses($multiAccountConfig)
let generatedAccounts = $nim_status.multiAccountGenerateAndDeriveAddresses($multiAccountConfig)
result = Json.decode(generatedAccounts, seq[GeneratedAccount])
proc generateAlias*(publicKey: string): string =
result = $libstatus.generateAlias(publicKey.toGoString)
result = $nim_status.generateAlias(publicKey.toGoString)
proc generateIdenticon*(publicKey: string): string =
result = $libstatus.identicon(publicKey.toGoString)
result = $nim_status.identicon(publicKey.toGoString)
proc ensureDir(dirname: string) =
if not existsDir(dirname):
@ -56,10 +56,10 @@ proc initNode*() =
ensureDir(DATADIR)
ensureDir(KEYSTOREDIR)
discard $libstatus.initKeystore(KEYSTOREDIR)
discard $nim_status.initKeystore(KEYSTOREDIR)
proc openAccounts*(): seq[NodeAccount] =
let strNodeAccounts = $libstatus.openAccounts(DATADIR)
let strNodeAccounts = $nim_status.openAccounts(DATADIR)
result = Json.decode(strNodeAccounts, seq[NodeAccount])
proc saveAccountAndLogin*(
@ -88,7 +88,7 @@ proc saveAccountAndLogin*(
}
]
var savedResult = $libstatus.saveAccountAndLogin(accountData, hashedPassword, settingsJSON, configJSON, $subaccountData)
var savedResult = $nim_status.saveAccountAndLogin(accountData, hashedPassword, settingsJSON, configJSON, $subaccountData)
let parsedSavedResult = savedResult.parseJson
let error = parsedSavedResult["error"].getStr
@ -106,7 +106,7 @@ proc storeDerivedAccounts*(account: GeneratedAccount, password: string): MultiAc
"paths": [PATH_WALLET_ROOT, PATH_EIP_1581, PATH_WHISPER, PATH_DEFAULT_WALLET],
"password": hashedPassword
}
let response = $libstatus.multiAccountStoreDerivedAccounts($multiAccount);
let response = $nim_status.multiAccountStoreDerivedAccounts($multiAccount);
try:
result = Json.decode($response, MultiAccounts)
@ -165,12 +165,12 @@ proc setupAccount*(account: GeneratedAccount, password: string): types.Account =
finally:
# TODO this is needed for now for the retrieving of past messages. We'll either move or remove it later
let peer = "enode://44160e22e8b42bd32a06c1532165fa9e096eebedd7fa6d6e5f8bbef0440bc4a4591fe3651be68193a7ec029021cdb496cfe1d7f9f1dc69eb99226e6f39a7a5d4@35.225.221.245:443"
discard libstatus.addPeer(peer)
discard nim_status.addPeer(peer)
proc login*(nodeAccount: NodeAccount, password: string): NodeAccount =
let hashedPassword = hashPassword(password)
let account = nodeAccount.toAccount
let loginResult = $libstatus.login($toJson(account), hashedPassword)
let loginResult = $nim_status.login($toJson(account), hashedPassword)
let error = parseJson(loginResult)["error"].getStr
if error == "":
@ -182,7 +182,7 @@ proc login*(nodeAccount: NodeAccount, password: string): NodeAccount =
proc verifyAccountPassword*(address: string, password: string): bool =
let hashedPassword = hashPassword(password)
let verifyResult = $libstatus.verifyAccountPassword(KEYSTOREDIR, address, hashedPassword)
let verifyResult = $nim_status.verifyAccountPassword(KEYSTOREDIR, address, hashedPassword)
let error = parseJson(verifyResult)["error"].getStr
if error == "":
@ -195,17 +195,17 @@ proc multiAccountImportMnemonic*(mnemonic: string): GeneratedAccount =
"mnemonicPhrase": mnemonic,
"Bip39Passphrase": ""
}
# libstatus.multiAccountImportMnemonic never results in an error given ANY input
let importResult = $libstatus.multiAccountImportMnemonic($mnemonicJson)
# nim_status.multiAccountImportMnemonic never results in an error given ANY input
let importResult = $nim_status.multiAccountImportMnemonic($mnemonicJson)
result = Json.decode(importResult, GeneratedAccount)
proc MultiAccountImportPrivateKey*(privateKey: string): GeneratedAccount =
let privateKeyJson = %* {
"privateKey": privateKey
}
# libstatus.MultiAccountImportPrivateKey never results in an error given ANY input
# nim_status.MultiAccountImportPrivateKey never results in an error given ANY input
try:
let importResult = $libstatus.MultiAccountImportPrivateKey($privateKeyJson)
let importResult = $nim_status.multiAccountImportPrivateKey($privateKeyJson)
result = Json.decode(importResult, GeneratedAccount)
except Exception as e:
error "Error getting account from private key", msg=e.msg
@ -272,8 +272,8 @@ proc deriveAccounts*(accountId: string): MultiAccounts =
"accountID": accountId,
"paths": [PATH_WALLET_ROOT, PATH_EIP_1581, PATH_WHISPER, PATH_DEFAULT_WALLET]
}
let deriveResult = $libstatus.multiAccountDeriveAddresses($deriveJson)
let deriveResult = $nim_status.multiAccountDeriveAddresses($deriveJson)
result = Json.decode(deriveResult, MultiAccounts)
proc logout*(): StatusGoError =
result = Json.decode($libstatus.logout(), StatusGoError)
result = Json.decode($nim_status.logout(), StatusGoError)

View File

@ -1,14 +1,14 @@
import json, nimcrypto, chronicles
import libstatus, utils
import nim_status, utils
logScope:
topics = "rpc"
proc callRPC*(inputJSON: string): string =
return $libstatus.callRPC(inputJSON)
return $nim_status.callRPC(inputJSON)
proc callPrivateRPCRaw*(inputJSON: string): string =
return $libstatus.callPrivateRPC(inputJSON)
return $nim_status.callPrivateRPC(inputJSON)
proc callPrivateRPC*(methodName: string, payload = %* []): string =
try:
@ -18,7 +18,7 @@ proc callPrivateRPC*(methodName: string, payload = %* []): string =
"params": %payload
}
debug "calling json", request = $inputJSON
let response = libstatus.callPrivateRPC($inputJSON)
let response = nim_status.callPrivateRPC($inputJSON)
result = $response
if parseJSON(result).hasKey("error"):
error "rpc response error", result = result
@ -27,7 +27,7 @@ proc callPrivateRPC*(methodName: string, payload = %* []): string =
proc sendTransaction*(inputJSON: string, password: string): string =
var hashed_password = "0x" & $keccak_256.digest(password)
return $libstatus.sendTransaction(inputJSON, hashed_password)
return $nim_status.sendTransaction(inputJSON, hashed_password)
proc startMessenger*() =
discard callPrivateRPC("startMessenger".prefix)

View File

@ -1,41 +0,0 @@
import types
proc hashMessage*(p0: cstring): cstring {.importc: "HashMessage".}
proc initKeystore*(keydir: cstring): cstring {.importc: "InitKeystore".}
proc openAccounts*(datadir: cstring): cstring {.importc: "OpenAccounts".}
proc multiAccountGenerateAndDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountGenerateAndDeriveAddresses".}
proc multiAccountStoreDerivedAccounts*(paramsJSON: cstring): cstring {.importc: "MultiAccountStoreDerivedAccounts".}
proc multiAccountImportMnemonic*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportMnemonic".}
proc MultiAccountImportPrivateKey*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportPrivateKey".}
proc multiAccountDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountDeriveAddresses".}
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: SignalCallback) {.importc: "SetSignalEventCallback".}
proc sendTransaction*(jsonArgs: cstring, password: cstring): cstring {.importc: "SendTransaction".}
proc generateAlias*(p0: GoString): cstring {.importc: "GenerateAlias".}
proc identicon*(p0: GoString): cstring {.importc: "Identicon".}
proc login*(acctData: cstring, password: cstring): cstring {.importc: "Login".}
proc logout*(): cstring {.importc: "Logout".}
proc verifyAccountPassword*(keyStoreDir: cstring, address: cstring, password: cstring): cstring {.importc: "VerifyAccountPassword".}
proc validateMnemonic*(mnemonic: cstring): cstring {.importc: "ValidateMnemonic".}

View File

@ -2,8 +2,6 @@ import eventemitter, json
import eth/common/eth_types, stew/byteutils, json_serialization, stint
import accounts/constants
type SignalCallback* = proc(eventMessage: cstring): void {.cdecl.}
type SignalType* {.pure.} = enum
Message = "messages.new"
Wallet = "wallet"
@ -23,11 +21,6 @@ type SignalType* {.pure.} = enum
WhisperFilterAdded = "whisper.filter.added"
Unknown
type
GoString* = object
str*: cstring
length*: cint
type DerivedAccount* = object
publicKey*: string
address*: string

View File

@ -1,5 +1,5 @@
import json, types, random, strutils, strformat, tables
import stint
import stint, nim_status
from times import getTime, toUnix, nanosecond
import accounts/signing_phrases

View File

@ -1,5 +1,5 @@
import json, httpclient, strformat, stint, strutils, sequtils, chronicles, parseutils, tables
import libstatus, core, types, utils
import json, httpclient, json, strformat, stint, strutils, sequtils, chronicles, parseutils, tables
import nim_status, core, types, utils
import ../wallet/account
from ./accounts/constants import ZERO_ADDRESS
import ./contracts as contractMethods
@ -107,4 +107,4 @@ proc hex2Eth*(input: string): string =
result = utils.wei2Eth(value)
proc validateMnemonic*(mnemonic: string): string =
result = $libstatus.validateMnemonic(mnemonic)
result = $nim_status.validateMnemonic(mnemonic)

1
vendor/nim-status vendored Submodule

@ -0,0 +1 @@
Subproject commit fa93323ba328768fc8240719c3380edfd12f61ed

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 4720224ba20348fea25091413c606017204d4ef2
Subproject commit 0b3cdf7362bbdf9ba7fc11da803105f9417dfbac