Ejemplo n.º 1
0
 def _mainnet(self) -> _Web3:
     # a web3 instance connected to the mainnet
     if CONFIG["active_network"]["name"] == "mainnet":
         return self
     if "mainnet" not in CONFIG["network"]["networks"]:
         raise MainnetUndefined("No 'mainnet' network defined in brownie-config.json")
     if not self._mainnet_w3:
         uri = _expand_environment_vars(CONFIG["network"]["networks"]["mainnet"]["host"])
         self._mainnet_w3 = _Web3(HTTPProvider(uri))
         self._mainnet_w3.enable_unstable_package_management_api()
     return self._mainnet_w3
Ejemplo n.º 2
0
 def _mainnet(self) -> _Web3:
     # a web3 instance connected to the mainnet
     if self.isConnected() and CONFIG.active_network["id"] == "mainnet":
         return self
     try:
         mainnet = CONFIG.networks["mainnet"]
     except KeyError:
         raise MainnetUndefined("No 'mainnet' network defined") from None
     if not self._mainnet_w3:
         uri = _expand_environment_vars(mainnet["host"])
         self._mainnet_w3 = _Web3(HTTPProvider(uri))
         self._mainnet_w3.enable_unstable_package_management_api()
     return self._mainnet_w3
Ejemplo n.º 3
0
def _resolve_address(address: str) -> str:
    if not isinstance(address, str) or "." not in address:
        return to_address(address)
    address = address.lower()
    if address not in _ens_cache:
        try:
            ns = ENS.fromWeb3(web3._mainnet)
        except MainnetUndefined as e:
            raise MainnetUndefined(
                f"Cannot resolve ENS address - {e}") from None
        resolved_address = ns.address(address)
        _ens_cache[address] = resolved_address
    if _ens_cache[address] is None:
        raise UnsetENSName(f"ENS address '{address}' is not set")
    return _ens_cache[address]
Ejemplo n.º 4
0
def _resolve_address(domain: str) -> str:
    # convert ENS domain to address
    if not isinstance(domain, str) or "." not in domain:
        return to_address(domain)
    domain = domain.lower()
    if domain not in _ens_cache or time.time() - _ens_cache[domain][1] > 86400:
        try:
            ns = ENS.fromWeb3(web3._mainnet)
        except MainnetUndefined as e:
            raise MainnetUndefined(f"Cannot resolve ENS address - {e}") from None
        address = ns.address(domain)
        _ens_cache[domain] = [address, int(time.time())]
        with _get_path().open("w") as fp:
            json.dump(_ens_cache, fp)
    if _ens_cache[domain][0] is None:
        raise UnsetENSName(f"ENS domain '{domain}' is not set")
    return _ens_cache[domain][0]