Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix where **kwargs was required in RPC callback function #113

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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