def get_local_package(self, package_name: str, ethpm_dir: Path = None) -> Package: """ Returns a `Package <https://github.com/ethpm/py-ethpm/blob/master/ethpm/package.py>`__ instance built with the Manifest found at the package name in your local ethpm_dir. * Parameters: * ``package_name``: Must be the name of a package installed locally. * ``ethpm_dir``: Path pointing to the target ethpm directory (optional). """ if not ethpm_dir: ethpm_dir = Path.cwd() / '_ethpm_packages' if not ethpm_dir.name == "_ethpm_packages" or not ethpm_dir.is_dir(): raise PMError( f"{ethpm_dir} is not a valid ethPM packages directory.") local_packages = [ pkg.name for pkg in ethpm_dir.iterdir() if pkg.is_dir() ] if package_name not in local_packages: raise PMError(f"Package: {package_name} not found in {ethpm_dir}. " f"Available packages include: {local_packages}.") target_manifest = json.loads( (ethpm_dir / package_name / "manifest.json").read_text()) return self.get_package_from_manifest(target_manifest)
def _validate_set_registry(self) -> None: try: self.registry except AttributeError: raise PMError("web3.pm does not have a set registry. " "Please set registry with either: " "web3.pm.set_registry(address) or " "web3.pm.deploy_and_set_registry()") if not isinstance(self.registry, ERC1319Registry): raise PMError( "web3.pm requires an instance of a subclass of ERC1319Registry " "to be set as the web3.pm.registry attribute. Instead found: " f"{type(self.registry)}.")
def _release(self, package_name: str, version: str, manifest_uri: str) -> bytes: if len(package_name) > 32 or len(version) > 32: raise PMError( "Vyper registry only works with package names and versions less than 32 chars." ) if len(manifest_uri) > 1000: raise PMError( "Vyper registry only works with manifest URIs shorter than 1000 chars." ) args = process_vyper_args(package_name, version, manifest_uri) tx_hash = self.registry.functions.release(*args).transact() self.w3.eth.waitForTransactionReceipt(tx_hash) return self._get_release_id(package_name, version)
def set_registry(self, address: Address) -> None: """ Sets the current registry used in ``web3.pm`` functions that read/write to an on-chain registry. This method accepts checksummed/canonical addresses or ENS names. Addresses must point to an on-chain instance of an ERC1319 registry implementation. To use an ENS domain as the address, make sure a valid ENS instance set as ``web3.ens``. * Parameters: * ``address``: Address of on-chain Registry. """ if is_canonical_address(address) or is_checksum_address(address): self.registry = SimpleRegistry(address, self.web3) elif is_ens_name(address): self._validate_set_ens() addr_lookup = self.web3.ens.address(address) if not addr_lookup: raise NameNotFound( "No address found after ENS lookup for name: {0}.".format( address)) self.registry = SimpleRegistry(addr_lookup, self.web3) else: raise PMError( "Expected a canonical/checksummed address or ENS name for the address, " "instead received {0}.".format(type(address)))
def set_registry(self, address: Address) -> None: """ Sets the current registry used in ``web3.pm`` functions that read/write to an on-chain registry. This method accepts checksummed/canonical addresses or ENS names. Addresses must point to an instance of the Vyper Reference Registry implementation. If you want to use a different registry implementation with ``web3.pm``, manually set the ``web3.pm.registry`` attribute to any subclass of ``ERCRegistry``. To use an ENS domain as the address, make sure a valid ENS instance set as ``web3.ens``. * Parameters: * ``address``: Address of on-chain Vyper Reference Registry. """ if is_canonical_address(address) or is_checksum_address(address): canonical_address = to_canonical_address(address) self.registry = VyperReferenceRegistry(canonical_address, self.web3) elif is_ens_name(address): self._validate_set_ens() addr_lookup = self.web3.ens.address(address) if not addr_lookup: raise NameNotFound( "No address found after ENS lookup for name: {0}.".format( address)) self.registry = VyperReferenceRegistry( to_canonical_address(addr_lookup), self.web3) else: raise PMError( "Expected a canonical/checksummed address or ENS name for the address, " "instead received {0}.".format(type(address)))