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

Python wRPC client subscription prototype #62

Merged
merged 14 commits into from
Jul 12, 2024
Prev Previous commit
Next Next commit
Python wRPC subscribtions prototype
smartgoo committed Jul 6, 2024
commit b50150dc7e48eb4ebedbc6cd521ee7ede76c8fa8
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions python/examples/rpc.py
Original file line number Diff line number Diff line change
@@ -5,11 +5,21 @@
from kaspa import RpcClient


async def main():
client = RpcClient(url = "ws://localhost:17110")
await client.connect()
print(f'Client is connected: {client.is_connected()}')
def subscription_callback(event):
print(event)

async def rpc_subscriptions(client):
client.add_event_listener('all', subscription_callback)

await client.subscribe_daa_score()
await client.subscribe_virtual_chain_changed(True)

await asyncio.sleep(10)

await client.unsubscribe_daa_score()
await client.unsubscribe_virtual_chain_changed(True)

async def rpc_calls(client):
get_server_info_response = await client.get_server_info()
print(get_server_info_response)

@@ -25,6 +35,14 @@ async def main():
get_balances_by_addresses_response = await client.get_balances_by_addresses_call(get_balances_by_addresses_request)
print(get_balances_by_addresses_response)

async def main():
client = RpcClient(url = "ws://localhost:17110")
await client.connect()
print(f'Client is connected: {client.is_connected()}')

await rpc_calls(client)
await rpc_subscriptions(client)


if __name__ == "__main__":
asyncio.run(main())
3 changes: 3 additions & 0 deletions rpc/wrpc/python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -17,7 +17,9 @@ py-sdk = [
]

[dependencies]
ahash.workspace = true
cfg-if.workspace = true
futures.workspace = true
kaspa-consensus-core.workspace = true
kaspa-notify.workspace = true
kaspa-rpc-core.workspace = true
@@ -30,4 +32,5 @@ serde_json.workspace = true
serde-pyobject = "0.3.0"
thiserror.workspace = true
workflow-core.workspace = true
workflow-log.workspace = true
workflow-rpc.workspace = true
Loading