diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 1784da0..554e88c 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -1,7 +1,6 @@ -import std/json import std/tables import std/uri -import pkg/chronicles +import pkg/chronicles except `%` import pkg/eth/common/eth_types_json_serialization import pkg/json_rpc/rpcclient import pkg/json_rpc/errors @@ -11,6 +10,7 @@ import ../signer import ./jsonrpc/rpccalls import ./jsonrpc/conversions import ./jsonrpc/subscriptions +import ./jsonrpc/json export json export basics @@ -34,12 +34,14 @@ type subscriptions: JsonRpcSubscriptions id: JsonNode -proc raiseJsonRpcProviderError(message: string) {.raises: [JsonRpcProviderError].} = +proc raiseJsonRpcProviderError( + message: string) {.raises: [JsonRpcProviderError].} = + var message = message - try: - message = parseJson(message){"message"}.getStr - except Exception: - discard + if json =? JsonNode.fromJson(message): + if "message" in json: + message = json{"message"}.getStr + echo "JsonRpcProviderError: ", message raise newException(JsonRpcProviderError, message) template convertError(body) = diff --git a/ethers/providers/jsonrpc/subscriptions.nim b/ethers/providers/jsonrpc/subscriptions.nim index fe15748..45ddcec 100644 --- a/ethers/providers/jsonrpc/subscriptions.nim +++ b/ethers/providers/jsonrpc/subscriptions.nim @@ -1,3 +1,4 @@ +import std/hashes import std/tables import std/sequtils import pkg/chronos @@ -200,7 +201,7 @@ method subscribeBlocks(subscriptions: PollingSubscriptions, discard proc callback(id, change: JsonNode) = - if hash =? BlockHash.fromJson(change).catch: + if hash =? BlockHash.fromJson(change): asyncSpawn getBlock(hash) let id = await subscriptions.client.eth_newBlockFilter() @@ -214,7 +215,7 @@ method subscribeLogs(subscriptions: PollingSubscriptions, {.async.} = proc callback(id, change: JsonNode) = - if log =? Log.fromJson(change).catch: + if log =? Log.fromJson(change): onLog(log) let id = await subscriptions.client.eth_newFilter(filter) diff --git a/ethers/transaction.nim b/ethers/transaction.nim index 0ee9d2a..19ac8dc 100644 --- a/ethers/transaction.nim +++ b/ethers/transaction.nim @@ -1,5 +1,6 @@ import pkg/stew/byteutils import ./basics +import ./providers/jsonrpc/json type TransactionType* = enum @@ -7,17 +8,17 @@ type AccessList = 1, Dynamic = 2 Transaction* = object - sender*: ?Address - to*: Address - data*: seq[byte] - value*: UInt256 - nonce*: ?UInt256 - chainId*: ?UInt256 - gasPrice*: ?UInt256 - maxFee*: ?UInt256 - maxPriorityFee*: ?UInt256 - gasLimit*: ?UInt256 - transactionType*: ?TransactionType + sender* {.serialize.}: ?Address + to* {.serialize.}: Address + data* {.serialize.}: seq[byte] + value* {.serialize.}: UInt256 + nonce* {.serialize.}: ?UInt256 + chainId* {.serialize.}: ?UInt256 + gasPrice* {.serialize.}: ?UInt256 + maxFee* {.serialize.}: ?UInt256 + maxPriorityFee* {.serialize.}: ?UInt256 + gasLimit* {.serialize.}: ?UInt256 + `type`* {.serialize.}: ?TransactionType func `$`*(transaction: Transaction): string = result = "(" @@ -34,6 +35,6 @@ func `$`*(transaction: Transaction): string = result &= ", gasPrice: " & $gasPrice if gasLimit =? transaction.gasLimit: result &= ", gasLimit: " & $gasLimit - if txType =? transaction.transactionType: + if txType =? transaction.`type`: result &= ", type: " & $txType result &= ")"