Exemplo n.º 1
0
def validate_project_directory(project_dir: Path) -> None:
    if not project_dir.is_dir():
        raise ValidationError(f"{project_dir} is not a valid directory")

    if not (project_dir / "contracts").is_dir():
        raise ValidationError(
            f"{project_dir} must contain a contracts/ directory that contains project contracts."
        )
Exemplo n.º 2
0
def setup_xdg_ethpm_dir(xdg_ethpmcli_root: Path, w3: Web3) -> None:
    if not xdg_ethpmcli_root.is_dir():
        initialize_xdg_ethpm_dir(xdg_ethpmcli_root, w3)

    if not (xdg_ethpmcli_root / IPFS_CHAIN_DATA).is_file():
        raise ValidationError(
            f"Invalid xdg ethpm dir found @ {xdg_ethpmcli_root}. No IPFS chain data file found."
        )

    if not (xdg_ethpmcli_root / KEYFILE_PATH).is_file():
        raise ValidationError(
            f"Invalid xdg ethpm dir found @ {xdg_ethpmcli_root}. No keyfile found."
        )
Exemplo n.º 3
0
def create_basic_manifest_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    validate_config_has_project_dir_attr(config)
    validate_solc_output(args.project_dir)
    if not args.package_name:
        raise ValidationError(
            "To automatically generate a basic manifest, you must provide a --package-name."
        )

    if not args.package_version:
        raise ValidationError(
            "To automatically generate a basic manifest, you must provide a --package-version."
        )
    generate_basic_manifest(args.package_name, args.package_version, args.project_dir)
Exemplo n.º 4
0
def validate_alias(alias: str) -> None:
    try:
        validate_package_name(alias)
    except EthPMValidationError:
        raise ValidationError(
            f"{alias} is not a valid package name. All aliases must conform "
            "to the ethpm spec definition of a package name.")
Exemplo n.º 5
0
def validate_solc_output(project_dir: Path) -> None:
    solc_output_path = project_dir / SOLC_OUTPUT
    if not solc_output_path.is_file():
        raise ValidationError(
            f"{project_dir} does not contain solc output. Please follow the steps in the "
            "documentation to generate your Solidity compiler output.")
    try:
        solc_output_data = json.loads(solc_output_path.read_text())
    except ValueError:
        raise ValidationError(
            f"Content found at {solc_output_path} does not look like valid json."
        )

    if "contracts" not in solc_output_data:
        raise ValidationError(
            f"JSON found at {solc_output_path} does not look like valid "
            "Solidity compiler standard json output.")
Exemplo n.º 6
0
def validate_same_registry(left: str, right: str) -> None:
    left_uri = parse_registry_uri(left)
    right_uri = parse_registry_uri(right)
    if (not is_same_address(left_uri.address, right_uri.address)
            or left_uri.chain_id != right_uri.chain_id  # noqa: W503
        ):
        raise ValidationError(
            f"Registry URI: {left} does not match the registry found on URI: {right}."
        )
Exemplo n.º 7
0
def setup_w3(chain_id: int, private_key: str = None) -> Web3:
    if chain_id not in SUPPORTED_CHAIN_IDS.keys():
        raise ValidationError(
            f"Chain ID: {chain_id} is invalid. Currently supported chain ids "
            f"include: {list(SUPPORTED_CHAIN_IDS.keys())}.")
    infura_url = f"{SUPPORTED_CHAIN_IDS[chain_id]}.infura.io"
    headers = build_http_headers()
    infura_url = build_infura_url(infura_url)
    w3 = Web3(load_provider_from_uri(infura_url, headers))

    if private_key is not None:
        owner_address = Account.from_key(private_key).address
        signing_middleware = construct_sign_and_send_raw_middleware(
            private_key)
        w3.middleware_onion.add(signing_middleware)
        w3.eth.defaultAccount = to_checksum_address(owner_address)
        cli_logger.debug(
            "In-flight tx signing has been enabled for address: {owner_address}."
        )
    w3.enable_unstable_package_management_api()
    return w3