mirror of
https://github.com/status-im/status-lib.git
synced 2025-02-20 16:18:22 +00:00
Refactor/wallet 1 (#89)
* refactor: add custom token new backend * refactor: add transactions new backend * refactor: add collectible new backend * refactor: add accounts backend * refactor: add settings backend * refactor: Add eth call to fetch balance * refactor: add call to get eth block
This commit is contained in:
parent
47553f4fc8
commit
0759388710
@ -1,6 +1,6 @@
|
||||
import json, json_serialization, chronicles
|
||||
import core, utils
|
||||
import response_type
|
||||
import ./core, ./utils
|
||||
import ./response_type
|
||||
|
||||
import status_go
|
||||
|
||||
@ -12,6 +12,9 @@ logScope:
|
||||
const NUMBER_OF_ADDRESSES_TO_GENERATE = 5
|
||||
const MNEMONIC_PHRASE_LENGTH = 12
|
||||
|
||||
proc getAccounts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
return core.callPrivateRPC("accounts_getAccounts")
|
||||
|
||||
proc generateAddresses*(paths: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* {
|
||||
"n": NUMBER_OF_ADDRESSES_TO_GENERATE,
|
||||
@ -138,4 +141,4 @@ proc login*(name, keyUid, hashedPassword, identicon, thumbnail, large: string):
|
||||
|
||||
except RpcException as e:
|
||||
error "error doing rpc request", methodName = "login", exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
||||
raise newException(RpcException, e.msg)
|
||||
|
14
status/statusgo_backend_new/collectibles.nim
Normal file
14
status/statusgo_backend_new/collectibles.nim
Normal file
@ -0,0 +1,14 @@
|
||||
import json
|
||||
import ./core, ./response_type
|
||||
|
||||
export response_type
|
||||
|
||||
proc getOpenseaCollections*(chainId: int, address: string): RpcResponse[JsonNode] =
|
||||
let payload = %* [chainId, address]
|
||||
return callPrivateRPC("wallet_getOpenseaCollectionsByOwner", payload)
|
||||
|
||||
proc getOpenseaAssets*(
|
||||
chainId: int, address: string, collectionSlug: string, limit: int
|
||||
): RpcResponse[JsonNode] =
|
||||
let payload = %* [chainId, address, collectionSlug, limit]
|
||||
return callPrivateRPC("wallet_getOpenseaAssetsByOwnerAndCollection", payload)
|
15
status/statusgo_backend_new/custom_tokens.nim
Normal file
15
status/statusgo_backend_new/custom_tokens.nim
Normal file
@ -0,0 +1,15 @@
|
||||
import json
|
||||
import ./core, ./response_type
|
||||
|
||||
export response_type
|
||||
|
||||
proc getCustomTokens*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
return callPrivateRPC("wallet_getCustomTokens", %* [])
|
||||
|
||||
proc addCustomToken*(address: string, name: string, symbol: string, decimals: int, color: string) {.raises: [Exception].} =
|
||||
discard callPrivateRPC("wallet_addCustomToken", %* [
|
||||
{"address": address, "name": name, "symbol": symbol, "decimals": decimals, "color": color}
|
||||
])
|
||||
|
||||
proc removeCustomToken*(address: string) {.raises: [Exception].} =
|
||||
discard callPrivateRPC("wallet_deleteCustomToken", %* [address])
|
20
status/statusgo_backend_new/eth.nim
Normal file
20
status/statusgo_backend_new/eth.nim
Normal file
@ -0,0 +1,20 @@
|
||||
import json, strutils, strformat
|
||||
import ./core, ./response_type
|
||||
|
||||
export response_type
|
||||
|
||||
proc getBlockByNumber*(blockNumber: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [blockNumber, false]
|
||||
return core.callPrivateRPC("eth_getBlockByNumber", payload)
|
||||
|
||||
proc getEthBalance*(address: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [address, "latest"]
|
||||
return core.callPrivateRPC("eth_getBalance", payload)
|
||||
|
||||
proc getTokenBalance*(tokenAddress: string, accountAddress: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
var postfixedAccount: string = accountAddress
|
||||
postfixedAccount.removePrefix("0x")
|
||||
let payload = %* [{
|
||||
"to": tokenAddress, "from": accountAddress, "data": fmt"0x70a08231000000000000000000000000{postfixedAccount}"
|
||||
}, "latest"]
|
||||
return core.callPrivateRPC("eth_call", payload)
|
7
status/statusgo_backend_new/settings.nim
Normal file
7
status/statusgo_backend_new/settings.nim
Normal file
@ -0,0 +1,7 @@
|
||||
import json
|
||||
import ./core, ./response_type
|
||||
|
||||
export response_type
|
||||
|
||||
proc getSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
return core.callPrivateRPC("settings_getSettings")
|
7
status/statusgo_backend_new/transactions.nim
Normal file
7
status/statusgo_backend_new/transactions.nim
Normal file
@ -0,0 +1,7 @@
|
||||
import json
|
||||
|
||||
import ./core
|
||||
|
||||
proc checkRecentHistory*(addresses: seq[string]) {.raises: [Exception].} =
|
||||
let payload = %* [addresses]
|
||||
discard callPrivateRPC("wallet_checkRecentHistory", payload)
|
Loading…
x
Reference in New Issue
Block a user