Skip to content

Commit

Permalink
fixed a problem with geth when sending newHeads with an empty {} argu…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
onqtam committed Sep 24, 2020
1 parent bf6805d commit dde382f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions web3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ proc subscribe*(w: Web3, name: string, options: JsonNode,
## In case of any errors or illegal behavior of the remote RPC node,
## the `errorHandler` will be executed with relevant information about
## the error.
let id = await w.provider.eth_subscribe(name, if options.isNil: newJNull()
else: options)

# Don't send an empty `{}` object as an extra argument if there are no options
let id = if options.isNil:
await w.provider.eth_subscribe(name)
else:
await w.provider.eth_subscribe(name, options)

result = Subscription(id: id,
web3: w,
eventHandler: eventHandler,
Expand All @@ -142,7 +147,7 @@ proc subscribeForLogs*(w: Web3, options: JsonNode,
else:
result.historicalEventsProcessed = true

proc subscribeForBlockHeaders*(w: Web3, options: JsonNode,
proc subscribeForBlockHeaders*(w: Web3,
blockHeadersCallback: proc(b: BlockHeader) {.gcsafe, raises: [Defect].},
errorHandler: SubscriptionErrorHandler): Future[Subscription]
{.async.} =
Expand All @@ -152,7 +157,9 @@ proc subscribeForBlockHeaders*(w: Web3, options: JsonNode,
except CatchableError as err: errorHandler(err[])
blockHeadersCallback(blk)

result = await subscribe(w, "newHeads", options, eventHandler, errorHandler)
# `nil` options so that we skip sending an empty `{}` object as an extra argument
# to geth for `newHeads`: https://github.com/ethereum/go-ethereum/issues/21588
result = await subscribe(w, "newHeads", nil, eventHandler, errorHandler)
result.historicalEventsProcessed = true

proc unsubscribe*(s: Subscription): Future[void] {.async.} =
Expand Down
1 change: 1 addition & 0 deletions web3/ethcallsigs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ proc eth_getWork(): seq[UInt256]
proc eth_submitWork(nonce: int64, powHash: Uint256, mixDigest: Uint256): bool
proc eth_submitHashrate(hashRate: UInt256, id: Uint256): bool
proc eth_subscribe(name: string, options: JsonNode): string
proc eth_subscribe(name: string): string
proc eth_unsubscribe(id: string)

proc shh_post(): string
Expand Down

0 comments on commit dde382f

Please sign in to comment.