You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/subscriptions.rst
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ As of v7.7.0, web3.py includes some additional convenient subscription managemen
49
49
1.) The subscription_manager
50
50
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
51
52
-
First, your w3 instance now includes a new module, subscription_manager. While you may still use the w3.eth.subscribe method from the previous example, the subscription_manager offers an additional way to start one or more subscriptions. We're going to pass in a list of events we want to subscribe to within the w3.subscription_manager.subscribe method.
52
+
First, your ``w3`` (``AsyncWeb3``) instance now includes a new module, ``subscription_manager``. While you may still use the ``w3.eth.subscribe`` method from the previous example, the ``subscription_manager`` offers an additional way to start one or more subscriptions. We're going to pass in a list of events we want to subscribe to within the ``w3.subscription_manager.subscribe`` method.
53
53
54
54
.. code-block:: python
55
55
@@ -59,7 +59,7 @@ First, your w3 instance now includes a new module, subscription_manager. While y
59
59
2.) Subscription types
60
60
~~~~~~~~~~~~~~~~~~~~~~
61
61
62
-
To aid in defining those subscriptions, subscription type classes have been introduced: NewHeadsSubscription, PendingTxSubscription, LogsSubscription, and SyncingSubscription. Each class is context aware, meaning it will throw an error if you provide an unexpected data type.
62
+
To aid in defining those subscriptions, subscription type classes have been introduced: ``NewHeadsSubscription``, ``PendingTxSubscription``, ``LogsSubscription``, and ``SyncingSubscription``. Each class is context aware, meaning it will throw an error if you provide an unexpected data type.
63
63
64
64
.. code-block:: python
65
65
@@ -94,7 +94,7 @@ To aid in defining those subscriptions, subscription type classes have been intr
94
94
~~~~~~~~~~~~
95
95
96
96
In the example above, there is a handler specified for each subscription. These are context-aware functions that you can declare separate from the subscription logic. Within each handler, parse and perform whatever logic you require.
97
-
Note that in addition to the result being processed, the handler_context in each handler provides access to your async_w3 instance, the subscription instance, and any custom values declared within the handler_context of the subscription. from web3.utils.subscriptions import LogsSubscriptionContext
97
+
Note that in addition to the result being processed, the ``handler_context`` in each handler provides access to your ``AsyncWeb3`` instance, the subscription instance, and any custom values declared within the ``handler_context`` of the subscription: ``from web3.utils.subscriptions import LogsSubscriptionContext``
98
98
99
99
.. code-block:: python
100
100
@@ -136,10 +136,10 @@ Finally, when all your subscriptions are configured, utilize the handle_subscrip
136
136
5.) Unsubscribing
137
137
~~~~~~~~~~~~~~~~~
138
138
139
-
If you don't want to subscribe indefinitely to an event, you can unsubscribe at any point. The first example in this post demonstrated the manual approach:await w3.eth.unsubscribe(subscription_id)
139
+
If you don't want to subscribe indefinitely to an event, you can unsubscribe at any point. The first example in this post demonstrated the manual approach: ``await w3.eth.unsubscribe(subscription_id)``
140
140
141
141
142
-
The new handler pattern will keep track of the subscription ID for you however, so the same can be accomplished via the handler_context without an ID:
142
+
The new handler pattern will keep track of the subscription ID for you however, so the same can be accomplished via the ``handler_context`` without an ID:
143
143
144
144
.. code-block:: python
145
145
@@ -149,7 +149,7 @@ The new handler pattern will keep track of the subscription ID for you however,
149
149
await handler_context.subscription.unsubscribe()
150
150
151
151
152
-
Lastly, if you're wrapping up the whole show, you can reach for unsubscribe_all on the subscription_manager:
152
+
Lastly, if you're wrapping up the whole show, you can reach for ``unsubscribe_all`` on the subscription_manager:
153
153
154
154
.. code-block:: python
155
155
@@ -222,7 +222,7 @@ FAQ
222
222
How can I subscribe to additional events once my application is running?
0 commit comments