diff --git a/status/statusgo_backend_new/accounts.nim b/status/statusgo_backend_new/accounts.nim new file mode 100644 index 0000000..1348929 --- /dev/null +++ b/status/statusgo_backend_new/accounts.nim @@ -0,0 +1,120 @@ +import json, json_serialization, chronicles +import core, utils +import response_type + +import status_go + +export response_type + +logScope: + topics = "rpc-accounts" + +const NUMBER_OF_ADDRESSES_TO_GENERATE = 5 +const MNEMONIC_PHRASE_LENGTH = 12 + +proc generateAddresses*(paths: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} = + let payload = %* { + "n": NUMBER_OF_ADDRESSES_TO_GENERATE, + "mnemonicPhraseLength": MNEMONIC_PHRASE_LENGTH, + "bip39Passphrase": "", + "paths": paths + } + + try: + let response = status_go.multiAccountGenerateAndDeriveAddresses($payload) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "generateAddresses", exception=e.msg + raise newException(RpcException, e.msg) + +proc generateAlias*(publicKey: string): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.generateAlias(publicKey) + result.result = %* response + + except RpcException as e: + error "error doing rpc request", methodName = "generateAlias", exception=e.msg + raise newException(RpcException, e.msg) + +proc generateIdenticon*(publicKey: string): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.identicon(publicKey) + result.result = %* response + + except RpcException as e: + error "error doing rpc request", methodName = "generateIdenticon", exception=e.msg + raise newException(RpcException, e.msg) + +proc multiAccountImportMnemonic*(mnemonic: string): RpcResponse[JsonNode] {.raises: [Exception].} = + let payload = %* { + "mnemonicPhrase": mnemonic, + "Bip39Passphrase": "" + } + + try: + let response = status_go.multiAccountImportMnemonic($payload) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "multiAccountImportMnemonic", exception=e.msg + raise newException(RpcException, e.msg) + +proc deriveAccounts*(accountId: string, paths: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} = + let payload = %* { + "accountID": accountId, + "paths": paths + } + + try: + let response = status_go.multiAccountDeriveAddresses($payload) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "deriveAccounts", exception=e.msg + raise newException(RpcException, e.msg) + +proc openedAccounts*(path: string): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.openAccounts(path) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "openedAccounts", exception=e.msg + raise newException(RpcException, e.msg) + +proc storeDerivedAccounts*(id, hashedPassword: string, paths: seq[string]): + RpcResponse[JsonNode] {.raises: [Exception].} = + let payload = %* { + "accountID": id, + "paths": paths, + "password": hashedPassword + } + + try: + let response = status_go.multiAccountStoreDerivedAccounts($payload) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "storeDerivedAccounts", exception=e.msg + raise newException(RpcException, e.msg) + +proc addPeer*(peer: string): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.addPeer(peer) + result.result = %* response + + except RpcException as e: + error "error doing rpc request", methodName = "addPeer", exception=e.msg + raise newException(RpcException, e.msg) + +proc saveAccountAndLogin*(hashedPassword: string, account, subaccounts, settings, + config: JsonNode): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.saveAccountAndLogin($account, hashedPassword, + $settings, $config, $subaccounts) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "saveAccountAndLogin", exception=e.msg + raise newException(RpcException, e.msg) \ No newline at end of file diff --git a/status/statusgo_backend_new/contacts.nim b/status/statusgo_backend_new/contacts.nim index a1baa5c..1dd2f9c 100644 --- a/status/statusgo_backend_new/contacts.nim +++ b/status/statusgo_backend_new/contacts.nim @@ -9,7 +9,7 @@ proc getContacts*(): RpcResponse[JsonNode] {.raises: [Exception].} = result = callPrivateRPC("contacts".prefix, payload) proc getContactById*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} = - let payload = %* [] + let payload = %* [id] result = callPrivateRPC("getContactByID".prefix, payload) proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string, diff --git a/status/statusgo_backend_new/general.nim b/status/statusgo_backend_new/general.nim new file mode 100644 index 0000000..45f1f80 --- /dev/null +++ b/status/statusgo_backend_new/general.nim @@ -0,0 +1,19 @@ +import json, strutils, json_serialization, chronicles +import core +import response_type + +import status_go + +export response_type + +logScope: + topics = "rpc-general" + +proc validateMnemonic*(mnemonic: string): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + let response = status_go.validateMnemonic(mnemonic.strip()) + result.result = Json.decode(response, JsonNode) + + except RpcException as e: + error "error doing rpc request", methodName = "validateMnemonic", exception=e.msg + raise newException(RpcException, e.msg) \ No newline at end of file diff --git a/status/statusgo_backend_new/utils.nim b/status/statusgo_backend_new/utils.nim index bae0160..6fff86a 100644 --- a/status/statusgo_backend_new/utils.nim +++ b/status/statusgo_backend_new/utils.nim @@ -4,4 +4,4 @@ proc isWakuEnabled(): bool = proc prefix*(methodName: string, isExt:bool = true): string = result = if isWakuEnabled(): "waku" else: "shh" result = result & (if isExt: "ext_" else: "_") - result = result & methodName + result = result & methodName \ No newline at end of file