Beispiel #1
0
def _pin_source(
    name: str,
    compiler_output: Dict[str, Any],
    ipfs_backend: BaseIPFSBackend,
    package_root_dir: Optional[Path],
    manifest: Manifest,
) -> Manifest:
    names_and_paths = get_names_and_paths(compiler_output)
    source_path = names_and_paths[name]
    if package_root_dir:
        if not (package_root_dir / source_path).is_file():
            raise ManifestBuildingError(
                f"Unable to find and pin contract source: {source_path} "
                f"under specified package_root_dir: {package_root_dir}.")
        (ipfs_data, ) = ipfs_backend.pin_assets(package_root_dir / source_path)
    else:
        cwd = Path.cwd()
        if not (cwd / source_path).is_file():
            raise ManifestBuildingError(
                f"Unable to find and pin contract source: {source_path} "
                f"current working directory: {cwd}.")
        (ipfs_data, ) = ipfs_backend.pin_assets(cwd / source_path)

    return assoc_in(manifest, ["sources", source_path],
                    f"ipfs://{ipfs_data['Hash']}")
Beispiel #2
0
def _pin_source(
    name: str,
    compiler_output: Dict[str, Any],
    ipfs_backend: BaseIPFSBackend,
    package_root_dir: Optional[Path],
    manifest: Manifest,
) -> Manifest:
    names_and_paths = get_names_and_paths(compiler_output)
    try:
        source_path = names_and_paths[name]
    except KeyError:
        raise ManifestBuildingError(
            f"Unable to pin source: {name}. "
            f"Available sources include: {list(sorted(names_and_paths.keys()))}."
        )
    if package_root_dir:
        if not (package_root_dir / source_path).is_file():
            raise ManifestBuildingError(
                f"Unable to find and pin contract source: {source_path} "
                f"under specified package_root_dir: {package_root_dir}.")
        (ipfs_data, ) = ipfs_backend.pin_assets(package_root_dir / source_path)
    else:
        cwd = Path.cwd()
        if not (cwd / source_path).is_file():
            raise ManifestBuildingError(
                f"Unable to find and pin contract source: {source_path} "
                f"current working directory: {cwd}.")
        (ipfs_data, ) = ipfs_backend.pin_assets(cwd / source_path)

    source_data_object = {
        "urls": [f"ipfs://{ipfs_data['Hash']}"],
        "type": "solidity",
        "installPath": source_path,
    }
    return assoc_in(manifest, ["sources", source_path], source_data_object)
Beispiel #3
0
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)
Beispiel #4
0
def resolve_sources(
        package: Package,
        ipfs_backend: BaseIPFSBackend) -> Iterable[Tuple[str, str]]:
    for path, source in package.manifest["sources"].items():
        if is_ipfs_uri(source):
            contents = to_text(
                ipfs_backend.fetch_uri_contents(source)).rstrip("\n")
        else:
            # for inlined sources
            contents = source
        yield path, contents
Beispiel #5
0
def write_docs_to_disk(package: Package, package_dir: Path,
                       ipfs_backend: BaseIPFSBackend) -> None:
    try:
        doc_uri = package.manifest["meta"]["links"]["documentation"]
    except KeyError:
        return

    if is_ipfs_uri(doc_uri):
        documentation = ipfs_backend.fetch_uri_contents(doc_uri)
        doc_path = package_dir / "documentation.md"
        doc_path.touch()
        doc_path.write_bytes(documentation)
def pin_to_ipfs(
        manifest: Manifest, *, backend: BaseIPFSBackend, prettify: Optional[bool] = False
) -> List[Dict[str, str]]:
    """
    Returns the IPFS pin data after pinning the manifest to the provided IPFS Backend.

    `pin_to_ipfs()` Should *always* be the last argument in a builder, as it will return the pin
    data and not the manifest.
    """
    contents = format_manifest(manifest, prettify=prettify)

    with tempfile.NamedTemporaryFile() as temp:
        temp.write(to_bytes(text=contents))
        temp.seek(0)
        return backend.pin_assets(Path(temp.name))
Beispiel #7
0
def resolve_sources(
        package: Package,
        ipfs_backend: BaseIPFSBackend) -> Iterable[Tuple[str, str]]:
    for path, source_object in package.manifest["sources"].items():
        # for inlined sources
        if "content" in source_object:
            yield path, source_object["content"]
        else:
            ipfs_uri = next(
                (uri for uri in source_object["urls"] if is_ipfs_uri(uri)),
                None)
            if not ipfs_uri:
                raise InstallError(
                    "Manifest is missing a content-addressed uri.")
            contents = to_text(
                ipfs_backend.fetch_uri_contents(ipfs_uri)).rstrip("\n")
            yield path, contents