def validate_supported_uri(uri: URI) -> None: if (not is_ipfs_uri(uri) and not is_etherscan_uri(uri) # noqa: W503 and not is_valid_registry_uri(uri) # noqa: W503 and not is_valid_content_addressed_github_uri(uri) # noqa: W503 ): raise UriNotSupportedError( f"Target uri: {uri} not a currently supported uri. " "Target uris must be one of: ipfs, github blob, etherscan, or registry." )
def resolve_manifest_uri(uri: URI, ipfs: BaseIPFSBackend) -> ResolvedManifestURI: github_backend = GithubOverHTTPSBackend() if github_backend.can_resolve_uri(uri): raw_manifest = github_backend.fetch_uri_contents(uri) resolved_content_hash = parse.urlparse(uri).path.split("/")[-1] elif ipfs.can_resolve_uri(uri): raw_manifest = ipfs.fetch_uri_contents(uri) resolved_content_hash = extract_ipfs_path_from_uri(uri) else: raise UriNotSupportedError( f"{uri} is not supported. Currently ethPM CLI only supports " "IPFS and Github blob manifest uris.") return ResolvedManifestURI(raw_manifest, resolved_content_hash)
def activate_package(args: Namespace, config: Config) -> None: # support: etherscan / ipfs / github / erc1319 url = parse.urlparse(args.package_or_uri) if url.scheme: if url.scheme not in SUPPORTED_SCHEMES: raise UriNotSupportedError( f"URIs with a scheme of {url.scheme} are not supported. " f"Currently supported schemes include: {SUPPORTED_SCHEMES}") try: args.package_name = "etherscan" # for etherscan URIs args.package_version = "1.0.0" # for etherscan URIs args.uri = args.package_or_uri cli_pkg = Package(args, config.ipfs_backend) manifest = cli_pkg.manifest except UriNotSupportedError: raise UriNotSupportedError( f"{args.package_or_uri} is not a supported URI. The only URIs currently supported " "are Registry, Github Blob, Etherscan and IPFS") else: if not is_package_installed(args.package_or_uri, config): raise InstallError( f"Package: {args.package_or_uri} not installed in ethPM dir: {config.ethpm_dir}." ) manifest = json.loads((config.ethpm_dir / args.package_or_uri / "manifest.json").read_text()) pkg = ethpmPackage(manifest, config.w3) activation_banner = ( f"{(LIGHTNING_EMOJI + PACKAGE_EMOJI) * 4}{LIGHTNING_EMOJI}\n" f"{bold_white('Activating package')}: {bold_blue(pkg.name)}@{bold_green(pkg.version)}\n" f"{(LIGHTNING_EMOJI + PACKAGE_EMOJI) * 4}{LIGHTNING_EMOJI}\n") cli_logger.info(activation_banner) if "contractTypes" in pkg.manifest: num_contract_types = len(pkg.manifest["contractTypes"]) else: num_contract_types = 0 if "deployments" in pkg.manifest: num_deployments = sum( len(deps) for _, deps in pkg.manifest["deployments"].items()) else: num_deployments = 0 if num_contract_types > 0: available_factories = generate_contract_factories(pkg) if len(available_factories) > 0: formatted_factories = list_keys_for_display(available_factories) factories_banner = ( f"Successfully generated {len(available_factories)} contract " f"{pluralize(len(available_factories), 'factory')} on mainnet from " f"{num_contract_types} detected contract {pluralize(num_contract_types, 'type')}.\n" f"{''.join(formatted_factories)}\n" "To get a contract factory on a different chain, call " f"`{bold_white('get_factory(target_factory, target_w3)')}`\n" "using the available contract fatories and Web3 instances.\n\n" ) else: factories_banner = "\n" else: available_factories = {} factories_banner = "No detected contract types.\n" if num_deployments > 0: available_instances = generate_deployments(pkg, config) formatted_instances = list_keys_for_display(available_instances) deployments_banner = ( f"Successfully generated {len(available_instances)} contract " f"{pluralize(len(available_instances), 'instance')} from {num_deployments} detected " f"{pluralize(num_deployments, 'deployment')}.\n" f"{''.join(formatted_instances)}\n") else: available_instances = {} deployments_banner = "No detected deployments.\n" if config.private_key: auth_banner = ( f"Deployments configured to sign for: {config.w3.eth.defaultAccount}\n" ) else: auth_banner = ( "Contract instances and web3 instances have not been configured with an account.\n" "Use the --keyfile-password flag to enable automatic signing.\n") available_w3s = get_w3s(config) formatted_w3s = list_keys_for_display(available_w3s) web3_banner = "Available Web3 Instances\n" f"{''.join(formatted_w3s)}\n" banner = ( f"{factories_banner}{deployments_banner}{web3_banner}{auth_banner}\n" "The API for web3.py contract factories and instances can be found here:\n" f"{bold_white('https://web3py.readthedocs.io/en/stable/contracts.html')}\n\n" "Starting IPython console... ") helper_fns = {"get_factory": get_factory} embed( user_ns={ **available_factories, **available_instances, # ignore b/c conflicting types w/in dict values **available_w3s, # type: ignore **helper_fns, # type: ignore }, banner1=banner, colors="neutral", )