def build_etherscan_manifest(uri: URI, package_name: str, version: str) -> Iterable[Tuple[str, Any]]: address, chain_id = parse.urlparse(uri).netloc.split(":") network = get_etherscan_network(chain_id) body = make_etherscan_request(address, network) contract_type = body["ContractName"] w3 = setup_w3(to_int(text=chain_id)) block_uri = create_latest_block_uri(w3) runtime_bytecode = to_hex( w3.eth.getCode(ChecksumAddress(HexAddress(HexStr(address))))) yield "package_name", package_name yield "version", version yield "manifest_version", "2" yield "sources", {f"./{contract_type}.sol": body["SourceCode"]} yield "contract_types", { contract_type: { "abi": json.loads(body["ABI"]), "runtime_bytecode": { "bytecode": runtime_bytecode }, "compiler": generate_compiler_info(body), } } yield "deployments", { block_uri: { contract_type: { "contract_type": contract_type, "address": address } } }
def release_package(package_name: str, version: str, manifest_uri: URI, config: Config) -> bytes: if not config.private_key: raise AuthorizationError( "To release a package you must provide the password for your local keyfile." ) registry_store_path = config.xdg_ethpmcli_root / REGISTRY_STORE active_registry = get_active_registry(registry_store_path) parsed_uri = parse_registry_uri(active_registry.uri) if config.w3.net.version != parsed_uri.chain_id: w3 = setup_w3(to_int(text=parsed_uri.chain_id), config.private_key) else: w3 = config.w3 w3.pm.set_registry(parsed_uri.address) release_id = w3.pm.release_package(package_name, version, manifest_uri) return release_id
def gen_single_deployment(solc_output: Dict[str, Any]) -> Dict[str, Any]: chain_id = get_chain_id() w3 = setup_w3(chain_id) block_uri = create_latest_block_uri(w3) address = get_deployment_address() available_contract_types = get_contract_types(solc_output) contract_type = get_deployment_contract_type(available_contract_types) contract_instance = get_deployment_alias(contract_type) tx_hash, block_hash = get_deployment_chain_data(w3) deployment_data = { "block_uri": block_uri, "contract_instance": contract_instance, "contract_type": contract_type, "address": address, "transaction": tx_hash, "block": block_hash, } return {field: value for field, value in deployment_data.items() if value}
def gen_single_deployment(solc_output: Dict[str, Any]) -> Dict[str, Any]: chain_id = get_chain_id() w3 = setup_w3(chain_id) block_uri = create_latest_block_uri(w3) address = get_deployment_address() contract_type = get_deployment_contract_type(solc_output) # todo: support custom contract instance definitions contract_instance = contract_type tx_hash, block_hash = get_deployment_chain_data(w3) deployment_data = { "block_uri": block_uri, "contract_instance": contract_instance, "contract_type": contract_type, "address": address, "transaction": tx_hash, "block": block_hash, } return {field: value for field, value in deployment_data.items() if value}
def amend_single_deployment(manifest: Dict[str, Any]) -> Iterable[Dict[str, Any]]: chain_id = get_chain_id() w3 = setup_w3(chain_id) block_uri = create_latest_block_uri(w3) address = get_deployment_address() available_contract_types = manifest["contractTypes"].keys() contract_type = get_deployment_contract_type(available_contract_types) contract_instance = get_deployment_alias(contract_type) tx_hash, block_hash = get_deployment_chain_data(w3) deployment_data = { "block_uri": block_uri, "contract_instance": contract_instance, "contract_type": contract_type, "address": address, "transaction": tx_hash, "block": block_hash, } yield {field: value for field, value in deployment_data.items() if value}
def get_matching_w3(chain_uri: URI, config: Config) -> Tuple[Web3, str]: genesis_hash = parse_BIP122_uri(chain_uri)[0] chain_data = SUPPORTED_GENESIS_HASHES[genesis_hash] web3 = setup_w3(chain_data[1], config.private_key) return web3, chain_data[0]
def get_w3s(config: Config) -> Iterable[Tuple[str, Web3]]: all_chain_data = [data for data in SUPPORTED_GENESIS_HASHES.values()] for name, chain_id in all_chain_data: w3 = setup_w3(chain_id, config.private_key) yield f"{name}_w3", w3
def get_w3s(config): all_chain_data = [data for data in SUPPORTED_GENESIS_HASHES.values()] for name, chain_id in all_chain_data: w3 = setup_w3(chain_id, config.private_key) yield f"{name}_w3", w3