From 479f74514c034d0e7d2258df1b27ab5ce0a82cbc Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 24 Feb 2024 04:14:46 -0500 Subject: [PATCH] feat: convenience imports (#126) * feat: convenience aliases * feat: convenience import BlockSemaphore --- dank_mids/__init__.py | 7 ++++++- dank_mids/brownie_patch/__init__.py | 2 ++ examples/dank_brownie_example.py | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dank_mids/__init__.py b/dank_mids/__init__.py index 236cf42a..5c4e5eeb 100644 --- a/dank_mids/__init__.py +++ b/dank_mids/__init__.py @@ -2,9 +2,14 @@ from dank_mids.controller import instances from dank_mids.helpers import setup_dank_w3, setup_dank_w3_from_sync from dank_mids.middleware import dank_middleware +from dank_mids.semaphores import BlockSemaphore try: - from dank_mids.brownie_patch import Contract, dank_web3, patch_contract + from dank_mids.brownie_patch import Contract, dank_eth, dank_web3, patch_contract + from web3.eth import AsyncEth as _AsyncEth + # aliased for cleanliness and convenience + web3 = dank_web3 + eth = dank_eth except ImportError: pass diff --git a/dank_mids/brownie_patch/__init__.py b/dank_mids/brownie_patch/__init__.py index 81f24939..6461788c 100644 --- a/dank_mids/brownie_patch/__init__.py +++ b/dank_mids/brownie_patch/__init__.py @@ -6,6 +6,8 @@ from brownie import network, web3 if network.is_connected(): from dank_mids.brownie_patch.contract import Contract, patch_contract + from web3.eth import AsyncEth as _AsyncEth dank_web3 = setup_dank_w3_from_sync(web3) + dank_eth: _AsyncEth = dank_web3.eth except ImportError: pass \ No newline at end of file diff --git a/examples/dank_brownie_example.py b/examples/dank_brownie_example.py index 93808d95..e476bdfa 100644 --- a/examples/dank_brownie_example.py +++ b/examples/dank_brownie_example.py @@ -50,10 +50,10 @@ async def get_tokens_for_pool(pool): ) -# To batch other rpc calls, import and use the dank_web3 instance. -# This instance wraps the connected brownie Web3 instance and injects the dank middleware for batching -from dank_mids import dank_web3 +# To batch other rpc calls, use the `dank_mids.eth` object like you would brownie's `web3.eth` object. +# This object wraps the connected brownie Web3 instance and injects the dank middleware for batching +import dank_mids async def get_timestamp_at_block(block): - block = await dank_web3.eth.get_block(block) + block = await dank_mids.eth.get_block(block) return block.timestamp