Formatting

This commit is contained in:
Mark Spanbroek 2023-06-27 14:07:36 +02:00 committed by markspanbroek
parent 16fa0cfcf8
commit 127c9c9b0d
1 changed files with 15 additions and 13 deletions

View File

@ -34,7 +34,9 @@ method unsubscribe(subscriptions: JsonRpcSubscriptions,
raiseAssert "not implemented" raiseAssert "not implemented"
method unsubscribe(subscription: JsonRpcSubscription) {.async.} = method unsubscribe(subscription: JsonRpcSubscription) {.async.} =
await subscription.subscriptions.unsubscribe(subscription.id) let subscriptions = subscription.subscriptions
let id = subscription.id
await subscriptions.unsubscribe(id)
proc getCallback(subscriptions: JsonRpcSubscriptions, proc getCallback(subscriptions: JsonRpcSubscriptions,
id: JsonNode): ?SubscriptionCallback = id: JsonNode): ?SubscriptionCallback =
@ -51,10 +53,20 @@ proc getCallback(subscriptions: JsonRpcSubscriptions,
type type
WebSocketSubscriptions = ref object of JsonRpcSubscriptions WebSocketSubscriptions = ref object of JsonRpcSubscriptions
proc new*(_: type JsonRpcSubscriptions,
client: RpcWebSocketClient): JsonRpcSubscriptions =
let subscriptions = WebSocketSubscriptions(client: client)
proc subscriptionHandler(arguments: JsonNode) {.upraises:[].} =
if id =? arguments["subscription"].catch and
callback =? subscriptions.getCallback(id):
callback(id, arguments)
client.setMethodHandler("eth_subscription", subscriptionHandler)
subscriptions
method subscribeBlocks(subscriptions: WebSocketSubscriptions, method subscribeBlocks(subscriptions: WebSocketSubscriptions,
onBlock: BlockHandler): onBlock: BlockHandler):
Future[JsonRpcSubscription] Future[JsonRpcSubscription]
{.async.} = {.async.} =
proc callback(id, arguments: JsonNode) = proc callback(id, arguments: JsonNode) =
if blck =? Block.fromJson(arguments["result"]).catch: if blck =? Block.fromJson(arguments["result"]).catch:
asyncSpawn onBlock(blck) asyncSpawn onBlock(blck)
@ -80,16 +92,6 @@ method unsubscribe(subscriptions: WebSocketSubscriptions,
subscriptions.callbacks.del(id) subscriptions.callbacks.del(id)
discard await subscriptions.client.eth_unsubscribe(id) discard await subscriptions.client.eth_unsubscribe(id)
proc new*(_: type JsonRpcSubscriptions,
client: RpcWebSocketClient): JsonRpcSubscriptions =
let subscriptions = WebSocketSubscriptions(client: client)
proc subscriptionHandler(arguments: JsonNode) {.upraises:[].} =
if id =? arguments["subscription"].catch and
callback =? subscriptions.getCallback(id):
callback(id, arguments)
client.setMethodHandler("eth_subscription", subscriptionHandler)
subscriptions
# Polling # Polling
type type