2022-02-07 18:37:50 +01:00
|
|
|
import json
|
2022-02-03 15:23:51 +01:00
|
|
|
import ./core, ./response_type
|
|
|
|
|
|
|
|
export response_type
|
|
|
|
|
|
|
|
proc getAccounts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
return core.callPrivateRPC("eth_accounts")
|
|
|
|
|
|
|
|
proc getBlockByNumber*(blockNumber: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
let payload = %* [blockNumber, false]
|
|
|
|
return core.callPrivateRPC("eth_getBlockByNumber", payload)
|
|
|
|
|
2022-02-10 13:10:56 +01:00
|
|
|
proc getNativeChainBalance*(chainId: int, address: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
2022-02-03 15:23:51 +01:00
|
|
|
let payload = %* [address, "latest"]
|
2022-02-17 10:15:37 +01:00
|
|
|
return core.callPrivateRPCWithChainId("eth_getBalance", chainId, payload)
|
2022-02-03 15:23:51 +01:00
|
|
|
|
2022-05-19 10:53:57 +02:00
|
|
|
proc sendTransaction*(chainId: int, transactionData: string, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
core.sendTransaction(chainId, transactionData, password)
|
2022-02-03 15:23:51 +01:00
|
|
|
|
|
|
|
# This is the replacement of the `call` function
|
|
|
|
proc doEthCall*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
core.callPrivateRPC("eth_call", payload)
|
|
|
|
|
2022-05-19 10:53:57 +02:00
|
|
|
proc estimateGas*(chainId: int, payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
core.callPrivateRPCWithChainId("eth_estimateGas", chainId, payload)
|
2022-02-03 15:23:51 +01:00
|
|
|
|
|
|
|
proc getEthAccounts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
return core.callPrivateRPC("eth_accounts")
|
|
|
|
|
2022-03-23 09:32:25 +01:00
|
|
|
proc suggestedFees*(chainId: int): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
let payload = %* [chainId]
|
2022-05-19 10:53:57 +02:00
|
|
|
return core.callPrivateRPC("wallet_getSuggestedFees", payload)
|
|
|
|
|
|
|
|
proc suggestedRoutes*(account: string, amount: float64, token: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
let payload = %* [account, amount, token]
|
|
|
|
return core.callPrivateRPC("wallet_getSuggestedRoutes", payload)
|