refactor: methods updated due to cleaning `status-lib` dependencies

- `conversion.nim` removed since it has nothing with remote `status-go` lib
- `startMessenger` call added to general section
- `getTransfersByAddress` call updated
- `wallet` section introduced
This commit is contained in:
Sale Djenic 2022-01-10 14:11:51 +01:00 committed by saledjenic
parent 6cb419fedb
commit ad280888e0
5 changed files with 34 additions and 43 deletions

View File

@ -1,35 +0,0 @@
import
json, options, strutils
import
web3/[conversions, ethtypes], stint
import ../types/transaction
# TODO: make this public in nim-web3 lib
template stripLeadingZeros*(value: string): string =
var cidx = 0
# ignore the last character so we retain '0' on zero value
while cidx < value.len - 1 and value[cidx] == '0':
cidx.inc
value[cidx .. ^1]
proc `%`*(x: TransactionData): JsonNode =
result = newJobject()
result["from"] = %x.source
result["type"] = %x.txType
if x.to.isSome:
result["to"] = %x.to.unsafeGet
if x.gas.isSome:
result["gas"] = %x.gas.unsafeGet
if x.gasPrice.isSome:
result["gasPrice"] = %("0x" & x.gasPrice.unsafeGet.toHex.stripLeadingZeros)
if x.maxFeePerGas.isSome:
result["maxFeePerGas"] = %("0x" & x.maxFeePerGas.unsafeGet.toHex)
if x.maxPriorityFeePerGas.isSome:
result["maxPriorityFeePerGas"] = %("0x" & x.maxPriorityFeePerGas.unsafeGet.toHex)
if x.value.isSome:
result["value"] = %("0x" & x.value.unsafeGet.toHex)
result["data"] = %x.data
if x.nonce.isSome:
result["nonce"] = %x.nonce.unsafeGet

View File

@ -18,6 +18,10 @@ proc validateMnemonic*(mnemonic: string): RpcResponse[JsonNode] {.raises: [Excep
error "error doing rpc request", methodName = "validateMnemonic", exception=e.msg
raise newException(RpcException, e.msg)
proc startMessenger*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = core.callPrivateRPC("startMessenger".prefix, payload)
proc generateSymKeyFromPassword*(password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [password]
result = core.callPrivateRPC("waku_generateSymKeyFromPassword", payload)

View File

@ -0,0 +1,13 @@
import json, strutils, chronicles
import core, utils
import response_type
import status_go
export response_type
logScope:
topics = "rpc-keystore"
proc initKeycard*(keystoreDir: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result.result = newJString($status_go.initKeystore(keystoreDir))

View File

@ -1,7 +1,5 @@
import json, stint, chronicles, strutils, conversions
import json, stint, chronicles, strutils
import ../types/transaction
import ./core as core
type PendingTransactionType* {.pure.} = enum
@ -15,12 +13,11 @@ proc checkRecentHistory*(addresses: seq[string]) {.raises: [Exception].} =
let payload = %* [addresses]
discard callPrivateRPC("wallet_checkRecentHistory", payload)
proc getTransfersByAddress*(address: string, toBlock: Uint256, limit: int, loadMore: bool = false): RpcResponse[JsonNode] {.raises: [Exception].} =
let
toBlockParsed = if not loadMore: newJNull() else: %("0x" & stint.toHex(toBlock))
limitParsed = "0x" & limit.toHex.stripLeadingZeros
proc getTransfersByAddress*(address: string, toBlock: Uint256, limitAsHexWithoutLeadingZeros: string,
loadMore: bool = false): RpcResponse[JsonNode] {.raises: [Exception].} =
let toBlockParsed = if not loadMore: newJNull() else: %("0x" & stint.toHex(toBlock))
callPrivateRPC("wallet_getTransfersByAddress", %* [address, toBlockParsed, limitParsed, loadMore])
callPrivateRPC("wallet_getTransfersByAddress", %* [address, toBlockParsed, limitAsHexWithoutLeadingZeros, loadMore])
proc trackPendingTransaction*(hash: string, fromAddress: string, toAddress: string, trxType: PendingTransactionType, data: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [{"hash": hash, "from": fromAddress, "to": toAddress, "type": $trxType, "additionalData": data, "data": "", "value": 0, "timestamp": 0, "gasPrice": 0, "gasLimit": 0}]

View File

@ -0,0 +1,12 @@
import json, chronicles
import core, utils
import response_type
export response_type
logScope:
topics = "rpc-wallet"
proc getPendingTransactions*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = core.callPrivateRPC("wallet_getPendingTransactions", payload)