squid_py.ocean.ocean_agreements module

Ocean module.

class squid_py.ocean.ocean_agreements.OceanAgreements(keeper, asset_resolver, asset_consumer, config)

Bases: object

Ocean agreements class.

create(did, index, agreement_id, service_agreement_signature, consumer_address, account, provider_address=None, auto_consume=False)

Execute the service agreement on-chain using keeper’s ServiceAgreement contract.

The on-chain executeAgreement method requires the following arguments: templateId, signature, consumer, hashes, timeouts, serviceAgreementId, did. agreement_message_hash is necessary to verify the signature. The consumer signature includes the conditions timeouts and parameters values which is usedon-chain to verify that the values actually match the signed hashes.

Parameters
  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • index – str identifies the specific service in the ddo to use in this agreement.

  • agreement_id – 32 bytes identifier created by the consumer and will be used on-chain for the executed agreement.

  • service_agreement_signature – str the signed agreement message hash which includes conditions and their parameters values and other details of the agreement.

  • consumer_address – ethereum account address of consumer, hex str

  • account – Account instance creating the agreement. Can be either the consumer, publisher or provider

  • provider_address – ethereum account address of provider (optional)

  • auto_consume – bool

Returns

dict the executeAgreement transaction receipt

get(agreement_id)

Retrieve the agreement data of agreement_id.

Parameters

agreement_id – id of the agreement, hex str

Returns

AgreementValues instance – a namedtuple with the following attributes:

did, owner, template_id, condition_ids, updated_by, block_number_updated

is_access_granted(agreement_id, did, consumer_address)

Check permission for the agreement.

Verify on-chain that the consumer_address has permission to access the given asset did according to the agreement_id.

Parameters
  • agreement_id – id of the agreement, hex str

  • did – DID, str

  • consumer_address – ethereum account address of consumer, hex str

Returns

bool True if user has permission

static new()
prepare(did, consumer_account, service_index)
Parameters
  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • consumer_account – Account instance of the consumer

  • service_index – int identifies the specific service in the ddo to use in this agreement.

Returns

tuple (agreement_id: str, signature: hex str)

send(did, agreement_id, service_index, signature, consumer_account, auto_consume=False)

Send a signed service agreement to the publisher Brizo instance to consume/access the service.

Parameters
  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • agreement_id – 32 bytes identifier created by the consumer and will be used on-chain for the executed agreement.

  • service_index – int identifies the specific service in the ddo to use in this agreement.

  • signature – str the signed agreement message hash which includes conditions and their parameters values and other details of the agreement.

  • consumer_account – Account instance of the consumer

  • auto_consume – boolean tells this function wether to automatically trigger consuming the asset upon receiving access permission

Raises

OceanInitializeServiceAgreementError – on failure

Returns

bool

sign(agreement_id, did, consumer_account, service_index)

Sign a service agreement.

Parameters
  • agreement_id – 32 bytes identifier created by the consumer and will be used on-chain for the executed agreement.

  • did – str representation fo the asset DID. Use this to retrieve the asset DDO.

  • consumer_account – Account instance of the consumer

  • service_index – int identifies the specific service in the ddo to use in this agreement.

Returns

signature

status(agreement_id)

Get the status of a service agreement.

Parameters

agreement_id – id of the agreement, hex str

Returns

dict with condition status of each of the agreement’s conditions or None if the

agreement is invalid.