From f8128e7d61b3bc65fcdab51617433401d901ca77 Mon Sep 17 00:00:00 2001 From: smartgoo Date: Sat, 26 Oct 2024 15:42:07 -0400 Subject: [PATCH] Bug fix **kwargs requirement in RPC callback fn (#113) --- python/examples/rpc_subscriptions.py | 4 ++++ rpc/wrpc/python/src/client.rs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/examples/rpc_subscriptions.py b/python/examples/rpc_subscriptions.py index d64cd3cde..bdaedd5f8 100644 --- a/python/examples/rpc_subscriptions.py +++ b/python/examples/rpc_subscriptions.py @@ -6,9 +6,13 @@ def subscription_callback(event, name, **kwargs): print(f"{name} | {event}") +def block_added_handler(event): + print(f"block_added_handler: {event}") + async def rpc_subscriptions(client: RpcClient): # client.add_event_listener("all", subscription_callback, callback_id=1, kwarg1="Im a kwarg!!") client.add_event_listener("all", subscription_callback, name="all") + client.add_event_listener("block-added", block_added_handler) await client.subscribe_virtual_daa_score_changed() await client.subscribe_virtual_chain_changed(True) diff --git a/rpc/wrpc/python/src/client.rs b/rpc/wrpc/python/src/client.rs index b9892603a..b6eb4e2a2 100644 --- a/rpc/wrpc/python/src/client.rs +++ b/rpc/wrpc/python/src/client.rs @@ -268,7 +268,11 @@ impl RpcClient { let event = NotificationEvent::from_str(event.as_str()).unwrap(); let args = args.to_object(py).extract::>(py)?; - let kwargs = kwargs.unwrap().to_object(py).extract::>(py)?; + + let kwargs = match kwargs { + Some(kw) => kw.to_object(py).extract::>(py)?, + None => PyDict::new_bound(py).into(), + }; let py_callback = PyCallback { callback, args: Some(args), kwargs: Some(kwargs) };