squid_py.ocean.ocean_assets module

Ocean module.

class squid_py.ocean.ocean_assets.OceanAssets(keeper, did_resolver, agreements, asset_consumer, config)

Bases: object

Ocean assets class.

consume(service_agreement_id, did, service_index, consumer_account, destination, index=None)

Consume the asset data.

Using the service endpoint defined in the ddo’s service pointed to by service_definition_id. Consumer’s permissions is checked implicitly by the secret-store during decryption of the contentUrls. The service endpoint is expected to also verify the consumer’s permissions to consume this asset. This method downloads and saves the asset datafiles to disk.

Parameters
  • service_agreement_id – str

  • did – DID, str

  • service_index – identifier of the service inside the asset DDO, str

  • consumer_account – Account instance of the consumer

  • destination – str path

  • index – Index of the document that is going to be downloaded, int

Returns

str path to saved files

consumer_assets(consumer_address)

List of Asset objects purchased by consumerAddress

Parameters

consumer_address – ethereum address of consumer, hes-str

Returns

list of dids

create(metadata, publisher_account, service_descriptors=None, providers=None, use_secret_store=True, owner_address=None)

Register an asset in both the keeper’s DIDRegistry (on-chain) and in the Metadata store ( Aquarius).

Parameters
  • metadata – dict conforming to the Metadata accepted by Ocean Protocol.

  • publisher_account – Account of the publisher registering this asset

  • service_descriptors – list of ServiceDescriptor tuples of length 2. The first item must be one of ServiceTypes and the second item is a dict of parameters and values required by the service

  • providers – list of addresses of providers of this asset (a provider is an ethereum account that is authorized to provide asset services)

  • use_secret_store – bool indicate whether to use the secret store directly for encrypting urls (Uses Brizo provider service if set to False)

  • owner_address – hex str the ethereum address to assign asset ownership to. After registering the asset on-chain, the ownership is transferred to this address

Returns

DDO instance

get_permissions(did, address)

Gets access permission of a grantee

Parameters
  • did – the id of an asset on-chain, hex str

  • address – ethereum account address, hex str

Returns

true if the address has access permission to a DID

grant_permissions(did, address_to_grant, account)

Grant access permissions to an address.

Parameters
  • did – the id of an asset on-chain, hex str

  • address_to_grant – ethereum account address, hex str

  • account – Account executing the action

Returns

bool

order(did, index, consumer_account, provider_address=None, auto_consume=False)

Place order by directly creating an SEA (agreement) on-chain.

Parameters

did – str starting with the prefix did:op: and followed by the asset id which is

a hex str :param index: str the service definition id identifying a specific service in the DDO (DID document) :param consumer_account: Account instance of the consumer :param provider_address: ethereum account address of provider (optional) :param auto_consume: boolean :return: agreement_id the service agreement id (can be used to query

the keeper-contracts for the status of the service agreement)

owner(did)

Return the owner of the asset.

Parameters

did – DID, str

Returns

the ethereum address of the owner/publisher of given asset did, hex-str

owner_assets(owner_address)

List of Asset objects published by ownerAddress

Parameters

owner_address – ethereum address of owner/publisher, hex-str

Returns

list of dids

query(query, sort=None, offset=100, page=1, aquarius_url=None)

Search an asset in oceanDB using search query.

Parameters
Returns

List of assets that match with the query.

resolve(did)

When you pass a did retrieve the ddo associated.

Parameters

did – DID, str

Returns

DDO instance

retire(did)

Retire this did of Aquarius

Parameters

did – DID, str

Returns

bool

revoke_permissions(did, address_to_revoke, account)

Revoke access permission to an address.

Parameters
  • did – the id of an asset on-chain, hex str

  • address_to_revoke – ethereum account address, hex str

  • account – Account executing the action

Returns

bool

search(text, sort=None, offset=100, page=1, aquarius_url=None)

Search an asset in oceanDB using aquarius.

Parameters
  • text – String with the value that you are searching

  • sort – Dictionary to choose order main in some value

  • offset – Number of elements shows by page

  • page – Page number

  • aquarius_url – Url of the aquarius where you want to search. If there is not provided take the default

Returns

List of assets that match with the query

transfer_ownership(did, new_owner_address, account)

Transfer did ownership to an address.

Parameters
  • did – the id of an asset on-chain, hex str

  • new_owner_address – ethereum account address, hex str

  • account – Account executing the action

Returns

bool

validate(metadata)

Validate that the metadata is ok to be stored in aquarius.

Parameters

metadata – dict conforming to the Metadata accepted by Ocean Protocol.

Returns

bool