def get_scraped_blocks(chain_data_path: Path) -> List[int]: scraped_blocks = json.loads(chain_data_path.read_text())["scraped_blocks"] scraped_ranges = [ list(range(int(rnge["min"]), int(rnge["max"]) + 1)) for rnge in scraped_blocks ] return flatten(scraped_ranges)
def write_ipfs_uris_to_disk(ethpm_dir: Path, manifests: Dict[Address, Dict[str, str]]) -> None: all_manifest_uris = [ version_release_data["manifestURI"] for version_release_data in manifests.values() if is_supported_content_addressed_uri(version_release_data["manifestURI"]) ] base_ipfs_uris = [uri for uri in all_manifest_uris if is_ipfs_uri(uri)] nested_ipfs_uris = [ pluck_ipfs_uris_from_manifest(uri) for uri in all_manifest_uris ] all_ipfs_uris = set(flatten(nested_ipfs_uris) + base_ipfs_uris) # ex. # ipfs uri: QmdvZEW3AaUntDfFkcbdnYzeLAAeD4YFeixQsdmHF88T6Q # dir store: ethpmcli/Qm/dv/ZE/QmdvZEW3AaUntDfFkcbdnYzeLAAeD4YFeixQsdmHF88T6Q for uri in all_ipfs_uris: ipfs_hash = extract_ipfs_path_from_uri(uri) first_two_bytes_dir = ethpm_dir / ipfs_hash[0:2] second_two_bytes_dir = first_two_bytes_dir / ipfs_hash[2:4] third_two_bytes_dir = second_two_bytes_dir / ipfs_hash[4:6] asset_dest_path = third_two_bytes_dir / ipfs_hash if not asset_dest_path.is_file(): if not first_two_bytes_dir.is_dir(): first_two_bytes_dir.mkdir() if not second_two_bytes_dir.is_dir(): second_two_bytes_dir.mkdir() if not third_two_bytes_dir.is_dir(): third_two_bytes_dir.mkdir() asset_dest_path.touch() asset_dest_path.write_bytes(resolve_uri_contents(uri)) logger.info("%s written to\n %s.\n", uri, asset_dest_path)
def gen_contract_types_and_sources( solc_output: Dict[str, Any], contracts_dir: Path) -> Tuple[Callable[..., Manifest], ...]: # todo: option to include additional sources not associated with included contract types ctypes_and_sources = get_contract_types_and_sources(solc_output) all_contract_types = [ctype for ctype, _ in ctypes_and_sources] pretty = "".join( format_contract_types_and_sources_for_display(ctypes_and_sources)) flag = parse_bool_flag( "\n" f"{len(all_contract_types)} contract types available.\n\n" f"{pretty}\n" "Would you like to automatically include all available contract types and their sources?" ) # get target contract types to include in manifest if flag: target_contract_types = all_contract_types else: while True: raw_included_ctypes = input( "Please list the contract types you would like to include, separated by commas: " ) target_contract_types = [ ct.strip(" ") for ct in raw_included_ctypes.split(",") ] invalid_contract_types = set(target_contract_types) - set( all_contract_types) if invalid_contract_types: cli_logger.info( f"Invalid contract type(s) selected: {invalid_contract_types}. " "Please try again.") else: break # get target sources associated with target contract types inline_source_flag = parse_bool_flag( "Would you like to inline source files? If not, sources will " "be automatically pinned to IPFS.") target_sources = set( flatten([ sources for ctype, sources in ctypes_and_sources if ctype in target_contract_types ])) target_source_names = tuple(src.stem for src in target_sources) # generate contract types and sources builder fns for manfiest builder generated_contract_types = build_contract_types(target_contract_types, solc_output) if inline_source_flag: generated_sources = build_inline_sources(target_source_names, solc_output, contracts_dir) else: generated_sources = build_pinned_sources(target_source_names, solc_output, contracts_dir) return ((*generated_contract_types), (*generated_sources))