Skip to content

Commit

Permalink
Return the subscription id and result for subscription messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Sep 14, 2023
1 parent 7abf97d commit af37d88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion newsfragments/3096.breaking.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Breaking change to the API for interacting with a persistent websocket connection via ``AsyncWeb3`` and ``WebsocketProviderV2``. This change internalizes the ``provider.ws`` property and opts for a ``w3.ws`` API achieved via a new ``WebsocketConnection`` class.
Breaking change to the API for interacting with a persistent websocket connection via ``AsyncWeb3`` and ``WebsocketProviderV2``. This change internalizes the ``provider.ws`` property and opts for a ``w3.ws`` API achieved via a new ``WebsocketConnection`` class. With these changes, ``eth_subscription`` messages now return the subscription id as the ``subscription`` param and the formatted message as the ``result`` param.
9 changes: 7 additions & 2 deletions web3/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,15 @@ def formatted_response(
return response["result"]
elif (
# eth_subscribe case
response.get("params") is not None
response.get("method") == "eth_subscription"
and response.get("params") is not None
and response["params"].get("subscription") is not None
and response["params"].get("result") is not None
):
return response["params"]["result"]
return {
"subscription": response["params"]["subscription"],
"result": response["params"]["result"],
}
else:
raise BadResponseFormat(
"The response was in an unexpected format and unable to be parsed. "
Expand Down

0 comments on commit af37d88

Please sign in to comment.