Remove duplication

This commit is contained in:
Mark Spanbroek 2022-07-21 11:36:54 +02:00 committed by markspanbroek
parent 52f57894f5
commit 16a3d25419
2 changed files with 7 additions and 14 deletions

View File

@ -159,19 +159,12 @@ proc subscribe(provider: JsonRpcProvider,
let client = await provider.client
doAssert client of RpcWebSocketClient, "subscriptions require websockets"
let id = await client.eth_subscribe(name, filter)
provider.subscriptions[id] = handler
var id: JsonNode
if filter =? filter:
id = await client.eth_subscribe(name, filter)
else:
id = await client.eth_subscribe(name)
return JsonRpcSubscription(id: id, provider: provider)
proc subscribe(provider: JsonRpcProvider,
name: string,
handler: SubscriptionHandler): Future[Subscription] {.async.} =
convertError:
let client = await provider.client
doAssert client of RpcWebSocketClient, "subscriptions require websockets"
let id = await client.eth_subscribe(name)
provider.subscriptions[id] = handler
return JsonRpcSubscription(id: id, provider: provider)
@ -191,7 +184,7 @@ method subscribe*(provider: JsonRpcProvider,
proc handler(id, arguments: JsonNode) {.async.} =
if blck =? Block.fromJson(arguments["result"]).catch:
await callback(blck)
return await provider.subscribe("newHeads", handler)
return await provider.subscribe("newHeads", Filter.none, handler)
method unsubscribe*(subscription: JsonRpcSubscription) {.async.} =
convertError:

View File

@ -10,6 +10,6 @@ proc eth_chainId(): UInt256
proc eth_sendTransaction(transaction: Transaction): TransactionHash
proc eth_getTransactionReceipt(hash: TransactionHash): ?TransactionReceipt
proc eth_sign(account: Address, message: seq[byte]): seq[byte]
proc eth_subscribe(name: string, filter: ?Filter): JsonNode
proc eth_subscribe(name: string, filter: Filter): JsonNode
proc eth_subscribe(name: string): JsonNode
proc eth_unsubscribe(id: JsonNode): bool