More json conversion updates

This commit is contained in:
Eric 2024-01-24 13:36:24 +11:00
parent d46db94f74
commit 71830221b6
No known key found for this signature in database
3 changed files with 25 additions and 21 deletions

View File

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

View File

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

View File

@ -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 &= ")"