Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct return type for eth_syncing #122

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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