Skip to content

Commit

Permalink
fix: missing : (#825)
Browse files Browse the repository at this point in the history
* fix: missing :

* chore: `black .`

* fix: name error (#826)

* chore: bump dank_mids

* fix: private member access

* Update requirements.txt

* fix: post init

* chore: `black .`

* fix: __post_init__ kwargs

* chore: `black .`

* fix: set persist false if contract was already in db

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Nov 29, 2024
1 parent a6c4808 commit 2f5143d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bobs_lazy_logging==0.0.4
checksum_dict>=1.4.1,<2
dank_mids>=4.20.106
dank_mids>=4.20.108
eth-brownie>=1.19.3,<1.21
eth_retry>=0.1.19,<0.2
ez-a-sync>=0.24.20
Expand Down
66 changes: 34 additions & 32 deletions y/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,6 @@ def __init__(
# Try to fetch the contract from the local sqlite db.
with _brownie_deployments_db_lock:
super().__init__(address, owner=owner)
if not isinstance(self.verified, bool) and self.verified is not None:
logger.warning(
f'`Contract("{address}").verified` property will not be usable due to the contract having a `verified` method in its ABI.'
)
self.__finish_init(cache_ttl)
return
except (AssertionError, IndexError) as e:
if str(e) == "pop from an empty deque" or isinstance(e, AssertionError):
raise CompilerError from None
Expand All @@ -366,6 +360,14 @@ def __init__(
logger.debug(f"{e}")
if not str(e).startswith("Unknown contract address: "):
raise
else: # Nice, we got it from the db.
if not isinstance(self.verified, bool) and self.verified is not None:
logger.warning(
f'`Contract("{address}").verified` property will not be usable due to the contract having a `verified` method in its ABI.'
)
# schedule call to pop from cache
self._schedule_cache_pop(cache_ttl)
return

# The contract does not exist in your local brownie deployments.db
try:
Expand All @@ -377,7 +379,7 @@ def __init__(
"type": "contract",
}
self.__init_from_abi__(build, owner=owner, persist=True)
self.__finish_init(cache_ttl)
self.__post_init__(cache_ttl)
except (ContractNotFound, exceptions.ContractNotVerified) as e:
if isinstance(e, exceptions.ContractNotVerified):
_unverified.add(address)
Expand Down Expand Up @@ -428,7 +430,7 @@ def from_abi(
"type": "contract",
}
self.__init_from_abi__(build, owner, persist)
self.__finish_init(cache_ttl)
self.__post_init__(cache_ttl)
return self

@classmethod
Expand All @@ -443,7 +445,7 @@ async def coroutine(
) -> Self:

address = str(address)
if contract := cls.get_instance(address)
if contract := cls.get_instance(address):
return contract

# dict lookups faster than string comparisons, keep this behind the singleton check
Expand All @@ -452,23 +454,23 @@ async def coroutine(
ZERO_ADDRESS,
]:
raise ContractNotFound(f"{address} is not a contract.") from None

contract = cls.__new__(cls)
build, _ = await _get_deployment_from_db(address)

if build:
async with _contract_locks[address]:
# now that we're inside the lock, check and see if another coro populated the cache
if cache_value := cls.get_instance(address):
return cache_value

# nope, continue
contract.__init_from_abi__(build, owner=owner, persist=persist)
contract.__finish_init(cache_ttl)
contract.__init_from_abi__(build, owner=owner, persist=False)
contract.__post_init__(cache_ttl)

elif not CONFIG.active_network.get("explorer"):
raise ValueError(f"Unknown contract address: '{address}'")

else:
try:
# The contract does not exist in your local brownie deployments.db
Expand All @@ -485,14 +487,18 @@ async def coroutine(
'`Contract("%s").verified` property will not be usable due to the contract having a `verified` method in its ABI.',
address,
)
contract._build = {"contractName": "Non-Verified Contract" if not_verified else "Broken Contract"}

contract._build = {
"contractName": (
"Non-Verified Contract" if not_verified else "Broken Contract"
)
}

else:
async with _contract_locks[address]:
# now that we're inside the lock, check and see if another coro populated the cache
if cache_value := cls.get_instance(address):
return cache_value

# nope, continue
build = {
"abi": abi,
Expand All @@ -501,9 +507,8 @@ async def coroutine(
"type": "contract",
}
contract.__init_from_abi__(build, owner=owner, persist=persist)
contract.__finish_init(cache_ttl)


contract.__post_init__(cache_ttl)

# Cache manually since we aren't calling init
cls[address] = contract

Expand All @@ -528,9 +533,8 @@ async def coroutine(
)

elif (
(loop := asyncio.get_running_loop()).time() + cache_ttl
> contract._ttl_cache_popper.when()
):
loop := asyncio.get_running_loop()
).time() + cache_ttl > contract._ttl_cache_popper.when():
contract._ttl_cache_popper.cancel()
contract._ttl_cache_popper = loop.call_later(
cache_ttl,
Expand All @@ -539,7 +543,7 @@ async def coroutine(
None,
)
return contract

def __init_from_abi__(
self, build: Dict, owner: Optional[AccountsType] = None, persist: bool = True
) -> None:
Expand Down Expand Up @@ -638,15 +642,13 @@ def _schedule_cache_pop(self, cache_ttl: Optional[int]) -> None:

self._ttl_cache_popper = loop.call_later(
cache_ttl,
cls.delete_instance,
type(self).delete_instance,
self.address,
None,
)

def __finish_init(self, cache_ttl):
# Patch the Contract with coroutines for each method.
# TODO I think we can maybe remove this now, gotta check
dank_mids.patch_contract(self)
def __post_init__(self, cache_ttl: Optional[int] = None) -> None:
super().__post_init__()

# Init an event container for each topic
_setup_events(self)
Expand Down Expand Up @@ -1173,7 +1175,7 @@ async def _resolve_proxy_async(address) -> Tuple[str, List]:
name, abi, _ = await _extract_abi_data_async(as_proxy_for)
return name, abi


_resolve_proxy_async = a_sync.SmartProcessingQueue(_resolve_proxy_async, num_workers=8)


Expand Down

0 comments on commit 2f5143d

Please sign in to comment.