Skip to content

Websockets docs #1575

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

Merged
merged 302 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
302 commits
Select commit Hold shift + click to select a range
faa97ec
Add `ws_client` and `full_node_ws_client` fixtures
franciszekjob Nov 8, 2024
7b4dd76
Move `devnet_ws` to separate file
franciszekjob Nov 8, 2024
9ebc171
Refactor `FullNodeWSClient._handle_received_message()`; Fix typechecks
franciszekjob Nov 8, 2024
ddcfc06
Fix formatting and linting
franciszekjob Nov 8, 2024
a5854da
Resolve conflicts with `development`
franciszekjob Jan 24, 2025
98165e5
Fix linting
franciszekjob Jan 24, 2025
6590944
Update `resource_bounds` params description
franciszekjob Jan 24, 2025
605b2b3
Apply other code review suggestions
franciszekjob Jan 24, 2025
14dcb5b
Fix description in migration guide
franciszekjob Jan 24, 2025
ba403dd
Fix example snippets in readme
franciszekjob Jan 24, 2025
6a3301b
Add mocked values in tests
franciszekjob Jan 24, 2025
34896b3
Add setup devnet workflow
franciszekjob Jan 24, 2025
8050a22
Change `devnet.yml` to be composite action
franciszekjob Jan 24, 2025
d8a901d
Rename `l1_transaction_hash` to `transaction_hash` in `starknet_getMe…
franciszekjob Jan 27, 2025
c12908b
Move `devnet.yml` to `composite-actions` dir
franciszekjob Jan 27, 2025
7233e65
Format
franciszekjob Jan 27, 2025
6945fbc
Rename devnet composite action
franciszekjob Jan 27, 2025
a62ebdc
Update devnet action path
franciszekjob Jan 27, 2025
819321e
Add missing `shell` property
franciszekjob Jan 27, 2025
e4b947c
Refactor devnet installation action; Add temporary workflow which wil…
franciszekjob Jan 27, 2025
667d5b3
Add inputs to steps using devnet action
franciszekjob Jan 27, 2025
dc09de0
Add missing checkout step
franciszekjob Jan 27, 2025
871499b
Add missing `devnet_sha` input to devnet setup workflow
franciszekjob Jan 27, 2025
22192f8
Fix devnet installation action - use `devnet_sha` input
franciszekjob Jan 27, 2025
44fe1ff
Trgigger CI
franciszekjob Jan 27, 2025
d45b63e
Remove `install_devnet.yml` workflow
franciszekjob Jan 27, 2025
480862c
Add todo in `checks.yml`
franciszekjob Jan 27, 2025
1c56dcf
Remove temporary step for showing dirs
franciszekjob Jan 27, 2025
90877d4
Move `parsed_abi_v2` into `test_event_serialization_v2`
franciszekjob Jan 27, 2025
1bffab1
Fix formatting
franciszekjob Jan 27, 2025
54da25a
Add echo for displaying contracts v2 directory contents
franciszekjob Jan 27, 2025
9e8e356
Fix displaying contents of contracts v2 directory
franciszekjob Jan 27, 2025
1431174
Temporary change for displaying directory contents
franciszekjob Jan 27, 2025
4c3bbf0
Temporarily list contract v2 directory
franciszekjob Jan 27, 2025
2ad7fe7
Temporarily display owd
franciszekjob Jan 27, 2025
a71dc33
Revert "Temporarily display owd"
franciszekjob Jan 27, 2025
cd64e4b
Include Python 3.9 in `Setup Tests` job
franciszekjob Jan 27, 2025
a081bd0
Remove CI changes apart from modified devnet installation
franciszekjob Jan 27, 2025
53945e8
Temporarily display directory with compiled contracts
franciszekjob Jan 27, 2025
c9af96a
Fix ls
franciszekjob Jan 27, 2025
25df9be
Fix ls
franciszekjob Jan 27, 2025
34dddd4
Unconditionally compile contracts v1 and v2
franciszekjob Jan 27, 2025
9e353c2
Use asdf action
franciszekjob Jan 27, 2025
09503e1
Implement `test_get_transaction_status_with_failure_reason`; Code cle…
franciszekjob Jan 27, 2025
b72068d
Fix linting; Tests cleanup
franciszekjob Jan 27, 2025
b78fe68
Update regex in `test_rejection_reason_in_transaction_receipt`
franciszekjob Jan 27, 2025
43c303c
Skip `test_compute_deploy_account_v3_transaction_hash`
franciszekjob Jan 27, 2025
97ccdef
Format
franciszekjob Jan 27, 2025
6e2ccc7
Skip `test_block_with_receipts_latest`
franciszekjob Jan 27, 2025
424e122
Fix failing docs tests
franciszekjob Jan 27, 2025
a0f3671
Fix linting
franciszekjob Jan 27, 2025
993508b
Remove contracts conditional compilation on CI
franciszekjob Jan 27, 2025
bd09a44
Add contracts compilation steps in docs tests
franciszekjob Jan 27, 2025
685b466
Skip `test_get_transaction_by_block_id`; Add todo
franciszekjob Jan 27, 2025
acaa392
Skip `test_get_transaction_by_block_id`; Add todo
franciszekjob Jan 27, 2025
9a16fdc
Skip `test_using_full_node_client`; Add todo
franciszekjob Jan 27, 2025
680317a
Skip `test_get_transaction_by_block_id`; Add todo
franciszekjob Jan 27, 2025
4bd520b
Add todos
franciszekjob Jan 28, 2025
8ad1d75
Add todos in workflow
franciszekjob Jan 29, 2025
bf1274b
Update resource bounds params
franciszekjob Jan 29, 2025
68adca7
Minor refactor of resource bounds params usage
franciszekjob Jan 30, 2025
20ad81a
Update resource bounds params
franciszekjob Jan 30, 2025
c7fb9bd
Apply code review suggestion
franciszekjob Jan 30, 2025
24a1357
Add `storage_root` field to `ContractLeafData`
franciszekjob Jan 30, 2025
c1dcbcb
Merge branch 'franciszekjob/1498-2-get-compiled-casm' of https://gith…
franciszekjob Jan 30, 2025
2ebead7
Rename `block` to `block_id` param in ws methods
franciszekjob Jan 30, 2025
372609f
Add `is_reverted` field to `FunctionInvocation`
franciszekjob Jan 30, 2025
706196a
Add todo
franciszekjob Jan 30, 2025
ceb1706
Remove `block_id` param from `starknet_subscribeTransactionStatus` en…
franciszekjob Jan 30, 2025
7819a66
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Jan 30, 2025
bde997d
Remove `contracts_storage_proof` field from `ContractsProof`
franciszekjob Jan 30, 2025
f868364
Fix `storage_root` data key
franciszekjob Jan 30, 2025
0edf8d1
Implement `test_get_messages_status`
franciszekjob Jan 30, 2025
8b7a4c1
Fix `test_latest_resource_bounds_take_precedence`
franciszekjob Feb 26, 2025
c0da326
Fix `test_deploy_prefunded_account`
franciszekjob Feb 26, 2025
4ea1317
Remove mocks from full node client
franciszekjob Feb 26, 2025
dd195ac
Add `l1_data_gas` to `ExecutionResources`
franciszekjob Feb 26, 2025
9c2b3c2
Update `CommonTransactionV3Fields.compute_resource_bounds_for_fee`
franciszekjob Feb 26, 2025
cae0da3
Add `l1_data_gas` to ExecutionResourcesSchema`
franciszekjob Feb 26, 2025
d7914ea
Fix `FullNodeClient.estimate_fee`
franciszekjob Feb 26, 2025
e7e8b64
Fix contract tests
franciszekjob Feb 26, 2025
4c39b2b
Temporarily skip some tests; Fix other tests
franciszekjob Feb 27, 2025
b4189eb
Update devnet sha
franciszekjob Feb 27, 2025
8ff797a
Remove code, tests and docs for old txs
franciszekjob Feb 27, 2025
1702e0e
Fix lint and typecheck
franciszekjob Feb 27, 2025
4d13bfc
Fix formatting
franciszekjob Feb 27, 2025
f2392e5
Fix lint and typecheck
franciszekjob Feb 27, 2025
ca2acab
Remove old txs usages, adjust tests and docs
franciszekjob Feb 27, 2025
093f956
Fix tests
franciszekjob Feb 27, 2025
7c49192
Remove todos
franciszekjob Feb 27, 2025
0774348
Remove `test_account_get_balance_eth`
franciszekjob Feb 27, 2025
ddafd39
Fix other tests
franciszekjob Feb 27, 2025
fd351ca
Skip test
franciszekjob Feb 28, 2025
73f2692
Adjust devnet
franciszekjob Feb 28, 2025
9475a36
Fix skip mark
franciszekjob Feb 28, 2025
2b2d7a5
Remove skip marks; Fix tests
franciszekjob Feb 28, 2025
e019506
Update ledger app sha
franciszekjob Feb 28, 2025
8152c21
Refactor assertion in test
franciszekjob Feb 28, 2025
1e3643b
Restore original `test_ci_v2`
franciszekjob Feb 28, 2025
d359e9b
Remove `ResourceBounds.init_with_l1_gas_only`
franciszekjob Feb 28, 2025
8c1a4c3
Add todos
franciszekjob Feb 28, 2025
f3a83cb
Formatting
franciszekjob Feb 28, 2025
ad110dc
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
4da960f
Pull main
franciszekjob Feb 28, 2025
c3b3366
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
061a17e
Adjust todos and fixmes
franciszekjob Feb 28, 2025
240c8ad
Use `argent_account_class_hash` in `test_deploy_account_and_transfer`
franciszekjob Feb 28, 2025
d4c2eed
Fix `test_deploy_account_and_transfer`
franciszekjob Feb 28, 2025
df36664
Revert "Fix `test_deploy_account_and_transfer`"
franciszekjob Feb 28, 2025
f67ad37
Revert "Use `argent_account_class_hash` in `test_deploy_account_and_t…
franciszekjob Feb 28, 2025
2468055
Skip and add todo for `test_deploy_account_and_transfer`
franciszekjob Feb 28, 2025
db6b342
Update skip message for `test_get_transaction_by_block_id`
franciszekjob Feb 28, 2025
6a943fd
Update todo
franciszekjob Feb 28, 2025
d9a2091
Remove `--initial-balance` flag for devnet start
franciszekjob Feb 28, 2025
dd9a037
Revert "Remove `--initial-balance` flag for devnet start"
franciszekjob Feb 28, 2025
a34ece9
Fix models and schemas for `get_storage_proof`; Add tests
franciszekjob Feb 28, 2025
7eb95b0
Add storage proof response json
franciszekjob Feb 28, 2025
c9027fa
Restore values in storage proof response json
franciszekjob Feb 28, 2025
d7f9afa
Use shorter example response for `get_storage_proof` test
franciszekjob Feb 28, 2025
2293012
Adjust storage proof tests
franciszekjob Feb 28, 2025
d6dd873
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
2ea844e
Remove helper function
franciszekjob Feb 28, 2025
b61bc4a
Update migration guide
franciszekjob Feb 28, 2025
eadc306
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
3472c77
Update migration guide
franciszekjob Feb 28, 2025
c3f1280
Fix linting
franciszekjob Feb 28, 2025
825d2b3
Fix formatting
franciszekjob Feb 28, 2025
dfa2565
Pull changes from upstream
franciszekjob Feb 28, 2025
26ae3b2
Remove unused imports
franciszekjob Feb 28, 2025
965ddfb
Add file with `ContractsStorageKeysSchema`
franciszekjob Feb 28, 2025
005df53
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
b1324fb
Pull changes from upstream
franciszekjob Feb 28, 2025
2c9ace9
Fix `test_get_storage_proof`
franciszekjob Feb 28, 2025
91df2ae
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
00ae4bc
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Feb 28, 2025
b2341f6
Remove multipliers from `EstimatedFee.to_resource_bounds`
franciszekjob Feb 28, 2025
3471fd0
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Feb 28, 2025
53c6720
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Feb 28, 2025
554c506
update todo
franciszekjob Feb 28, 2025
edf6244
Fix and update network tests
franciszekjob Mar 3, 2025
9a24a3a
Fix devnet client tests
franciszekjob Mar 3, 2025
874d549
Fix CI
franciszekjob Mar 3, 2025
88eae81
Use asdf action
franciszekjob Mar 3, 2025
6a08d7a
Restore `Download contracts` step in CI
franciszekjob Mar 3, 2025
d3ee384
Temporarily list contracts dir
franciszekjob Mar 3, 2025
a0da29a
Update listing dirs
franciszekjob Mar 3, 2025
ab7201a
Update listing dirs
franciszekjob Mar 3, 2025
95b6612
Temporary CI change
franciszekjob Mar 3, 2025
ad3092a
Display compiled contracts path
franciszekjob Mar 3, 2025
09582cb
Compile contract before running tests in CI
franciszekjob Mar 3, 2025
afc276d
Merge branch 'franciszekjob/1498-fix-network-tests' of https://github…
franciszekjob Mar 3, 2025
6919c41
Partially implement `test_get_compiled_casm`
franciszekjob Mar 3, 2025
bf40c24
Fix params in `FullNodeClient.get_compiled_casm`
franciszekjob Mar 3, 2025
334ae73
Update dependencies
franciszekjob Mar 3, 2025
98102b2
Restore read api for txs other than v3
franciszekjob Mar 3, 2025
9130912
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Mar 3, 2025
403acda
Refactor broadcasted txn schemas
franciszekjob Mar 3, 2025
be1d06c
Add todo as skip reason
franciszekjob Mar 3, 2025
96437db
Add `test_sign_invoke_v3_auto_estimate`
franciszekjob Mar 3, 2025
6e89aeb
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Mar 3, 2025
ff9e751
Run `poetry lock`
franciszekjob Mar 3, 2025
504a4bf
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Mar 3, 2025
149b3e7
Restore test values in `test_get_transaction_by_block_id_and_index`
franciszekjob Mar 3, 2025
8dff862
Fix docs
franciszekjob Mar 3, 2025
e769188
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Mar 3, 2025
4560095
Docstrings formatting
franciszekjob Mar 3, 2025
425a1ab
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Mar 3, 2025
4b30550
Merge branch 'franciszekjob/1498-fix-network-tests' of https://github…
franciszekjob Mar 3, 2025
bd795f2
Add todos
franciszekjob Mar 4, 2025
f2c8725
Merge branch 'franciszekjob/1498-remove-old-txs' of https://github.co…
franciszekjob Mar 4, 2025
555c0f2
Merge branch 'franciszekjob/1498-fix-network-tests' of https://github…
franciszekjob Mar 4, 2025
b9c8f54
Remove old transactions (#1557)
franciszekjob Mar 4, 2025
7b6c1cf
Fix `test_transaction_not_received_max_fee_too_big`
franciszekjob Mar 4, 2025
7e2482b
Resolve merge conflicts
franciszekjob Mar 4, 2025
b859d78
Merge branch 'franciszekjob/1498-fix-network-tests' of https://github…
franciszekjob Mar 4, 2025
9d6b269
Fix and update network tests (#1563)
franciszekjob Mar 4, 2025
6839a41
Add rust toolchain installation
franciszekjob Mar 4, 2025
e204733
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Mar 4, 2025
f02a234
Add `HintSchema`; Rename fields
franciszekjob Mar 4, 2025
8911fca
Update field names in models
franciszekjob Mar 4, 2025
d135bc5
Add tests for `get_compiled_casm`
franciszekjob Mar 4, 2025
86dee4d
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Mar 4, 2025
7ccbf0e
Move models and schema from executables api to separate files
franciszekjob Mar 4, 2025
b4da6f5
Add docs
franciszekjob Mar 4, 2025
eff757e
Fix migration guide
franciszekjob Mar 4, 2025
5484105
Pull changes from upstream
franciszekjob Mar 4, 2025
d097214
Rename file
franciszekjob Mar 4, 2025
e0ecdf5
Fix `test_get_compiled_casm` for devnet
franciszekjob Mar 4, 2025
90b1060
Remove unused import
franciszekjob Mar 4, 2025
a8ad3c6
Add `STARKNET_PY_MARSHMALLOW_UNKNOWN_EXCLUDE` to CI
franciszekjob Mar 4, 2025
c1d9235
Change `index_delta_minus_1` to `index_delta_minus1`
franciszekjob Mar 4, 2025
01fe3df
Add fixes in executables schemas and models
franciszekjob Mar 5, 2025
3e7578f
Use schema with excluding unknown fields for `CasmClassSchema`
franciszekjob Mar 5, 2025
57a3ec2
Update todos
franciszekjob Mar 5, 2025
d6750e4
Merge branch 'franciszekjob/1498-2-get-compiled-casm' of https://gith…
franciszekjob Mar 5, 2025
1bd395d
Support `starknet_getCompiledCasm` (#1514)
franciszekjob Mar 5, 2025
23381b5
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Mar 5, 2025
5103bf8
Add todos
franciszekjob Mar 5, 2025
855f30b
Merge branch 'franciszekjob/1498-rpc-0.8.0' of https://github.com/sof…
franciszekjob Mar 5, 2025
a9af3cc
Merge branch 'development' of https://github.com/software-mansion/sta…
franciszekjob Mar 30, 2025
41f3a06
Add missing websocket API methods; Add tests
franciszekjob Apr 1, 2025
ab9fa6a
Fix formatting
franciszekjob Apr 1, 2025
12e242a
Remove composite action
franciszekjob Apr 1, 2025
830f831
Format and lint
franciszekjob Apr 1, 2025
132ae58
Add more tests
franciszekjob Apr 1, 2025
f55c041
Further improvements of websocket client
franciszekjob Apr 1, 2025
8ed4671
Remove api docs (will be added in subsequent PR)
franciszekjob Apr 2, 2025
1236dc7
Run `poetry lock`
franciszekjob Apr 2, 2025
9e7168e
Update docstrings
franciszekjob Apr 2, 2025
d57cc18
Add `WebsocketClientError`
franciszekjob Apr 2, 2025
991eb79
Fix `pytest_plugins`
franciszekjob Apr 2, 2025
a611bec
Remove unused schemas; Refactor passing block number and block hash p…
franciszekjob Apr 2, 2025
70a38ba
Remove unused `WSClient`
franciszekjob Apr 2, 2025
2ea58e8
Add `devnet_ws` fixture
franciszekjob Apr 2, 2025
423d10f
Add `test_new_heads_subscription_block_not_found`
franciszekjob Apr 2, 2025
a165e45
Remove prints
franciszekjob Apr 2, 2025
7eec2fa
Fix passing block id
franciszekjob Apr 2, 2025
74659d1
Update websocket schemas
franciszekjob Apr 2, 2025
315e68e
Add devnet websocket fixture
franciszekjob Apr 2, 2025
d11e2e5
Remove `test_new_heads_subscription_block_not_found`
franciszekjob Apr 2, 2025
cd1bfaf
Restructure files; Add new tests
franciszekjob Apr 2, 2025
9b57962
Remove unused model
franciszekjob Apr 2, 2025
5ddd91a
Add missing docstrings
franciszekjob Apr 2, 2025
96e2106
Update subscription id type to `str` (RPC 0.8.1)
franciszekjob Apr 2, 2025
22bb883
Fix formatting
franciszekjob Apr 2, 2025
591acca
Remove unused schema
franciszekjob Apr 2, 2025
c9a026b
Add `is_connected` property; Add connection test
franciszekjob Apr 2, 2025
652657b
Little comments cleanup
franciszekjob Apr 2, 2025
9910d00
Add websockets docs; Add code examples
franciszekjob Apr 2, 2025
d2a22cb
Add api and guide docs files
franciszekjob Apr 2, 2025
d796c63
Remove unneeded file
franciszekjob Apr 2, 2025
385495c
Rename `reorg_notification_handler` to `on_chain_reorg`
franciszekjob Apr 2, 2025
0746a0f
Fix formatting
franciszekjob Apr 2, 2025
1825400
Merge branch 'franciszekjob/1498-3-websockets' of https://github.com/…
franciszekjob Apr 2, 2025
2d2cf27
Trigger CI
franciszekjob Apr 3, 2025
8946c05
Format docstrings of `subscribe_pending_transactions`
franciszekjob Apr 3, 2025
0fddec1
Fix docs
franciszekjob Apr 3, 2025
247ff2c
Update `transaction_details` param description
franciszekjob Apr 3, 2025
eddf8bc
Increase sleep time in `test_subscribe_transaction_status`
franciszekjob Apr 3, 2025
4648c20
Fix serialize method in `PendingTransactionsNotificationResultField`
franciszekjob Apr 3, 2025
e0f0c66
Merge branch 'franciszekjob/1498-3-websockets' of https://github.com/…
franciszekjob Apr 3, 2025
83f84d5
Merge branch 'development' of https://github.com/software-mansion/sta…
franciszekjob Apr 6, 2025
649c8ea
Merge branch 'franciszekjob/1498-3-websockets' of https://github.com/…
franciszekjob Apr 6, 2025
ff17d73
Apply code review suggestions
franciszekjob Apr 7, 2025
0340cbf
Apply code review suggestions
franciszekjob Apr 8, 2025
382a837
Change subscription id type to int
franciszekjob Apr 8, 2025
0bf56d2
Merge branch 'franciszekjob/1498-3-websockets' of https://github.com/…
franciszekjob Apr 8, 2025
ffbde39
Change type of subscription id to str
franciszekjob Apr 8, 2025
1c55ed9
Merge branch 'franciszekjob/1498-3-websockets' of https://github.com/…
franciszekjob Apr 8, 2025
1135bbc
Merge branch 'development' of https://github.com/software-mansion/sta…
franciszekjob Apr 8, 2025
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
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ API
api/serializers
api/proxy_resolvers
api/typed_data
api/websocket_client
8 changes: 8 additions & 0 deletions docs/api/websocket_client.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WebsocketClient
===============

.. py:module:: starknet_py.net.websockets.websocket_client

.. autoclass-with-examples:: WebsocketClient
:members:
:member-order: groupwise
1 change: 1 addition & 0 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Guide
guide/serialization
guide/signing
guide/generating_key_pair
guide/websockets
98 changes: 98 additions & 0 deletions docs/guide/websockets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Websockets
==========

Introduction
------------
Apart from interacting with Starknet by request-response model, you can also rely on real-time notifications.
Here comes :class:`~starknet_py.net.websockets.websocket_client.WebsocketClient` which allows to establish a connection with Starknet node and listen for events.

Connecting
----------

To begin interacting with Starknet via websockets, create a new instance of :class:`~starknet_py.net.websockets.websocket_client.WebsocketClient` and connect to the node.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: connect
:end-before: docs-end: connect

Different subscription methods
------------------------------

New block headers
#################

To subscribe to new block headers, use :meth:`~starknet_py.net.websockets.websocket_client.WebsocketClient.subscribe_new_heads`.
Every time a new block is created, the event will be fired.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: subscribe_new_heads
:end-before: docs-end: subscribe_new_heads

New events
##########

To subscribe to new events, use :meth:`~starknet_py.net.websockets.websocket_client.WebsocketClient.subscribe_events`.
Every time a new event is emitted, the event will be fired.

It's possible to filter events by contract addresses, keys and block id. See all options in the method documentation.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: subscribe_events
:end-before: docs-end: subscribe_events


Transaction status
##################

To subscribe to transaction status changes, use :meth:`~starknet_py.net.websockets.websocket_client.WebsocketClient.subscribe_transaction_status`.
Every time a transaction status changes, the event will be fired.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: subscribe_transaction_status
:end-before: docs-end: subscribe_transaction_status


Pending transactions
####################

To subscribe to pending transactions, use :meth:`~starknet_py.net.websockets.websocket_client.WebsocketClient.subscribe_pending_transactions`.
Every time a new pending transaction is added, the event will be fired.

It's possible to filter pending transactions by sender address.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: subscribe_pending_transactions
:end-before: docs-end: subscribe_pending_transactions

Handling chain reorganization notifications
###########################################

When subscribing to new block headers, events, or transaction statuses, you also receive notifications of chain reorganizations. For example, if two blocks are produced nearly simultaneously and one replaces the other as the canonical block, you'll get an update indicating that the chain has restructured.
To handle them, you need to set the ``on_chain_reorg`` to your custom function.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: on_chain_reorg
:end-before: docs-end: on_chain_reorg

Disconnecting
-------------

To disconnect from the node, use :meth:`~starknet_py.net.websockets.websocket_client.WebsocketClient.disconnect`.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/code_examples/test_websocket_client.py
:language: python
:dedent: 4
:start-after: docs-start: disconnect
:end-before: docs-end: disconnect
6 changes: 3 additions & 3 deletions starknet_py/net/websockets/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ async def subscribe_pending_transactions(
While there is no mempool, this notifies of transactions in the pending block.

:param handler: The function to call when a new pending transaction is received.
:param transaction_details: Whether to include transaction details in the notification.
If false, only hash is returned.
:param transaction_details: If false, only hash is returned, otherwise full transaction details.
:param sender_address: The sender address to filter transactions by.

:return: The subscription ID.
"""
params = {}
Expand Down Expand Up @@ -220,7 +220,7 @@ def on_chain_reorg(
@on_chain_reorg.setter
def on_chain_reorg(self, handler: Callable[[ReorgNotification], Any]):
"""
Sets the handler for reorg notifications.
Sets the handler for chain reorg notifications.

:param handler: The handler for chain reorg notifications.
"""
Expand Down
219 changes: 3 additions & 216 deletions starknet_py/tests/e2e/client/websocket_client_test.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,13 @@
import asyncio
from typing import List, Optional, Union
from typing import Optional

import pytest

from starknet_py.devnet_utils.devnet_client import DevnetClient
from starknet_py.hash.selector import get_selector_from_name
from starknet_py.net.account.base_account import BaseAccount
from starknet_py.net.client_models import (
BlockHeader,
Call,
EmittedEvent,
StarknetBlock,
TransactionExecutionStatus,
TransactionStatus,
)
from starknet_py.net.client_models import BlockHeader, StarknetBlock
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.models import StarknetChainId
from starknet_py.net.websockets.errors import WebsocketClientError
from starknet_py.net.websockets.models import (
NewEventsNotification,
NewHeadsNotification,
NewTransactionStatus,
PendingTransactionsNotification,
ReorgData,
ReorgNotification,
Transaction,
TransactionStatusNotification,
)
from starknet_py.net.websockets.models import NewHeadsNotification
from starknet_py.net.websockets.websocket_client import WebsocketClient
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS


@pytest.mark.asyncio
async def test_connect_and_disconnect(devnet_ws: str):
websocket_client = WebsocketClient(devnet_ws)
assert not await websocket_client.is_connected

await websocket_client.connect()
assert await websocket_client.is_connected

await websocket_client.disconnect()
assert not await websocket_client.is_connected


@pytest.mark.asyncio
async def test_subscribe_new_heads(
websocket_client: WebsocketClient,
devnet_client: DevnetClient,
):
received_block: Optional[BlockHeader] = None

def handler(new_heads_notification: NewHeadsNotification):
nonlocal received_block
received_block = new_heads_notification.result

subscription_id = await websocket_client.subscribe_new_heads(handler=handler)

new_block_hash = await devnet_client.create_block()

assert received_block is not None
assert int(new_block_hash, 16) == received_block.block_hash

unsubscribe_result = await websocket_client.unsubscribe(subscription_id)
assert unsubscribe_result is True


@pytest.mark.asyncio
Expand Down Expand Up @@ -156,164 +101,6 @@ async def test_subscribe_new_heads_too_many_blocks_back(
)


@pytest.mark.asyncio
async def test_subscribe_events(
websocket_client: WebsocketClient,
deployed_balance_contract,
argent_account_v040: BaseAccount,
):
emitted_events: List[EmittedEvent] = []

def handler(new_events_notification: NewEventsNotification):
nonlocal emitted_events
emitted_events.append(new_events_notification.result)

subscription_id = await websocket_client.subscribe_events(
handler=handler, from_address=argent_account_v040.address
)

increase_balance_call = Call(
to_addr=deployed_balance_contract.address,
selector=get_selector_from_name("increase_balance"),
calldata=[100],
)
execute = await argent_account_v040.execute_v3(
calls=increase_balance_call, resource_bounds=MAX_RESOURCE_BOUNDS
)
await argent_account_v040.client.wait_for_tx(tx_hash=execute.transaction_hash)
await argent_account_v040.client.get_transaction_receipt(
tx_hash=execute.transaction_hash
)

assert len(emitted_events) > 0
for emitted_event in emitted_events:
assert emitted_event.from_address == argent_account_v040.address

unsubscribe_result = await websocket_client.unsubscribe(subscription_id)
assert unsubscribe_result is True


@pytest.mark.asyncio
async def test_subscribe_transaction_status(
websocket_client: WebsocketClient,
deployed_balance_contract,
argent_account_v040: BaseAccount,
):
new_transaction_status: Optional[NewTransactionStatus] = None

def handler(transaction_status_notification: TransactionStatusNotification):
nonlocal new_transaction_status
new_transaction_status = transaction_status_notification.result

increase_balance_call = Call(
to_addr=deployed_balance_contract.address,
selector=get_selector_from_name("increase_balance"),
calldata=[100],
)
execute = await argent_account_v040.execute_v3(
calls=increase_balance_call, resource_bounds=MAX_RESOURCE_BOUNDS
)

subscription_id = await websocket_client.subscribe_transaction_status(
handler=handler, transaction_hash=execute.transaction_hash
)

await argent_account_v040.client.wait_for_tx(tx_hash=execute.transaction_hash)
await argent_account_v040.client.get_transaction_receipt(
tx_hash=execute.transaction_hash
)

await asyncio.sleep(5)

assert new_transaction_status is not None
assert new_transaction_status.transaction_hash == execute.transaction_hash
assert (
new_transaction_status.status.finality_status
== TransactionStatus.ACCEPTED_ON_L2
)
assert (
new_transaction_status.status.execution_status
== TransactionExecutionStatus.SUCCEEDED
)
assert new_transaction_status.status.failure_reason is None

unsubscribe_result = await websocket_client.unsubscribe(subscription_id)
assert unsubscribe_result is True


@pytest.mark.asyncio
async def test_subscribe_pending_transactions(
websocket_client: WebsocketClient,
deployed_balance_contract,
argent_account_v040: BaseAccount,
):
pending_transactions: List[Union[int, Transaction]] = []

def handler(pending_transaction_notification: PendingTransactionsNotification):
nonlocal pending_transactions
pending_transactions.append(pending_transaction_notification.result)

subscription_id = await websocket_client.subscribe_pending_transactions(
handler=handler,
sender_address=[argent_account_v040.address],
)

increase_balance_call = Call(
to_addr=deployed_balance_contract.address,
selector=get_selector_from_name("increase_balance"),
calldata=[100],
)
execute = await argent_account_v040.execute_v3(
calls=increase_balance_call, resource_bounds=MAX_RESOURCE_BOUNDS
)

await argent_account_v040.client.wait_for_tx(tx_hash=execute.transaction_hash)
await argent_account_v040.client.get_transaction_receipt(
tx_hash=execute.transaction_hash
)

assert len(pending_transactions) == 1
pending_transaction = pending_transactions[0]

transaction_hash = (
execute.transaction_hash
if isinstance(pending_transaction, int)
else pending_transaction.calculate_hash(StarknetChainId.SEPOLIA)
)
assert execute.transaction_hash == transaction_hash

unsubscribe_result = await websocket_client.unsubscribe(subscription_id)
assert unsubscribe_result is True


@pytest.mark.asyncio
async def test_receive_reorg_notification(
websocket_client: WebsocketClient,
devnet_client: DevnetClient,
):
reorg_data: Optional[ReorgData] = None

def handler_reorg(reorg_notification: ReorgNotification):
nonlocal reorg_data
reorg_data = reorg_notification.result

subscription_id = await websocket_client.subscribe_new_heads(handler=lambda _: _)

websocket_client.on_chain_reorg = handler_reorg
new_block_hash = await devnet_client.create_block()

await devnet_client.abort_block(block_hash=new_block_hash)

await asyncio.sleep(5)

assert reorg_data is not None
assert reorg_data.starting_block_hash == int(new_block_hash, 16)
assert reorg_data.ending_block_hash == int(new_block_hash, 16)

unsubscribe_result = await websocket_client.unsubscribe(subscription_id)
assert unsubscribe_result is True


@pytest.mark.asyncio
async def test_unsubscribe_with_non_existing_id(
websocket_client: WebsocketClient,
Expand Down
Loading