From 16a3d25419ed849cf6791e6537ad5b3736148376 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 21 Jul 2022 11:36:54 +0200 Subject: [PATCH] Remove duplication --- ethers/providers/jsonrpc.nim | 19 ++++++------------- ethers/providers/jsonrpc/signatures.nim | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 0d2c8d6..bbfc00e 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -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: diff --git a/ethers/providers/jsonrpc/signatures.nim b/ethers/providers/jsonrpc/signatures.nim index bcc016d..e0f9211 100644 --- a/ethers/providers/jsonrpc/signatures.nim +++ b/ethers/providers/jsonrpc/signatures.nim @@ -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