コード例 #1
0
ファイル: job.py プロジェクト: bxabi/hmt-escrow
    def _init_factory(self,
                      factory_addr: Optional[str],
                      credentials: Dict[str, str],
                      gas: int = GAS_LIMIT) -> Contract:
        """Takes an optional factory address and returns its contract representation. Alternatively
        a new factory is created.

        Initializing a new Job instance without a factory address succeeds.
        >>> credentials = {
        ... 	"gas_payer": "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
        ... 	"gas_payer_priv": "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        ... }
        >>> job = Job(credentials, manifest)
        >>> type(job.factory_contract)
        <class 'web3.utils.datatypes.Contract'>

        Initializing a new Job instance with a factory address succeeds.
        >>> factory_addr = deploy_factory(**credentials)
        >>> job = Job(credentials, manifest, factory_addr)
        >>> job.factory_contract.address == factory_addr
        True

        Args:
            credentials (Dict[str, str]): a dict of an ethereum address and its private key.
            factory_addr (Optional[str]): an ethereum address of the escrow factory contract.
            gas (int): maximum amount of gas the caller is ready to pay.

        Returns:
            bool: returns a factory contract.

        """
        factory_addr_valid = Web3.isChecksumAddress(factory_addr)
        factory = None

        if not factory_addr_valid:
            factory_addr = deploy_factory(GAS_LIMIT, **credentials)
            factory = get_factory(factory_addr)
            if not factory_addr:
                raise Exception("Unable to get address from factory")

        if not factory:
            factory = get_factory(factory_addr)
        return factory
コード例 #2
0
ファイル: job.py プロジェクト: bxabi/hmt-escrow
    def _factory_contains_escrow(self,
                                 escrow_addr: str,
                                 factory_addr: str,
                                 gas: int = GAS_LIMIT) -> bool:
        """Checks whether a given factory address contains a given escrow address.

        >>> credentials = {
        ... 	"gas_payer": "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
        ... 	"gas_payer_priv": "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5",
        ...     "rep_oracle_priv_key": b"28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        ... }
        >>> rep_oracle_pub_key = b"2dbc2c2c86052702e7c219339514b2e8bd4687ba1236c478ad41b43330b08488c12c8c1797aa181f3a4596a1bd8a0c18344ea44d6655f61fa73e56e743f79e0d"
        >>> job = Job(credentials, manifest)
        >>> job.launch(rep_oracle_pub_key)
        True
        >>> job.setup()
        True

        Factory contains the escrow address.
        >>> factory_addr = job.factory_contract.address
        >>> escrow_addr = job.job_contract.address
        >>> new_job = Job(credentials=credentials, factory_addr=factory_addr, escrow_addr=escrow_addr)
        >>> new_job._factory_contains_escrow(escrow_addr, factory_addr)
        True

        Args:
            factory_addr (str): an ethereum address of the escrow factory contract.
            escrow_addr (str): an ethereum address of the escrow contract.
            gas_payer (str): an ethereum address calling the contract.
            gas (int): maximum amount of gas the caller is ready to pay.

        Returns:
            bool: returns True escrow belongs to the factory.

        """
        factory_contract = get_factory(factory_addr)
        return factory_contract.functions.hasEscrow(escrow_addr).call({
            'from':
            self.gas_payer,
            'gas':
            gas
        })
コード例 #3
0
ファイル: job.py プロジェクト: bxabi/hmt-escrow
    def _access_job(self, factory_addr: str, escrow_addr: str, **credentials):
        """Given a factory and escrow address and credentials, access an already
        launched manifest of an already deployed escrow contract.

        Args:
            factory_addr (str): an ethereum address of the escrow factory contract.
            escrow_addr (str): an ethereum address of the escrow contract.
            **credentials: an unpacked dict of an ethereum address and its private key.

        """
        gas_payer = credentials["gas_payer"]
        rep_oracle_priv_key = credentials["rep_oracle_priv_key"]

        self.factory_contract = get_factory(factory_addr)
        self.job_contract = get_escrow(escrow_addr)
        self.manifest_url = manifest_url(self.job_contract, gas_payer)
        self.manifest_hash = manifest_hash(self.job_contract, gas_payer)

        manifest_dict = self.manifest(rep_oracle_priv_key)
        escrow_manifest = Manifest(manifest_dict)
        self._init_job(escrow_manifest)
コード例 #4
0
 def test_get_factory(self):
     self.assertIsNotNone(get_factory(self.job.factory_contract.address))