mirror of
https://github.com/status-im/status-lib.git
synced 2025-01-09 12:05:50 +00:00
initial accounts class added
This commit is contained in:
parent
c8b721994b
commit
77905a3182
120
status/statusgo_backend_new/accounts.nim
Normal file
120
status/statusgo_backend_new/accounts.nim
Normal 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)
|
@ -9,7 +9,7 @@ proc getContacts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|||||||
result = callPrivateRPC("contacts".prefix, payload)
|
result = callPrivateRPC("contacts".prefix, payload)
|
||||||
|
|
||||||
proc getContactById*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc getContactById*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
let payload = %* []
|
let payload = %* [id]
|
||||||
result = callPrivateRPC("getContactByID".prefix, payload)
|
result = callPrivateRPC("getContactByID".prefix, payload)
|
||||||
|
|
||||||
proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string,
|
proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string,
|
||||||
|
19
status/statusgo_backend_new/general.nim
Normal file
19
status/statusgo_backend_new/general.nim
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user