Exemple #1
0
    def deployments(self) -> Union["Deployments", Dict[None, None]]:
        """
        API to retrieve package deployments available on the current w3-connected chain.
        Cached property (self.deployments) gets busted everytime self.set_default_w3() is called.
        """
        if not check_for_deployments(self.manifest):
            return {}

        all_blockchain_uris = self.manifest["deployments"].keys()
        matching_uri = validate_single_matching_uri(all_blockchain_uris,
                                                    self.w3)

        deployments = self.manifest["deployments"][matching_uri]
        all_contract_factories = {
            deployment_data["contract_type"]:
            self.get_contract_factory(deployment_data["contract_type"])
            for deployment_data in deployments.values()
        }
        validate_deployments_tx_receipt(deployments, self.w3)
        linked_deployments = get_linked_deployments(deployments)
        if linked_deployments:
            for deployment_data in linked_deployments.values():
                on_chain_bytecode = self.w3.eth.getCode(
                    to_canonical_address(deployment_data["address"]))
                unresolved_linked_refs = normalize_linked_references(
                    deployment_data["runtime_bytecode"]["link_dependencies"])
                resolved_linked_refs = tuple(
                    self._resolve_linked_references(link_ref, deployments)
                    for link_ref in unresolved_linked_refs)
                for linked_ref in resolved_linked_refs:
                    validate_linked_references(linked_ref, on_chain_bytecode)

        return Deployments(deployments, all_contract_factories, self.w3)
Exemple #2
0
    def deployments(self) -> Union["Deployments", Dict[None, None]]:
        """
        Returns a ``Deployments`` object containing all the deployment data and contract
        factories of a ``Package``'s `contract_types`. Automatically filters deployments
        to only expose those available on the current ``Package.w3`` instance.

        .. code:: python

           package.deployments.get_instance("ContractType")
        """
        if not check_for_deployments(self.manifest):
            return {}

        all_blockchain_uris = self.manifest["deployments"].keys()
        matching_uri = validate_single_matching_uri(all_blockchain_uris, self.w3)

        deployments = self.manifest["deployments"][matching_uri]
        all_contract_factories = {
            deployment_data["contract_type"]: self.get_contract_factory(
                deployment_data["contract_type"]
            )
            for deployment_data in deployments.values()
        }
        validate_deployments_tx_receipt(deployments, self.w3, allow_missing_data=True)
        linked_deployments = get_linked_deployments(deployments)
        if linked_deployments:
            for deployment_data in linked_deployments.values():
                on_chain_bytecode = self.w3.eth.getCode(
                    to_canonical_address(deployment_data["address"])
                )
                unresolved_linked_refs = normalize_linked_references(
                    deployment_data["runtime_bytecode"]["link_dependencies"]
                )
                resolved_linked_refs = tuple(
                    self._resolve_linked_references(link_ref, deployments)
                    for link_ref in unresolved_linked_refs
                )
                for linked_ref in resolved_linked_refs:
                    validate_linked_references(linked_ref, on_chain_bytecode)

        return Deployments(deployments, all_contract_factories, self.w3)
Exemple #3
0
    def get_deployments(self, w3: Web3 = None) -> 'Deployments':
        """
        API to retrieve instance of deployed contract dependency.
        """
        if w3 is None:
            w3 = self.w3

        validate_w3_instance(w3)
        validate_deployments_are_present(self.package_data)

        all_blockchain_uris = self.package_data["deployments"].keys()
        matching_uri = validate_single_matching_uri(all_blockchain_uris, w3)

        deployments = self.package_data["deployments"][matching_uri]
        all_contract_factories = {
            deployment_data['contract_type']:
            self.get_contract_type(deployment_data['contract_type'], w3)
            for deployment_data in deployments.values()
        }

        return Deployments(deployments, all_contract_factories, w3)
Exemple #4
0
def invalid_deployment(w3):
    return Deployments(DEPLOYMENT_DATA, INVALID_CONTRACT_TYPES, w3)
Exemple #5
0
def deployment(w3):
    return Deployments(DEPLOYMENT_DATA, VALID_CONTRACT_TYPES, w3)