Skip to content
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
1 change: 1 addition & 0 deletions newsfragments/3066.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENS name-to-address support for ``eth_subscribe``.
29 changes: 24 additions & 5 deletions web3/middleware/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def name_to_address_middleware(w3: "Web3") -> Middleware:
# -- async -- #


def _is_logs_subscription_with_optional_args(method: RPCEndpoint, params: Any) -> bool:
return method == "eth_subscribe" and len(params) == 2 and params[0] == "logs"


async def async_format_all_ens_names_to_address(
async_web3: "AsyncWeb3",
abi_types_for_method: Sequence[Any],
Expand Down Expand Up @@ -111,12 +115,27 @@ async def async_name_to_address_middleware(
) -> AsyncMiddlewareCoroutine:
async def middleware(method: RPCEndpoint, params: Any) -> Any:
abi_types_for_method = RPC_ABIS.get(method, None)

if abi_types_for_method is not None:
params = await async_apply_ens_to_address_conversion(
async_w3,
params,
abi_types_for_method,
)
if _is_logs_subscription_with_optional_args(method, params):
# eth_subscribe optional logs params are unique.
# Handle them separately here.
(formatted_dict,) = await async_apply_ens_to_address_conversion(
async_w3,
(params[1],),
{
"address": "address",
"topics": "bytes32[]",
},
)
params = (params[0], formatted_dict)

else:
params = await async_apply_ens_to_address_conversion(
async_w3,
params,
abi_types_for_method,
)
return await make_request(method, params)

return middleware