コード例 #1
0
def test_did():
    """Tests various DID functions."""
    assert DID.did({"0": "0x123"}).startswith(OCEAN_PREFIX)
    assert len(DID.did({"0": "0x123"})) - len(OCEAN_PREFIX) == 64
    _id = did_to_id(DID.did({"0": "0x123"}))
    assert not _id.startswith(
        "0x"), "id portion of did should not have a 0x prefix."
コード例 #2
0
 def _get_num_assets(_minter):
     dids = [
         add_0x_prefix(did_to_id(a))
         for a in ocn.assets.owner_assets(_minter)
     ]
     dids = [a for a in dids if len(a) == 42]
     return len([
         a for a in dids
         if DataToken(ocn.web3, a).contract.caller.isMinter(_minter)
     ])
コード例 #3
0
    def pay_for_service(
        web3: Web3,
        amount: int,
        token_address: str,
        did: str,
        service_id: int,
        fee_receiver: str,
        from_wallet: Wallet,
        consumer: str,
    ) -> str:
        """
        Submits the payment for chosen service in DataTokens.

        :param amount:
        :param token_address:
        :param did:
        :param service_id:
        :param fee_receiver:
        :param from_wallet: Wallet instance
        :param consumer: str the address of consumer of the service
        :return: hex str id of transfer transaction
        """
        dt = DataToken(web3, token_address)
        balance = dt.balanceOf(from_wallet.address)
        if balance < amount:
            raise InsufficientBalance(
                f"Your token balance {pretty_ether_and_wei(balance, dt.symbol())} is not sufficient "
                f"to execute the requested service. This service "
                f"requires {pretty_ether_and_wei(amount, dt.symbol())}."
            )

        if did.startswith("did:"):
            did = add_0x_prefix(did_to_id(did))

        if fee_receiver is None:
            fee_receiver = ZERO_ADDRESS

        tx_hash = dt.startOrder(consumer, amount, service_id, fee_receiver, from_wallet)

        try:
            dt.verify_order_tx(tx_hash, did, service_id, amount, from_wallet.address)
            return tx_hash
        except (AssertionError, Exception) as e:
            msg = (
                f"Downloading asset files failed. The problem is related to "
                f"the transfer of the data tokens required for the download "
                f"service: {e}"
            )
            logger.error(msg)
            raise AssertionError(msg)
コード例 #4
0
def test_did_to_id():
    """Tests did to id conversion."""
    did = DID.did({"0": "0x123"})
    _id = did_to_id(did)
    assert _id is not None and len(_id) == 64, ""

    test_id = "%s" % secrets.token_hex(32)
    assert did_to_id(f"{OCEAN_PREFIX}{test_id}") == test_id
    assert did_to_id("did:op1:011") == "011"
    assert did_to_id("did:op:0") == "0"
    with pytest.raises(ValueError):
        did_to_id(OCEAN_PREFIX)

    assert did_to_id(f"{OCEAN_PREFIX}AB*&$#") == "AB", ""
コード例 #5
0
ファイル: asset.py プロジェクト: oceanprotocol/ocean.py
 def asset_id(self) -> Optional[str]:
     """The asset id part of the DID"""
     if not self.did:
         return None
     return add_0x_prefix(did_to_id(self.did))