コード例 #1
0
 def deploy_new_instance(cls, w3: Web3) -> 'SimpleRegistry':
     manifest = get_simple_registry_manifest()
     registry_package = Package(manifest, w3)
     registry_factory = registry_package.get_contract_factory(ContractName("PackageRegistry"))
     tx_hash = registry_factory.constructor().transact()
     tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
     return cls(tx_receipt["contractAddress"], w3)
コード例 #2
0
def _deploy(
    contract_name: str, args: Any, transaction: Dict[str, Any], package: Package
) -> Tuple[Package, Address]:
    # Deploy new instance
    factory = package.get_contract_factory(contract_name)
    if not factory.linked_references and factory.unlinked_references:
        raise LinkerError(
            f"Contract factory: {contract_name} is missing runtime link references, which are "
            "necessary to populate manifest deployments that have a link reference. If using the "
            "builder tool, use `contract_type(..., runtime_bytecode=True)`."
        )
    tx_hash = factory.constructor(*args).transact(transaction)
    tx_receipt = package.w3.eth.waitForTransactionReceipt(tx_hash)
    # Create manifest copy with new deployment instance
    latest_block_uri = create_latest_block_uri(package.w3, 0)
    deployment_data = create_deployment_data(
        contract_name,
        to_checksum_address(tx_receipt.contractAddress),
        tx_receipt,
        factory.linked_references,
    )
    manifest = insert_deployment(
        package, contract_name, deployment_data, latest_block_uri
    )
    logger.info("%s deployed." % contract_name)
    return Package(manifest, package.w3)
コード例 #3
0
 def deploy_new_instance(cls, w3):
     manifest = get_simple_registry_manifest()
     registry_package = Package(manifest, w3)
     registry_factory = registry_package.get_contract_factory("PackageRegistry")
     tx_hash = registry_factory.constructor().transact()
     tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
     return cls(tx_receipt.contractAddress, w3)
コード例 #4
0
 def _get_factory(package, factory_name):
     manifest = get_manifest(package)
     # Special case to fetch escrow manifest with added deployment bytecode
     if package == "escrow":
         manifest = escrow_manifest
     Pkg = Package(manifest, w3)
     factory = Pkg.get_contract_factory(factory_name)
     return factory
コード例 #5
0
def test_linkable_contract_class_handles_missing_link_refs(get_manifest, w3):
    safe_math_manifest = get_manifest("safe-math-lib")
    SafeMathLib = Package(safe_math_manifest, w3)
    safe_math_lib = SafeMathLib.get_contract_factory("SafeMathLib")
    assert safe_math_lib.needs_bytecode_linking is False
    with pytest.raises(BytecodeLinkingError):
        safe_math_lib.link_bytecode(
            {"SafeMathLib": "0xa66A05D6AB5c1c955F4D2c3FCC166AE6300b452B"})
コード例 #6
0
ファイル: activate.py プロジェクト: corydickson/ethpm-cli
def generate_contract_factories(pkg: ethpmPackage):
    for ctype in pkg.contract_types:
        try:
            factory = pkg.get_contract_factory(ctype)
            yield f"{ctype}_factory", factory
        except InsufficientAssetsError:
            cli_logger.info(
                f"Insufficient assets to generate factory for {ctype} "
                "(requires ABI & deployment_bytecode).")
コード例 #7
0
 def deploy_new_instance(cls, w3: Web3) -> "VyperReferenceRegistry":
     """
     Returns a new instance of ```VyperReferenceRegistry`` representing a freshly deployed
     instance on the given ``web3`` instance of the Vyper Reference Registry implementation.
     """
     manifest = get_vyper_registry_manifest()
     registry_package = Package(manifest, w3)
     registry_factory = registry_package.get_contract_factory("registry")
     tx_hash = registry_factory.constructor().transact()
     tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
     return cls(tx_receipt.contractAddress, w3)
コード例 #8
0
def test_deployed_escrow_and_safe_send(escrow_manifest, w3):
    # Deploy a SafeSendLib
    safe_send_manifest = json.loads(
        (ASSETS_DIR / "escrow" / "1.0.3.json").read_text())
    safe_send_contract_type = safe_send_manifest["contract_types"][
        "SafeSendLib"]
    SafeSend = w3.eth.contract(
        abi=safe_send_contract_type["abi"],
        bytecode=safe_send_contract_type["deployment_bytecode"]["bytecode"],
    )
    tx_hash = SafeSend.constructor().transact()
    tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
    safe_send_address = to_canonical_address(tx_receipt["contractAddress"])

    EscrowPackage = Package(escrow_manifest, w3)
    EscrowFactory = EscrowPackage.get_contract_factory("Escrow")
    LinkedEscrowFactory = EscrowFactory.link_bytecode(
        {"SafeSendLib": safe_send_address})

    # Deploy an Escrow Contract
    escrow_tx_hash = LinkedEscrowFactory.constructor(
        "0x4F5B11c860b37b68DE6D14Fb7e7b5f18A9A1bdC0").transact()
    escrow_tx_receipt = w3.eth.waitForTransactionReceipt(escrow_tx_hash)
    escrow_address = to_canonical_address(escrow_tx_receipt.contractAddress)

    # Cannot deploy with an unlinked factory
    with pytest.raises(BytecodeLinkingError):
        escrow_tx_hash = EscrowFactory.constructor(
            "0x4F5B11c860b37b68DE6D14Fb7e7b5f18A9A1bdC0").transact()

    # Cannot instantiate a contract instance from an unlinked factory
    with pytest.raises(BytecodeLinkingError):
        EscrowFactory(escrow_address)
    contract_instance = LinkedEscrowFactory(escrow_address)
    assert EscrowFactory.needs_bytecode_linking is True
    assert LinkedEscrowFactory.needs_bytecode_linking is False
    assert isinstance(contract_instance, web3.contract.Contract)
    assert to_canonical_address(
        safe_send_address) in LinkedEscrowFactory.bytecode
    assert (to_canonical_address(safe_send_address)
            in LinkedEscrowFactory.bytecode_runtime)
    assert to_canonical_address(
        safe_send_address) not in EscrowFactory.bytecode
    assert to_canonical_address(
        safe_send_address) not in EscrowFactory.bytecode_runtime
コード例 #9
0
def link(contract: str, linked_type: str, package: Package) -> Package:
    """
    Return a new package, created with a new manifest after applying the linked type
    reference to the contract factory.
    """
    deployment_address = get_deployment_address(linked_type, package)
    unlinked_factory = package.get_contract_factory(contract)
    if not unlinked_factory.needs_bytecode_linking:
        raise LinkerError(
            f"Contract factory: {unlinked_factory.__repr__()} does not need bytecode linking, "
            "so it is not a valid contract type for link()")
    linked_factory = unlinked_factory.link_bytecode(
        {linked_type: deployment_address})
    # todo replace runtime_bytecode in manifest
    manifest = assoc_in(
        package.manifest,
        ("contract_types", contract, "deployment_bytecode", "bytecode"),
        to_hex(linked_factory.bytecode),
    )
    logger.info(
        "%s linked to %s at address %s." %
        (contract, linked_type, to_checksum_address(deployment_address)))
    return Package(manifest, package.w3)