initial accounts class added

This commit is contained in:
Sale Djenic 2021-10-13 13:09:51 +02:00
parent c8b721994b
commit 77905a3182
4 changed files with 141 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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