Skip to content

Commit

Permalink
Use correct return type for eth_syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jan 13, 2024
1 parent bf1ce86 commit dffeb12
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/helpers/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type
Hash256 = w3.Hash256

proc installHandlers*(server: RpcServer) =
server.rpc("eth_syncing") do(x: JsonString, ) -> bool:
return false
server.rpc("eth_syncing") do(x: JsonString, ) -> SyncingStatus:
return SyncingStatus(syncing: false)

server.rpc("eth_sendRawTransaction") do(x: JsonString, data: seq[byte]) -> TxHash:
let tx = rlp.decode(data, Transaction)
Expand Down
21 changes: 20 additions & 1 deletion web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ proc readValue*(r: var JsonReader[JrpcConv], val: var RtBlockIdentifier)
val = RtBlockIdentifier(kind: bidNumber, number: fromHex[uint64](hexStr))
else:
val = RtBlockIdentifier(kind: bidAlias, alias: hexStr)

proc writeValue*(w: var JsonWriter[JrpcConv], v: RtBlockIdentifier)
{.gcsafe, raises: [IOError].} =
case v.kind
Expand Down Expand Up @@ -333,6 +333,25 @@ proc writeValue*(w: var JsonWriter[JrpcConv], v: SingleOrList)
of slkSingle: w.writeValue(v.single)
of slkList: w.writeValue(v.list)

proc readValue*(r: var JsonReader[JrpcConv], val: var SyncingStatus)
{.gcsafe, raises: [IOError, SerializationError].} =
let tok = r.tokKind()
case tok
of JsonValueKind.Bool:
val = SyncingStatus(syncing: r.parseBool())
of JsonValueKind.Object:
val = SyncingStatus(syncing: true)
r.readValue(val.syncObject)
else:
r.raiseUnexpectedValue("SyncingStatus unexpected token kind =" & $tok)

proc writeValue*(w: var JsonWriter[JrpcConv], v: SyncingStatus)
{.gcsafe, raises: [IOError].} =
if not v.syncing:
w.writeValue(false)
else:
w.writeValue(v.syncObject)

func `$`*(v: Quantity): string {.inline.} =
encodeQuantity(v.uint64)

Expand Down
2 changes: 1 addition & 1 deletion web3/eth_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ createRpcSigsFromNim(RpcClient):
proc net_peerCount(): Quantity
proc net_listening(): bool
proc eth_protocolVersion(): string
proc eth_syncing(): SyncObject
proc eth_syncing(): SyncingStatus
proc eth_coinbase(): Address
proc eth_mining(): bool
proc eth_hashrate(): Quantity
Expand Down
4 changes: 4 additions & 0 deletions web3/eth_api_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type
currentBlock*: Quantity
highestBlock*: Quantity

SyncingStatus* = object
syncing*: bool
syncObject*: SyncObject

HistoricExtraData* = DynamicBytes[0, 4096]
## In the current specs, the maximum is 32, but historically this value was
## used as Clique metadata which is dynamic in lenght and exceeds 32 bytes.
Expand Down

0 comments on commit dffeb12

Please sign in to comment.