Ocean Instance Tech Details

Technical details about most used ocean.py functions

At the beginning of most flows, we create an ocean object, which is an instance of class Ocean. It exposes useful information, including the following:

  • properties for config & OCEAN

  • contract objects retrieval

  • users' orders

  • provider fees

Constructor

  • __init__(self, config_dict: Dict, data_provider: Optional[Type] = None)

The Ocean class is the entry point into Ocean Procol.

In order to initialize a Ocean object, you must provide config_dict which is a Dictionary instance and optionally a DataServiceProvider instance.

Parameters

  • config_dict: dict which is mandatory and it contains the configuration as dictionary format.

  • data_provider: Optional[DataProvider] which is optional with a default value of None. If it is not provided, the constructor will instantiate a new one from scratch.

Returns

None

Defined in

ocean/ocean.py

Source code
class Ocean:
    """The Ocean class is the entry point into Ocean Protocol."""

    @enforce_types
    def __init__(self, config_dict: Dict, data_provider: Optional[Type] = None) -> None:
        """Initialize Ocean class.

        Usage: Make a new Ocean instance

        `ocean = Ocean({...})`

        This class provides the main top-level functions in ocean protocol:
        1. Publish assets metadata and associated services
            - Each asset is assigned a unique DID and a DID Document (DDO)
            - The DDO contains the asset's services including the metadata
            - The DID is registered on-chain with a URL of the metadata store
              to retrieve the DDO from

            `ddo = ocean.assets.create(metadata, publisher_wallet)`

        2. Discover/Search ddos via the current configured metadata store (Aquarius)

            - Usage:
            `ddos_list = ocean.assets.search('search text')`

        An instance of Ocean is parameterized by a `Config` instance.

        :param config_dict: variable definitions
        :param data_provider: `DataServiceProvider` instance
        """
        config_errors = {}
        for key, value in config_defaults.items():
            if key not in config_dict:
                config_errors[key] = "required"
                continue

            if not isinstance(config_dict[key], type(value)):
                config_errors[key] = f"must be {type(value).__name__}"

        if config_errors:
            raise Exception(json.dumps(config_errors))

        self.config_dict = config_dict

        network_name = config_dict["NETWORK_NAME"]
        check_network(network_name)

        if not data_provider:
            data_provider = DataServiceProvider

        self.assets = OceanAssets(self.config_dict, data_provider)
        self.compute = OceanCompute(self.config_dict, data_provider)

        logger.debug("Ocean instance initialized: ")

Config Getter

  • config(self) -> dict

It is a helper method for retrieving the user's configuration for ocean.py. It can be called only by Ocean object and returns a python dictionary.

Returns

dict

Configuration fields as dictionary.

Defined in

ocean/ocean.py

Source code

OCEAN Address

  • ocean_address(self) -> str

It is a helper method for retrieving the OCEAN's token address. It can be called only by Ocean object and returns the address as a string.

Returns

str

OCEAN address for that network.

Defined in

ocean/ocean.py

Source code

get_ocean_token_address function is an utilitary function which gets the address from address.json file

OCEAN Token Object

  • ocean_token(self) -> DatatokenBase

  • OCEAN(self) -> DatatokenBase as alias for the above option

It is a helper method for retrieving the OCEAN token object (Datatoken class). It can be called within Ocean class and returns the OCEAN Datatoken.

Returns

DatatokenBase

OCEAN token as DatatokenBase object.

Defined in

ocean/ocean.py

Source code

Data NFT Factory

  • data_nft_factory(self) -> DataNFTFactoryContract

It is a property for getting Data NFT Factory object for the singleton smart contract. It can be called within Ocean class and returns the DataNFTFactoryContract instance.

Returns

DataNFTFactoryContract

Data NFT Factory contract object which access all the functionalities available from smart contracts in Python.

Defined in

ocean/ocean.py

Source code

Dispenser

  • dispenser(self) -> Dispenser

Dispenser is represented by a faucet for free data. It is a property for getting Dispenser object for the singleton smart contract. It can be called within Ocean class and returns the Dispenser instance.

Returns

Dispenser

Dispenser contract object which access all the functionalities available from smart contracts in Python.

Defined in

ocean/ocean.py

Source code

Fixed Rate Exchange

  • fixed_rate_exchange(self) -> FixedRateExchange

Exchange is used for priced data. It is a property for getting FixedRateExchange object for the singleton smart contract. It can be called within Ocean class and returns the FixedRateExchange instance.

Returns

FixedRateExchange

Fixed Rate Exchange contract object which access all the functionalities available from smart contracts in Python.

Defined in

ocean/ocean.py

Source code

NFT Token Getter

  • get_nft_token(self, token_adress: str) -> DataNFT

It is a getter for a specific data NFT object based on its checksumed address. It can be called within Ocean class which returns the DataNFT instance based on string token_address specified as parameter.

Parameters

  • token_address - string checksumed address of the NFT token that you are searching for.

Returns

DataNFT

Data NFT object which access all the functionalities available for ERC721 template in Python.

Defined in

ocean/ocean.py

Source code

Datatoken Getter

  • get_datatoken(self, token_address: str) -> DatatokenBase

It is a getter for a specific datatoken object based on its checksumed address. It can be called within Ocean class with a string token_address as parameter which returns the DatatokenBase instance depending on datatoken's template index.

Parameters

  • token_address - string checksumed address of the datatoken that you are searching for.

Returns

DatatokenBase

Datatoken object which access all the functionalities available for ERC20 templates in Python.

Defined in

ocean/ocean.py

Source code

User Orders Getter

  • get_user_orders(self, address: str, datatoken: str) -> List[AttributeDict]

Returns the list of orders that were made by a certain user on a specific datatoken.

It can be called within Ocean class.

Parameters

  • address - wallet address of that user

  • datatoken - datatoken address

Returns

List[AttributeDict]

List of all the orders on that datatoken done by the specified user.

Defined in

ocean/ocean.py

Source code

Provider Fees

  • retrieve_provider_fees( self, ddo: DDO, access_service: Service, publisher_wallet ) -> dict

Calls Provider to compute provider fees as dictionary for access service.

Parameters

  • ddo - the data asset which has the DDO object

  • access_service - Service instance for the service that needs the provider fees

  • publisher_wallet - Wallet instance of the user that wants to retrieve the provider fees

Returns

dict

A dictionary which contains the following keys (providerFeeAddress, providerFeeToken, providerFeeAmount, providerData, v, r, s, validUntil).

Defined in

ocean/ocean.py

Source code

Compute Provider Fees

  • retrieve_provider_fees_for_compute(self, datasets: List[ComputeInput], algorithm_data: Union[ComputeInput, AlgorithmMetadata], consumer_address: str, compute_environment: str, valid_until: int) -> dict

Calls Provider to generate provider fees as dictionary for compute service.

Parameters

  • datasets - list of ComputeInput which contains the data assets

  • algorithm_data - necessary data for algorithm and it can be either a ComputeInput object, either just the algorithm metadata, AlgorithmMetadata

  • consumer_address - address of the compute consumer wallet which is requesting the provider fees

  • compute_environment - id provided from the compute environment as string

  • valid_until - timestamp in UNIX miliseconds for the duration of provider fees for the compute service.

Returns

dict

A dictionary which contains the following keys (providerFeeAddress, providerFeeToken, providerFeeAmount, providerData, v, r, s, validUntil).

Defined in

ocean/ocean.py

Source code

Last updated

Was this helpful?