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:
Anthony Laibe 2021-10-20 15:25:52 +02:00 committed by GitHub
parent 47553f4fc8
commit 0759388710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 3 deletions

View File

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

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

View 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])

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

View 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")

View File

@ -0,0 +1,7 @@
import json
import ./core
proc checkRecentHistory*(addresses: seq[string]) {.raises: [Exception].} =
let payload = %* [addresses]
discard callPrivateRPC("wallet_checkRecentHistory", payload)