Memory Agent class

class starfish.agent.MemoryAgent(ddo: Optional[starfish.network.ddo.DDO] = None)

Bases: starfish.agent.agent_base.AgentBase

Memory Agent class allows to register, list, purchase and consume assets.

Parameters

ddo (DDO) – ddo to access the agent

consume_asset(listing: Any, account: Any, purchase_id: str) bool

Consume the asset and download the data. The actual payment to the asset provider will be made at this point.

Parameters
  • listing (Listing) – Listing that was used to make the purchase.

  • purchase_id (str) – purchase id that was used to purchase the asset.

  • account (Account object to use for registration.) – Ocean account that was used to purchase the asset.

Returns

True if the asset has been consumed and downloaded

Type

boolean

create_listing(listing_data: starfish.types.ListingData, asset_did: str) starfish.types.Listing

Create a listing on the market place for this asset

Parameters
  • listing_data (dict) – Listing inforamiton to give for this asset

  • asset_did (str) – asset DID to assign to this listing

Returns

A new Listing object that has been registered, if failure then return None.

Type

Listing class

get_asset_purchase_ids(asset: Any) Any

Returns as list of purchase id’s that have been used for this asset

Parameters

asset (DataAsset object) – DataAsset to return purchase details.

Returns

list of purchase ids

Type

list

get_listing(listing_id: str) starfish.types.Listing

Return an listing from the given listing_id.

Parameters

listing_id (str) – Id of the listing.

Returns

a registered listing given a Id of the listing

Type

Listing class

is_access_granted_for_asset(asset: Any, account: Any, purchase_id: Optional[str] = None) bool

Check to see if the account and purchase_id have access to the assed data.

Parameters
  • asset (Asset object) – Asset to check for access.

  • account (Account object to use for registration.) – Ocean account to purchase the asset.

  • purchase_id (str) – purchase id that was used to purchase the asset.

Returns

True if the asset can be accessed and consumed.

Type

boolean

purchase_asset(listing: Any, account: Any) Any

Purchase an asset using it’s listing and an account.

Parameters
  • listing (Listing) – Listing to use for the purchase.

  • account (Account object to use for registration.) – Ocean account to purchase the asset.

purchase_wait_for_completion(asset: Any, account: Any, purchase_id: str, timeoutSeconds: int) bool

Wait for completion of the purchase

TODO: issues here… + No method as yet to pass back paramaters and values during the purchase process + We assume that the following templates below will always be used.

register_asset(asset: starfish.types.Asset) starfish.types.Asset

Register a memory asset.

Parameters

metadata (object) – asset object to register for this asset.

Returns

A AssetBase object that has been registered, if failure then return None.

Type

AssetBase class

search_listings(text: str, sort: Optional[str] = None, offset: int = 100, page: int = 0) Any

Search for listings with the givien ‘text’

Parameters
  • text (str) – Text to search all listing data for.

  • sort (str or None) – sort the results ( defaults: None, no sort).

  • offset (int) – Return the result from with the maximum record count ( defaults: 100 ).

  • page (int) – Returns the page number based on the offset.

Returns

a list of listing objects found using the search.

Type

Listing objects

For example:

# return the 300 -> 399 records in the search for the text 'weather' in the metadata.
my_result = agent.search_registered_assets('weather', None, 100, 3)
update_listing(listing: starfish.types.Listing) None

Update the listing to the agent server.

Parameters

listing (Listing class) – Listing object to update

validate_asset(asset: starfish.types.Asset) bool

Validate an asset

Parameters

asset – Asset to validate.

Returns

True if the asset is valid