Search is not available for this dataset
text stringlengths 75 104k |
|---|
def create(self, metadata, publisher_account,
service_descriptors=None, providers=None,
use_secret_store=True):
"""
Register an asset in both the keeper's DIDRegistry (on-chain) and in the Metadata store (
Aquarius).
:param metadata: dict conforming to the ... |
def retire(self, did):
"""
Retire this did of Aquarius
:param did: DID, str
:return: bool
"""
try:
ddo = self.resolve(did)
metadata_service = ddo.find_service_by_type(ServiceTypes.METADATA)
self._get_aquarius(metadata_service.endpoints... |
def search(self, text, sort=None, offset=100, page=1, aquarius_url=None):
"""
Search an asset in oceanDB using aquarius.
:param text: String with the value that you are searching
:param sort: Dictionary to choose order base in some value
:param offset: Number of elements shows b... |
def query(self, query, sort=None, offset=100, page=1, aquarius_url=None):
"""
Search an asset in oceanDB using search query.
:param query: dict with query parameters
(e.g.) https://github.com/oceanprotocol/aquarius/blob/develop/docs/for_api_users/API.md
:param sort: Dictiona... |
def order(self, did, service_definition_id, consumer_account, auto_consume=False):
"""
Sign service agreement.
Sign the service agreement defined in the service section identified
by `service_definition_id` in the ddo and send the signed agreement to the purchase endpoint
associ... |
def consume(self, service_agreement_id, did, service_definition_id, 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 impl... |
def propose(self, template_address, account):
"""
Propose a new template.
:param template_address: Address of the template contract, str
:param account: account proposing the template, Account
:return: bool
"""
try:
proposed = self._keeper.template_ma... |
def approve(self, template_address, account):
"""
Approve a template already proposed. The account needs to be owner of the templateManager
contract to be able of approve the template.
:param template_address: Address of the template contract, str
:param account: account approvi... |
def revoke(self, template_address, account):
"""
Revoke a template already approved. The account needs to be owner of the templateManager
contract to be able of revoke the template.
:param template_address: Address of the template contract, str
:param account: account revoking t... |
def get_price(self):
"""
Return the price from the conditions parameters.
:return: Int
"""
for cond in self.conditions:
for p in cond.parameters:
if p.name == '_amount':
return p.value |
def get_service_agreement_hash(
self, agreement_id, asset_id, consumer_address, publisher_address, keeper):
"""Return the hash of the service agreement values to be signed by a consumer.
:param agreement_id:id of the agreement, hex str
:param asset_id:
:param consumer_addres... |
def keeper_path(self):
"""Path where the keeper-contracts artifacts are allocated."""
keeper_path_string = self.get(self._section_name, NAME_KEEPER_PATH)
path = Path(keeper_path_string).expanduser().resolve()
# TODO: Handle the default case and make default empty string
# assert ... |
def add_public_key(self, did, public_key):
"""
Add a public key object to the list of public keys.
:param public_key: Public key, PublicKeyHex
"""
logger.debug(f'Adding public key {public_key} to the did {did}')
self._public_keys.append(
PublicKeyBase(did, **... |
def add_authentication(self, public_key, authentication_type=None):
"""
Add a authentication public key id and type to the list of authentications.
:param key_id: Key id, Authentication
:param authentication_type: Authentication type, str
"""
authentication = {}
... |
def add_service(self, service_type, service_endpoint=None, values=None):
"""
Add a service to the list of services on the DDO.
:param service_type: Service
:param service_endpoint: Service endpoint, str
:param values: Python dict with serviceDefinitionId, templateId, serviceAgre... |
def as_text(self, is_proof=True, is_pretty=False):
"""Return the DDO as a JSON text.
:param if is_proof: if False then do not include the 'proof' element.
:param is_pretty: If True return dictionary in a prettier way, bool
:return: str
"""
data = self.as_dictionary(is_pr... |
def as_dictionary(self, is_proof=True):
"""
Return the DDO as a JSON dict.
:param if is_proof: if False then do not include the 'proof' element.
:return: dict
"""
if self._created is None:
self._created = DDO._get_timestamp()
data = {
'@c... |
def _read_dict(self, dictionary):
"""Import a JSON dict into this DDO."""
values = dictionary
self._did = values['id']
self._created = values.get('created', None)
if 'publicKey' in values:
self._public_keys = []
for value in values['publicKey']:
... |
def add_proof(self, text, publisher_account, keeper):
"""Add a proof to the DDO, based on the public_key id/index and signed with the private key
add a static proof to the DDO, based on one of the public keys."""
# just incase clear out the current static proof property
self._proof = No... |
def get_public_key(self, key_id, is_search_embedded=False):
"""Key_id can be a string, or int. If int then the index in the list of keys."""
if isinstance(key_id, int):
return self._public_keys[key_id]
for item in self._public_keys:
if item.get_id() == key_id:
... |
def _get_public_key_count(self):
"""Return the count of public keys in the list and embedded."""
index = len(self._public_keys)
for authentication in self._authentications:
if authentication.is_public_key():
index += 1
return index |
def _get_authentication_from_public_key_id(self, key_id):
"""Return the authentication based on it's id."""
for authentication in self._authentications:
if authentication.is_key_id(key_id):
return authentication
return None |
def get_service(self, service_type=None):
"""Return a service using."""
for service in self._services:
if service.type == service_type and service_type:
return service
return None |
def find_service_by_id(self, service_id):
"""
Get service for a given service_id.
:param service_id: Service id, str
:return: Service
"""
service_id_key = 'serviceDefinitionId'
service_id = str(service_id)
for service in self._services:
if ser... |
def find_service_by_type(self, service_type):
"""
Get service for a given service type.
:param service_type: Service type, ServiceType
:return: Service
"""
for service in self._services:
if service_type == service.type:
return service
... |
def create_public_key_from_json(values):
"""Create a public key object based on the values from the JSON record."""
# currently we only support RSA public keys
_id = values.get('id')
if not _id:
# Make it more forgiving for now.
_id = ''
# raise ValueE... |
def create_authentication_from_json(values):
"""Create authentitaciton object from a JSON string."""
key_id = values.get('publicKey')
authentication_type = values.get('type')
if not key_id:
raise ValueError(
f'Invalid authentication definition, "publicKey" is ... |
def generate_checksum(did, metadata):
"""
Generation of the hash for integrity checksum.
:param did: DID, str
:param metadata: conforming to the Metadata accepted by Ocean Protocol, dict
:return: hex str
"""
files_checksum = ''
for file in metadata['base'... |
def register(self, did, checksum, url, account, providers=None):
"""
Register or update a DID on the block chain using the DIDRegistry smart contract.
:param did: DID to register/update, can be a 32 byte or hexstring
:param checksum: hex str hash of TODO
:param url: URL of the r... |
def _register_attribute(self, did, checksum, value, account, providers):
"""Register an DID attribute as an event on the block chain.
:param did: 32 byte string/hex of the DID
:param checksum: checksum of the ddo, hex str
:param value: url for resolve the did, str
:param account... |
def remove_provider(self, did, provider_address, account):
"""
Remove a provider
:param did: the id of an asset on-chain, hex str
:param provider_address: ethereum account address of the provider, hex str
:param account: Account executing the action
:return:
"""
... |
def get_did_providers(self, did):
"""
Return the list providers registered on-chain for the given did.
:param did: hex str the id of an asset on-chain
:return:
list of addresses
None if asset has no registerd providers
"""
register_values = self.c... |
def get_owner_asset_ids(self, address):
"""
Get the list of assets owned by an address owner.
:param address: ethereum account address, hex str
:return:
"""
block_filter = self._get_event_filter(owner=address)
log_items = block_filter.get_all_entries(max_tries=5)... |
def set_encode_key_value(self, value, store_type=PUBLIC_KEY_STORE_TYPE_BASE64):
"""Set the value based on the type of encoding supported by RSA."""
if store_type == PUBLIC_KEY_STORE_TYPE_PEM:
PublicKeyBase.set_encode_key_value(self, value.exportKey('PEM').decode(), store_type)
else:
... |
def did_parse(did):
"""
Parse a DID into it's parts.
:param did: Asset did, str.
:return: Python dictionary with the method and the id.
"""
if not isinstance(did, str):
raise TypeError(f'Expecting DID of string type, got {did} of {type(did)} type')
match = re.match('^did:([a-z0-9]+... |
def id_to_did(did_id, method='op'):
"""Return an Ocean DID from given a hex id."""
if isinstance(did_id, bytes):
did_id = Web3.toHex(did_id)
# remove leading '0x' of a hex string
if isinstance(did_id, str):
did_id = remove_0x_prefix(did_id)
else:
raise TypeError("did id must... |
def did_to_id_bytes(did):
"""
Return an Ocean DID to it's correspondng hex id in bytes.
So did:op:<hex>, will return <hex> in byte format
"""
if isinstance(did, str):
if re.match('^[0x]?[0-9A-Za-z]+$', did):
raise ValueError(f'{did} must be a DID not a hex string')
else:... |
def get_template(self, template_id):
"""
Get the template for a given template id.
:param template_id: id of the template, str
:return:
"""
template = self.contract_concise.getTemplate(template_id)
if template and len(template) == 4:
return AgreementT... |
def propose_template(self, template_id, from_account):
"""Propose a template.
:param template_id: id of the template, str
:param from_account: Account
:return: bool
"""
tx_hash = self.send_transaction(
'proposeTemplate',
(template_id,),
... |
def access_service_descriptor(price, consume_endpoint, service_endpoint, timeout, template_id):
"""
Access service descriptor.
:param price: Asset price, int
:param consume_endpoint: url of the service provider, str
:param service_endpoint: identifier of the service inside the a... |
def compute_service_descriptor(price, consume_endpoint, service_endpoint, timeout):
"""
Compute service descriptor.
:param price: Asset price, int
:param consume_endpoint: url of the service provider, str
:param service_endpoint: identifier of the service inside the asset DDO, s... |
def build_services(did, service_descriptors):
"""
Build a list of services.
:param did: DID, str
:param service_descriptors: List of 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 serv... |
def build_service(service_descriptor, did):
"""
Build a service.
:param service_descriptor: 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
:param did: DID, str
:return: Service... |
def build_metadata_service(did, metadata, service_endpoint):
"""
Build a metadata service.
:param did: DID, str
:param metadata: conforming to the Metadata accepted by Ocean Protocol, dict
:param service_endpoint: identifier of the service inside the asset DDO, str
:retu... |
def build_access_service(did, price, consume_endpoint, service_endpoint, timeout, template_id):
"""
Build the access service.
:param did: DID, str
:param price: Asset price, int
:param consume_endpoint: url of the service provider, str
:param service_endpoint: identifier... |
def fulfill(self, agreement_id, reward_address, amount, account):
"""
Fulfill the lock reward condition.
:param agreement_id: id of the agreement, hex str
:param reward_address: ethereum account address, hex str
:param amount: Amount of tokens, int
:param account: Accoun... |
def record_service_agreement(storage_path, service_agreement_id, did, service_definition_id, price,
files, start_time,
status='pending'):
"""
Records the given pending service agreement.
:param storage_path: storage path for the internal db, str
... |
def update_service_agreement_status(storage_path, service_agreement_id, status='pending'):
"""
Update the service agreement status.
:param storage_path: storage path for the internal db, str
:param service_agreement_id:
:param status:
:return:
"""
conn = sqlite3.connect(storage_path)
... |
def get_service_agreements(storage_path, status='pending'):
"""
Get service agreements pending to be executed.
:param storage_path: storage path for the internal db, str
:param status:
:return:
"""
conn = sqlite3.connect(storage_path)
try:
cursor = conn.cursor()
return [... |
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'):
"""Logging setup."""
path = default_path
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
with open(path, 'rt') as file:
try:
con... |
def encrypt(self, document_id, content, account):
"""
Encrypt string data using the DID as an secret store id,
if secret store is enabled then return the result from secret store encryption
None for no encryption performed
:param document_id: hex str id of document to use for e... |
def decrypt(self, document_id, encrypted_content, account):
"""
Decrypt a previously encrypted content using the secret store keys identified
by document_id.
Note that decryption requires permission already granted to the consumer account.
:param document_id: hex str id of docu... |
def resolve(self, did):
"""
Resolve a DID to an URL/DDO or later an internal/external DID.
:param did: 32 byte value or DID string to resolver, this is part of the ocean
DID did:op:<32 byte value>
:return string: URL or DDO of the resolved DID
:return None: if the DI... |
def get_resolve_url(self, did_bytes):
"""Return a did value and value type from the block chain event record using 'did'.
:param did_bytes: DID, hex-str
:return url: Url, str
"""
data = self._did_registry.get_registered_attribute(did_bytes)
if not (data and data.get('val... |
def get_instance(cls, dependencies=None):
"""
Return an instance for a contract name.
:param dependencies:
:return: Contract base instance
"""
assert cls is not ContractBase, 'ContractBase is not meant to be used directly.'
assert cls.CONTRACT_NAME, 'CONTRACT_NAM... |
def get_tx_receipt(tx_hash):
"""
Get the receipt of a tx.
:param tx_hash: hash of the transaction
:return: Tx receipt
"""
try:
Web3Provider.get_web3().eth.waitForTransactionReceipt(tx_hash, timeout=20)
except Timeout:
logger.info('Waiting ... |
def subscribe_to_event(self, event_name, timeout, event_filter, callback=False,
timeout_callback=None, args=None, wait=False):
"""
Create a listener for the event choose.
:param event_name: name of the event to subscribe, str
:param timeout:
:param eve... |
def send_transaction(self, fn_name, fn_args, transact=None):
"""Calls a smart contract function using either `personal_sendTransaction` (if
passphrase is available) or `ether_sendTransaction`.
:param fn_name: str the smart contract function name
:param fn_args: tuple arguments to pass t... |
def refund_reward(event, agreement_id, did, service_agreement, price, consumer_account,
publisher_address, condition_ids):
"""
Refund the reward to the publisher address.
:param event: AttributeDict with the event data.
:param agreement_id: id of the agreement, hex str
:param did:... |
def consume_asset(event, agreement_id, did, service_agreement, consumer_account, consume_callback):
"""
Consumption of an asset after get the event call.
:param event: AttributeDict with the event data.
:param agreement_id: id of the agreement, hex str
:param did: DID, str
:param service_agreem... |
def verify_contracts():
"""
Verify that the contracts are deployed correctly in the network.
:raise Exception: raise exception if the contracts are not deployed correctly.
"""
artifacts_path = ConfigProvider.get_config().keeper_path
logger.info(f'Keeper contract artifact... |
def create_access_service(price, service_endpoint, consume_endpoint, timeout=None):
"""
Publish an asset with an `Access` service according to the supplied attributes.
:param price: Asset price, int
:param service_endpoint: str URL for initiating service access request
:param co... |
def fulfill_lock_reward_condition(event, agreement_id, price, consumer_account):
"""
Fulfill the lock reward condition.
:param event: AttributeDict with the event data.
:param agreement_id: id of the agreement, hex str
:param price: Asset price, int
:param consumer_account: Account instance of ... |
def lock_reward(self, agreement_id, amount, account):
"""
Lock reward condition.
:param agreement_id: id of the agreement, hex str
:param amount: Amount of tokens, int
:param account: Account
:return: bool
"""
return self._keeper.lock_reward_condition.ful... |
def grant_access(self, agreement_id, did, grantee_address, account):
"""
Grant access condition.
:param agreement_id: id of the agreement, hex str
:param did: DID, str
:param grantee_address: Address, hex str
:param account: Account
:return:
"""
r... |
def release_reward(self, agreement_id, amount, account):
"""
Release reward condition.
:param agreement_id: id of the agreement, hex str
:param amount: Amount of tokens, int
:param account: Account
:return:
"""
agreement_values = self._keeper.agreement_ma... |
def refund_reward(self, agreement_id, amount, account):
"""
Refund reaward condition.
:param agreement_id: id of the agreement, hex str
:param amount: Amount of tokens, int
:param account: Account
:return:
"""
return self.release_reward(agreement_id, amou... |
def from_json_file(cls, path):
"""
Return a template from a json allocated in a path.
:param path: string
:return: ServiceAgreementTemplate
"""
with open(path) as jsf:
template_json = json.load(jsf)
return cls(template_json=template_json) |
def parse_template_json(self, template_json):
"""
Parse a template from a json.
:param template_json: json dict
"""
assert template_json['type'] == self.DOCUMENT_TYPE, ''
self.template_id = template_json['templateId']
self.name = template_json.get('name')
... |
def as_dictionary(self):
"""
Return the service agreement template as a dictionary.
:return: dict
"""
template = {
'contractName': self.contract_name,
'events': [e.as_dictionary() for e in self.agreement_events],
'fulfillmentOrder': self.fulfi... |
def request(self, account, amount):
"""
Request a number of tokens to be minted and transfered to `account`
:param account: Account instance requesting the tokens
:param amount: int number of tokens to request
:return: bool
"""
return self._keeper.dispenser.reque... |
def transfer(self, receiver_address, amount, sender_account):
"""
Transfer a number of tokens from `sender_account` to `receiver_address`
:param receiver_address: hex str ethereum address to receive this transfer of tokens
:param amount: int number of tokens to transfer
:param s... |
def list_assets(self):
"""
List all the assets registered in the aquarius instance.
:return: List of DID string
"""
response = self.requests_session.get(self._base_url).content
if not response:
return {}
try:
asset_list = json.loads(respo... |
def get_asset_ddo(self, did):
"""
Retrieve asset ddo for a given did.
:param did: Asset DID string
:return: DDO instance
"""
response = self.requests_session.get(f'{self.url}/{did}').content
if not response:
return {}
try:
parsed_r... |
def get_asset_metadata(self, did):
"""
Retrieve asset metadata for a given did.
:param did: Asset DID string
:return: metadata key of the DDO instance
"""
response = self.requests_session.get(f'{self._base_url}/metadata/{did}').content
if not response:
... |
def list_assets_ddo(self):
"""
List all the ddos registered in the aquarius instance.
:return: List of DDO instance
"""
return json.loads(self.requests_session.get(self.url).content) |
def publish_asset_ddo(self, ddo):
"""
Register asset ddo in aquarius.
:param ddo: DDO instance
:return: API response (depends on implementation)
"""
try:
asset_did = ddo.did
response = self.requests_session.post(self.url, data=ddo.as_text(),
... |
def update_asset_ddo(self, did, ddo):
"""
Update the ddo of a did already registered.
:param did: Asset DID string
:param ddo: DDO instance
:return: API response (depends on implementation)
"""
response = self.requests_session.put(f'{self.url}/{did}', data=ddo.as... |
def text_search(self, text, sort=None, offset=100, page=1):
"""
Search in aquarius using text query.
Given the string aquarius will do a full-text query to search in all documents.
Currently implemented are the MongoDB and Elastic Search drivers.
For a detailed guide on how to... |
def query_search(self, search_query, sort=None, offset=100, page=1):
"""
Search using a query.
Currently implemented is the MongoDB query model to search for documents according to:
https://docs.mongodb.com/manual/tutorial/query-documents/
And an Elastic Search driver, which im... |
def retire_asset_ddo(self, did):
"""
Retire asset ddo of Aquarius.
:param did: Asset DID string
:return: API response (depends on implementation)
"""
response = self.requests_session.delete(f'{self.url}/{did}', headers=self._headers)
if response.status_code == 20... |
def validate_metadata(self, metadata):
"""
Validate that the metadata of your ddo is valid.
:param metadata: conforming to the Metadata accepted by Ocean Protocol, dict
:return: bool
"""
response = self.requests_session.post(
f'{self.url}/validate',
... |
def get_sla_template_path(service_type=ServiceTypes.ASSET_ACCESS):
"""
Get the template for a ServiceType.
:param service_type: ServiceTypes
:return: Path of the template, str
"""
if service_type == ServiceTypes.ASSET_ACCESS:
name = 'access_sla_template.json'
elif service_type == Se... |
def balance(self, account):
"""
Return the balance, a tuple with the eth and ocn balance.
:param account: Account instance to return the balance of
:return: Balance tuple of (eth, ocn)
"""
return Balance(self._keeper.get_ether_balance(account.address),
... |
def register_service_agreement_consumer(storage_path, publisher_address, agreement_id, did,
service_agreement, service_definition_id, price,
encrypted_files, consumer_account, condition_ids,
consume_c... |
def process_agreement_events_consumer(publisher_address, agreement_id, did, service_agreement,
price, consumer_account, condition_ids,
consume_callback):
"""
Process the agreement events during the register of the service agreement for ... |
def register_service_agreement_publisher(storage_path, consumer_address, agreement_id, did,
service_agreement, service_definition_id, price,
publisher_account, condition_ids, start_time=None):
"""
Registers the given service agree... |
def process_agreement_events_publisher(publisher_account, agreement_id, did, service_agreement,
price, consumer_address, condition_ids):
"""
Process the agreement events during the register of the service agreement for the publisher side
:param publisher_account: Acco... |
def execute_pending_service_agreements(storage_path, account, actor_type, did_resolver_fn):
"""
Iterates over pending service agreements recorded in the local storage,
fetches their service definitions, and subscribes to service agreement events.
:param storage_path: storage path for the internal db, ... |
def generate_multi_value_hash(types, values):
"""
Return the hash of the given list of values.
This is equivalent to packing and hashing values in a solidity smart contract
hence the use of `soliditySha3`.
:param types: list of solidity types expressed as strings
:param values: list of values m... |
def process_tx_receipt(tx_hash, event, event_name):
"""
Wait until the tx receipt is processed.
:param tx_hash: hash of the transaction
:param event: AttributeDict with the event data.
:param event_name: name of the event to subscribe, str
:return:
"""
web3 = Web3Provider.get_web3()
... |
def get_condition(self, condition_id):
"""Retrieve the condition for a condition_id.
:param condition_id: id of the condition, str
:return:
"""
condition = self.contract_concise.getCondition(condition_id)
if condition and len(condition) == 7:
return Condition... |
def fulfill(self, agreement_id, message, account_address, signature, from_account):
"""
Fulfill the sign conditon.
:param agreement_id: id of the agreement, hex str
:param message:
:param account_address: ethereum account address, hex str
:param signature: signed agreeme... |
def send(self, did, agreement_id, service_definition_id, signature,
consumer_account, auto_consume=False):
"""
Send a signed service agreement to the publisher Brizo instance to
consume/access the service.
:param did: str representation fo the asset DID. Use this to retriev... |
def create(self, did, service_definition_id, agreement_id,
service_agreement_signature, consumer_address, account):
"""
Execute the service agreement on-chain using keeper's ServiceAgreement contract.
The on-chain executeAgreement method requires the following arguments:
... |
def is_access_granted(self, 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`.
:param agreement_id: id of the agreement, hex st... |
def _verify_service_agreement_signature(self, did, agreement_id, service_definition_id,
consumer_address, signature, ddo=None):
"""
Verify service agreement signature.
Verify that the given signature is truly signed by the `consumer_address`
a... |
def status(self, agreement_id):
"""
Get the status of a service agreement.
:param agreement_id: id of the agreement, hex str
:return: dict with condition status of each of the agreement's conditions or None if the
agreement is invalid.
"""
condition_ids = self._k... |
def create_agreement(self, agreement_id, did, condition_ids, time_locks, time_outs,
consumer_address, account):
"""
Create the service agreement. Return true if it is created successfully.
:param agreement_id: id of the agreement, hex str
:param did: DID, str
... |
def subscribe_agreement_created(self, agreement_id, timeout, callback, args, wait=False):
"""
Subscribe to an agreement created.
:param agreement_id: id of the agreement, hex str
:param timeout:
:param callback:
:param args:
:param wait: if true block the listene... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.