Skip to content

Commit

Permalink
feat: convenience imports (#126)
Browse files Browse the repository at this point in the history
* feat: convenience aliases

* feat: convenience import BlockSemaphore
  • Loading branch information
BobTheBuidler authored Feb 24, 2024
1 parent b95a58f commit 479f745
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion dank_mids/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions dank_mids/brownie_patch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions examples/dank_brownie_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 479f745

Please sign in to comment.