From 5718498c21c8deb40a78892e9e07f89ee94164d9 Mon Sep 17 00:00:00 2001 From: smartgoo Date: Sat, 26 Oct 2024 14:57:06 -0400 Subject: [PATCH] remove **kwargs requirement in supplied rpc callback function --- 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) };