Skip to content

Commit

Permalink
Bug fix **kwargs requirement in RPC callback fn (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartgoo authored Oct 26, 2024
1 parent bdc2198 commit f8128e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/examples/rpc_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion rpc/wrpc/python/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ impl RpcClient {
let event = NotificationEvent::from_str(event.as_str()).unwrap();

let args = args.to_object(py).extract::<Py<PyTuple>>(py)?;
let kwargs = kwargs.unwrap().to_object(py).extract::<Py<PyDict>>(py)?;

let kwargs = match kwargs {
Some(kw) => kw.to_object(py).extract::<Py<PyDict>>(py)?,
None => PyDict::new_bound(py).into(),
};

let py_callback = PyCallback { callback, args: Some(args), kwargs: Some(kwargs) };

Expand Down

0 comments on commit f8128e7

Please sign in to comment.