2021-09-08 18:05:39 +00:00
|
|
|
import
|
2021-09-11 12:20:32 +00:00
|
|
|
json, json_serialization, chronicles, web3/ethtypes
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
import
|
2021-09-11 21:50:36 +00:00
|
|
|
../statusgo_backend/core, ../types/[rpc_response, transaction], ../statusgo_backend/conversions
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-10 17:27:49 +00:00
|
|
|
proc estimateGas*(tx: TransactionData): RpcResponse =
|
2021-09-08 18:05:39 +00:00
|
|
|
let response = core.callPrivateRPC("eth_estimateGas", %*[%tx])
|
|
|
|
result = Json.decode(response, RpcResponse)
|
|
|
|
if not result.error.isNil:
|
|
|
|
raise newException(RpcException, "Error getting gas estimate: " & result.error.message)
|
|
|
|
|
|
|
|
trace "Gas estimated succesfully", estimate=result.result
|
|
|
|
|
2021-09-10 17:27:49 +00:00
|
|
|
proc sendTransaction*(tx: TransactionData, password: string): RpcResponse =
|
2021-09-08 18:05:39 +00:00
|
|
|
let responseStr = core.sendTransaction($(%tx), password)
|
|
|
|
result = Json.decode(responseStr, RpcResponse)
|
|
|
|
if not result.error.isNil:
|
|
|
|
raise newException(RpcException, "Error sending transaction: " & result.error.message)
|
|
|
|
|
|
|
|
trace "Transaction sent succesfully", hash=result.result
|
|
|
|
|
2021-09-10 17:27:49 +00:00
|
|
|
proc call*(tx: TransactionData): RpcResponse =
|
2021-09-08 18:05:39 +00:00
|
|
|
let responseStr = core.callPrivateRPC("eth_call", %*[%tx, "latest"])
|
|
|
|
result = Json.decode(responseStr, RpcResponse)
|
|
|
|
if not result.error.isNil:
|
2021-09-11 12:20:32 +00:00
|
|
|
raise newException(RpcException, "Error calling method: " & result.error.message)
|
|
|
|
|
|
|
|
proc eth_call*(payload = %* []): RpcResponse =
|
|
|
|
let responseStr = core.callPrivateRPC("eth_call", payload)
|
|
|
|
result = Json.decode(responseStr, RpcResponse)
|
|
|
|
if not result.error.isNil:
|
|
|
|
raise newException(RpcException, "Error calling method: " & result.error.message)
|