idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
235,300 | def merged_packages ( env_packages , names ) : combined_packages = sorted ( itertools . chain . from_iterable ( env_packages [ name ] . items ( ) for name in names ) ) result = { } errors = set ( ) for name , version in combined_packages : if name in result : if result [ name ] != version : errors . add ( ( name , vers... | Return union set of environment packages with given names |
235,301 | def recursive_refs ( envs , name ) : refs_by_name = { env [ 'name' ] : set ( env [ 'refs' ] ) for env in envs } refs = refs_by_name [ name ] if refs : indirect_refs = set ( itertools . chain . from_iterable ( [ recursive_refs ( envs , ref ) for ref in refs ] ) ) else : indirect_refs = set ( ) return set . union ( refs ... | Return set of recursive refs for given env name |
235,302 | def reference_cluster ( envs , name ) : edges = [ set ( [ env [ 'name' ] , ref ] ) for env in envs for ref in env [ 'refs' ] ] prev , cluster = set ( ) , set ( [ name ] ) while prev != cluster : prev = set ( cluster ) to_visit = [ ] for edge in edges : if cluster & edge : cluster |= edge else : to_visit . append ( edge... | Return set of all env names referencing or referenced by given name . |
235,303 | def get_requests_session ( ) : session = requests . sessions . Session ( ) session . mount ( 'http://' , HTTPAdapter ( pool_connections = 25 , pool_maxsize = 25 , pool_block = True ) ) session . mount ( 'https://' , HTTPAdapter ( pool_connections = 25 , pool_maxsize = 25 , pool_block = True ) ) return session | Set connection pool maxsize and block value to avoid connection pool full warnings . |
235,304 | def request_tokens ( self , amount , account ) : address = account . address try : tx_hash = self . send_transaction ( 'requestTokens' , ( amount , ) , transact = { 'from' : address , 'passphrase' : account . password } ) logging . debug ( f'{address} requests {amount} tokens, returning receipt' ) try : receipt = Web3P... | Request an amount of tokens for a particular address . This transaction has gas cost |
235,305 | def get_network_name ( network_id ) : if os . environ . get ( 'KEEPER_NETWORK_NAME' ) : logging . debug ( 'keeper network name overridden by an environment variable: {}' . format ( os . environ . get ( 'KEEPER_NETWORK_NAME' ) ) ) return os . environ . get ( 'KEEPER_NETWORK_NAME' ) return Keeper . _network_name_map . ge... | Return the keeper network name based on the current ethereum network id . Return development for every network id that is not mapped . |
235,306 | def unlock_account ( account ) : return Web3Provider . get_web3 ( ) . personal . unlockAccount ( account . address , account . password ) | Unlock the account . |
235,307 | def get_condition_name_by_address ( self , address ) : if self . lock_reward_condition . address == address : return 'lockReward' elif self . access_secret_store_condition . address == address : return 'accessSecretStore' elif self . escrow_reward_condition . address == address : return 'escrowReward' else : logging . ... | Return the condition name for a given address . |
235,308 | def consume_service ( service_agreement_id , service_endpoint , account , files , destination_folder , index = None ) : signature = Keeper . get_instance ( ) . sign_hash ( service_agreement_id , account ) if index is not None : assert isinstance ( index , int ) , logger . error ( 'index has to be an integer.' ) assert ... | Call the brizo endpoint to get access to the different files that form the asset . |
235,309 | def _prepare_consume_payload ( did , service_agreement_id , service_definition_id , signature , consumer_address ) : return json . dumps ( { 'did' : did , 'serviceAgreementId' : service_agreement_id , ServiceAgreement . SERVICE_DEFINITION_ID : service_definition_id , 'signature' : signature , 'consumerAddress' : consum... | Prepare a payload to send to Brizo . |
235,310 | def get_brizo_url ( config ) : brizo_url = 'http://localhost:8030' if config . has_option ( 'resources' , 'brizo.url' ) : brizo_url = config . get ( 'resources' , 'brizo.url' ) or brizo_url brizo_path = '/api/v1/brizo' return f'{brizo_url}{brizo_path}' | Return the Brizo component url . |
235,311 | def validate ( metadata ) : for section_key in Metadata . REQUIRED_SECTIONS : if section_key not in metadata or not metadata [ section_key ] or not isinstance ( metadata [ section_key ] , dict ) : return False section = Metadata . MAIN_SECTIONS [ section_key ] section_metadata = metadata [ section_key ] for subkey in s... | Validator of the metadata composition |
235,312 | def get_example ( ) : example = dict ( ) for section_key , section in Metadata . MAIN_SECTIONS . items ( ) : example [ section_key ] = section . EXAMPLE . copy ( ) return example | Retrieve an example of the metadata |
235,313 | def encrypt_document ( self , document_id , content , threshold = 0 ) : return self . _secret_store_client ( self . _account ) . publish_document ( remove_0x_prefix ( document_id ) , content , threshold ) | encrypt string data using the DID as an secret store id if secret store is enabled then return the result from secret store encryption |
235,314 | def download ( service_agreement_id , service_definition_id , ddo , consumer_account , destination , brizo , secret_store , index = None ) : did = ddo . did encrypted_files = ddo . metadata [ 'base' ] [ 'encryptedFiles' ] encrypted_files = ( encrypted_files if isinstance ( encrypted_files , str ) else encrypted_files [... | Download asset data files or result files from a compute job . |
235,315 | def set_key_value ( self , value , store_type = PUBLIC_KEY_STORE_TYPE_BASE64 ) : if isinstance ( value , dict ) : if PUBLIC_KEY_STORE_TYPE_HEX in value : self . set_key_value ( value [ PUBLIC_KEY_STORE_TYPE_HEX ] , PUBLIC_KEY_STORE_TYPE_HEX ) elif PUBLIC_KEY_STORE_TYPE_BASE64 in value : self . set_key_value ( value [ P... | Set the key value based on it s storage type . |
235,316 | def set_encode_key_value ( self , value , store_type ) : self . _store_type = store_type if store_type == PUBLIC_KEY_STORE_TYPE_HEX : self . _value = value . hex ( ) elif store_type == PUBLIC_KEY_STORE_TYPE_BASE64 : self . _value = b64encode ( value ) . decode ( ) elif store_type == PUBLIC_KEY_STORE_TYPE_BASE85 : self ... | Save the key value base on it s storage type . |
235,317 | def get_decode_value ( self ) : if self . _store_type == PUBLIC_KEY_STORE_TYPE_HEX : value = bytes . fromhex ( self . _value ) elif self . _store_type == PUBLIC_KEY_STORE_TYPE_BASE64 : value = b64decode ( self . _value ) elif self . _store_type == PUBLIC_KEY_STORE_TYPE_BASE85 : value = b85decode ( self . _value ) elif ... | Return the key value based on it s storage type . |
235,318 | def as_text ( self , is_pretty = False ) : values = { 'id' : self . _id , 'type' : self . _type } if self . _owner : values [ 'owner' ] = self . _owner if is_pretty : return json . dumps ( values , indent = 4 , separators = ( ',' , ': ' ) ) return json . dumps ( values ) | Return the key as JSON text . |
235,319 | def as_dictionary ( self ) : values = { 'id' : self . _id , 'type' : self . _type } if self . _owner : values [ 'owner' ] = self . _owner return values | Return the key as a python dictionary . |
235,320 | def get_agreement ( self , agreement_id ) : agreement = self . contract_concise . getAgreement ( agreement_id ) if agreement and len ( agreement ) == 6 : agreement = AgreementValues ( * agreement ) did = add_0x_prefix ( agreement . did . hex ( ) ) cond_ids = [ add_0x_prefix ( _id . hex ( ) ) for _id in agreement . cond... | Retrieve the agreement for a agreement_id . |
235,321 | def _load ( contract_name ) : contract_definition = ContractHandler . get_contract_dict_by_name ( contract_name ) address = Web3Provider . get_web3 ( ) . toChecksumAddress ( contract_definition [ 'address' ] ) abi = contract_definition [ 'abi' ] contract = Web3Provider . get_web3 ( ) . eth . contract ( address = addres... | Retrieve the contract instance for contract_name that represent the smart contract in the keeper network . |
235,322 | def get_contract_dict_by_name ( contract_name ) : network_name = Keeper . get_network_name ( Keeper . get_network_id ( ) ) . lower ( ) artifacts_path = ConfigProvider . get_config ( ) . keeper_path path = ContractHandler . _get_contract_file_path ( artifacts_path , contract_name , network_name ) if not ( path and os . ... | Retrieve the Contract instance for a given contract name . |
235,323 | def buy_asset ( ) : ConfigProvider . set_config ( ExampleConfig . get_config ( ) ) config = ConfigProvider . get_config ( ) ocn = Ocean ( ) acc = get_publisher_account ( config ) if not acc : acc = ( [ acc for acc in ocn . accounts . list ( ) if acc . password ] or ocn . accounts . list ( ) ) [ 0 ] ddo = ocn . assets .... | Requires all ocean services running . |
235,324 | def token_approve ( self , spender_address , price , from_account ) : if not Web3Provider . get_web3 ( ) . isChecksumAddress ( spender_address ) : spender_address = Web3Provider . get_web3 ( ) . toChecksumAddress ( spender_address ) tx_hash = self . send_transaction ( 'approve' , ( spender_address , price ) , transact ... | Approve the passed address to spend the specified amount of tokens . |
235,325 | def transfer ( self , receiver_address , amount , from_account ) : tx_hash = self . send_transaction ( 'transfer' , ( receiver_address , amount ) , transact = { 'from' : from_account . address , 'passphrase' : from_account . password } ) return self . get_tx_receipt ( tx_hash ) . status == 1 | Transfer tokens from one account to the receiver address . |
235,326 | def fulfill_access_secret_store_condition ( event , agreement_id , did , service_agreement , consumer_address , publisher_account ) : logger . debug ( f"release reward after event {event}." ) name_to_parameter = { param . name : param for param in service_agreement . condition_by_name [ 'accessSecretStore' ] . paramete... | Fulfill the access condition . |
235,327 | def retire ( self , did ) : try : ddo = self . resolve ( did ) metadata_service = ddo . find_service_by_type ( ServiceTypes . METADATA ) self . _get_aquarius ( metadata_service . endpoints . service ) . retire_asset_ddo ( did ) return True except AquariusGenericError as err : logger . error ( err ) return False | Retire this did of Aquarius |
235,328 | def search ( self , text , sort = None , offset = 100 , page = 1 , aquarius_url = None ) : assert page >= 1 , f'Invalid page value {page}. Required page >= 1.' logger . info ( f'Searching asset containing: {text}' ) return [ DDO ( dictionary = ddo_dict ) for ddo_dict in self . _get_aquarius ( aquarius_url ) . text_sear... | Search an asset in oceanDB using aquarius . |
235,329 | def query ( self , query , sort = None , offset = 100 , page = 1 , aquarius_url = None ) : logger . info ( f'Searching asset query: {query}' ) aquarius = self . _get_aquarius ( aquarius_url ) return [ DDO ( dictionary = ddo_dict ) for ddo_dict in aquarius . query_search ( query , sort , offset , page ) [ 'results' ] ] | Search an asset in oceanDB using search query . |
235,330 | def order ( self , did , service_definition_id , consumer_account , auto_consume = False ) : assert consumer_account . address in self . _keeper . accounts , f'Unrecognized consumer ' f'address `consumer_account`' agreement_id , signature = self . _agreements . prepare ( did , service_definition_id , consumer_account )... | Sign service agreement . |
235,331 | def consume ( self , service_agreement_id , did , service_definition_id , consumer_account , destination , index = None ) : ddo = self . resolve ( did ) if index is not None : assert isinstance ( index , int ) , logger . error ( 'index has to be an integer.' ) assert index >= 0 , logger . error ( 'index has to be 0 or ... | Consume the asset data . |
235,332 | def propose ( self , template_address , account ) : try : proposed = self . _keeper . template_manager . propose_template ( template_address , account ) return proposed except ValueError as err : template_values = self . _keeper . template_manager . get_template ( template_address ) if not template_values : logger . wa... | Propose a new template . |
235,333 | def approve ( self , template_address , account ) : try : approved = self . _keeper . template_manager . approve_template ( template_address , account ) return approved except ValueError as err : template_values = self . _keeper . template_manager . get_template ( template_address ) if not template_values : logger . wa... | Approve a template already proposed . The account needs to be owner of the templateManager contract to be able of approve the template . |
235,334 | def revoke ( self , template_address , account ) : try : revoked = self . _keeper . template_manager . revoke_template ( template_address , account ) return revoked except ValueError as err : template_values = self . _keeper . template_manager . get_template ( template_address ) if not template_values : logger . warnin... | Revoke a template already approved . The account needs to be owner of the templateManager contract to be able of revoke the template . |
235,335 | def get_price ( self ) : for cond in self . conditions : for p in cond . parameters : if p . name == '_amount' : return p . value | Return the price from the conditions parameters . |
235,336 | def get_service_agreement_hash ( self , agreement_id , asset_id , consumer_address , publisher_address , keeper ) : agreement_hash = ServiceAgreement . generate_service_agreement_hash ( self . template_id , self . generate_agreement_condition_ids ( agreement_id , asset_id , consumer_address , publisher_address , keeper... | Return the hash of the service agreement values to be signed by a consumer . |
235,337 | def keeper_path ( self ) : keeper_path_string = self . get ( self . _section_name , NAME_KEEPER_PATH ) path = Path ( keeper_path_string ) . expanduser ( ) . resolve ( ) if os . path . exists ( path ) : pass elif os . getenv ( 'VIRTUAL_ENV' ) : path = os . path . join ( os . getenv ( 'VIRTUAL_ENV' ) , 'artifacts' ) else... | Path where the keeper - contracts artifacts are allocated . |
235,338 | def add_public_key ( self , did , public_key ) : logger . debug ( f'Adding public key {public_key} to the did {did}' ) self . _public_keys . append ( PublicKeyBase ( did , ** { "owner" : public_key , "type" : "EthereumECDSAKey" } ) ) | Add a public key object to the list of public keys . |
235,339 | def add_authentication ( self , public_key , authentication_type = None ) : authentication = { } if public_key : authentication = { 'type' : authentication_type , 'publicKey' : public_key } logger . debug ( f'Adding authentication {authentication}' ) self . _authentications . append ( authentication ) | Add a authentication public key id and type to the list of authentications . |
235,340 | def add_service ( self , service_type , service_endpoint = None , values = None ) : if isinstance ( service_type , Service ) : service = service_type else : service = Service ( service_endpoint , service_type , values , did = self . _did ) logger . debug ( f'Adding service with service type {service_type} with did {sel... | Add a service to the list of services on the DDO . |
235,341 | def as_text ( self , is_proof = True , is_pretty = False ) : data = self . as_dictionary ( is_proof ) if is_pretty : return json . dumps ( data , indent = 2 , separators = ( ',' , ': ' ) ) return json . dumps ( data ) | Return the DDO as a JSON text . |
235,342 | def as_dictionary ( self , is_proof = True ) : if self . _created is None : self . _created = DDO . _get_timestamp ( ) data = { '@context' : DID_DDO_CONTEXT_URL , 'id' : self . _did , 'created' : self . _created , } if self . _public_keys : values = [ ] for public_key in self . _public_keys : values . append ( public_k... | Return the DDO as a JSON dict . |
235,343 | def _read_dict ( self , dictionary ) : values = dictionary self . _did = values [ 'id' ] self . _created = values . get ( 'created' , None ) if 'publicKey' in values : self . _public_keys = [ ] for value in values [ 'publicKey' ] : if isinstance ( value , str ) : value = json . loads ( value ) self . _public_keys . app... | Import a JSON dict into this DDO . |
235,344 | def get_public_key ( self , key_id , is_search_embedded = False ) : if isinstance ( key_id , int ) : return self . _public_keys [ key_id ] for item in self . _public_keys : if item . get_id ( ) == key_id : return item if is_search_embedded : for authentication in self . _authentications : if authentication . get_public... | Key_id can be a string or int . If int then the index in the list of keys . |
235,345 | def _get_public_key_count ( self ) : index = len ( self . _public_keys ) for authentication in self . _authentications : if authentication . is_public_key ( ) : index += 1 return index | Return the count of public keys in the list and embedded . |
235,346 | def _get_authentication_from_public_key_id ( self , key_id ) : for authentication in self . _authentications : if authentication . is_key_id ( key_id ) : return authentication return None | Return the authentication based on it s id . |
235,347 | def get_service ( self , service_type = None ) : for service in self . _services : if service . type == service_type and service_type : return service return None | Return a service using . |
235,348 | def find_service_by_id ( self , service_id ) : service_id_key = 'serviceDefinitionId' service_id = str ( service_id ) for service in self . _services : if service_id_key in service . values and str ( service . values [ service_id_key ] ) == service_id : return service try : int ( service_id ) return None except ValueEr... | Get service for a given service_id . |
235,349 | def find_service_by_type ( self , service_type ) : for service in self . _services : if service_type == service . type : return service return None | Get service for a given service type . |
235,350 | def create_public_key_from_json ( values ) : _id = values . get ( 'id' ) if not _id : _id = '' if values . get ( 'type' ) == PUBLIC_KEY_TYPE_RSA : public_key = PublicKeyRSA ( _id , owner = values . get ( 'owner' ) ) else : public_key = PublicKeyBase ( _id , owner = values . get ( 'owner' ) , type = 'EthereumECDSAKey' )... | Create a public key object based on the values from the JSON record . |
235,351 | def create_authentication_from_json ( values ) : key_id = values . get ( 'publicKey' ) authentication_type = values . get ( 'type' ) if not key_id : raise ValueError ( f'Invalid authentication definition, "publicKey" is missing: {values}' ) authentication = { 'type' : authentication_type , 'publicKey' : key_id } return... | Create authentitaciton object from a JSON string . |
235,352 | def generate_checksum ( did , metadata ) : files_checksum = '' for file in metadata [ 'base' ] [ 'files' ] : if 'checksum' in file : files_checksum = files_checksum + file [ 'checksum' ] return hashlib . sha3_256 ( ( files_checksum + metadata [ 'base' ] [ 'name' ] + metadata [ 'base' ] [ 'author' ] + metadata [ 'base' ... | Generation of the hash for integrity checksum . |
235,353 | def register ( self , did , checksum , url , account , providers = None ) : did_source_id = did_to_id_bytes ( did ) if not did_source_id : raise ValueError ( f'{did} must be a valid DID to register' ) if not urlparse ( url ) : raise ValueError ( f'Invalid URL {url} to register for DID {did}' ) if checksum is None : che... | Register or update a DID on the block chain using the DIDRegistry smart contract . |
235,354 | def _register_attribute ( self , did , checksum , value , account , providers ) : assert isinstance ( providers , list ) , '' return self . send_transaction ( 'registerAttribute' , ( did , checksum , providers , value ) , transact = { 'from' : account . address , 'passphrase' : account . password } ) | Register an DID attribute as an event on the block chain . |
235,355 | def remove_provider ( self , did , provider_address , account ) : tx_hash = self . send_transaction ( 'removeDIDProvider' , ( did , provider_address ) , transact = { 'from' : account . address , 'passphrase' : account . password } ) return self . get_tx_receipt ( tx_hash ) | Remove a provider |
235,356 | def get_did_providers ( self , did ) : register_values = self . contract_concise . getDIDRegister ( did ) if register_values and len ( register_values ) == 5 : return DIDRegisterValues ( * register_values ) . providers return None | Return the list providers registered on - chain for the given did . |
235,357 | def get_owner_asset_ids ( self , address ) : block_filter = self . _get_event_filter ( owner = address ) log_items = block_filter . get_all_entries ( max_tries = 5 ) did_list = [ ] for log_i in log_items : did_list . append ( id_to_did ( log_i . args [ '_did' ] ) ) return did_list | Get the list of assets owned by an address owner . |
235,358 | def set_encode_key_value ( self , value , store_type = PUBLIC_KEY_STORE_TYPE_BASE64 ) : if store_type == PUBLIC_KEY_STORE_TYPE_PEM : PublicKeyBase . set_encode_key_value ( self , value . exportKey ( 'PEM' ) . decode ( ) , store_type ) else : PublicKeyBase . set_encode_key_value ( self , value . exportKey ( 'DER' ) , st... | Set the value based on the type of encoding supported by RSA . |
235,359 | def did_parse ( did ) : 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]+):([a-zA-Z0-9-.]+)(.*)' , did ) if not match : raise ValueError ( f'DID {did} does not seem to be valid.' ) result = { 'method' : match . grou... | Parse a DID into it s parts . |
235,360 | def id_to_did ( did_id , method = 'op' ) : if isinstance ( did_id , bytes ) : did_id = Web3 . toHex ( did_id ) if isinstance ( did_id , str ) : did_id = remove_0x_prefix ( did_id ) else : raise TypeError ( "did id must be a hex string or bytes" ) if Web3 . toBytes ( hexstr = did_id ) == b'' : did_id = '0' return f'did:... | Return an Ocean DID from given a hex id . |
235,361 | def did_to_id_bytes ( did ) : 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 : did_result = did_parse ( did ) if not did_result : raise ValueError ( f'{did} is not a valid did' ) if not did_result [ 'id' ] : raise ValueErro... | Return an Ocean DID to it s correspondng hex id in bytes . |
235,362 | def get_template ( self , template_id ) : template = self . contract_concise . getTemplate ( template_id ) if template and len ( template ) == 4 : return AgreementTemplate ( * template ) return None | Get the template for a given template id . |
235,363 | def propose_template ( self , template_id , from_account ) : tx_hash = self . send_transaction ( 'proposeTemplate' , ( template_id , ) , transact = { 'from' : from_account . address , 'passphrase' : from_account . password } ) return self . get_tx_receipt ( tx_hash ) . status == 1 | Propose a template . |
235,364 | def access_service_descriptor ( price , consume_endpoint , service_endpoint , timeout , template_id ) : return ( ServiceTypes . ASSET_ACCESS , { 'price' : price , 'consumeEndpoint' : consume_endpoint , 'serviceEndpoint' : service_endpoint , 'timeout' : timeout , 'templateId' : template_id } ) | Access service descriptor . |
235,365 | def compute_service_descriptor ( price , consume_endpoint , service_endpoint , timeout ) : return ( ServiceTypes . CLOUD_COMPUTE , { 'price' : price , 'consumeEndpoint' : consume_endpoint , 'serviceEndpoint' : service_endpoint , 'timeout' : timeout } ) | Compute service descriptor . |
235,366 | def build_services ( did , service_descriptors ) : services = [ ] sa_def_key = ServiceAgreement . SERVICE_DEFINITION_ID for i , service_desc in enumerate ( service_descriptors ) : service = ServiceFactory . build_service ( service_desc , did ) service . update_value ( sa_def_key , str ( i ) ) services . append ( servic... | Build a list of services . |
235,367 | def build_service ( service_descriptor , did ) : assert isinstance ( service_descriptor , tuple ) and len ( service_descriptor ) == 2 , 'Unknown service descriptor format.' service_type , kwargs = service_descriptor if service_type == ServiceTypes . METADATA : return ServiceFactory . build_metadata_service ( did , kwar... | Build a service . |
235,368 | def build_metadata_service ( did , metadata , service_endpoint ) : return Service ( service_endpoint , ServiceTypes . METADATA , values = { 'metadata' : metadata } , did = did ) | Build a metadata service . |
235,369 | def build_access_service ( did , price , consume_endpoint , service_endpoint , timeout , template_id ) : param_map = { '_documentId' : did_to_id ( did ) , '_amount' : price , '_rewardAddress' : Keeper . get_instance ( ) . escrow_reward_condition . address , } sla_template_path = get_sla_template_path ( ) sla_template =... | Build the access service . |
235,370 | def record_service_agreement ( storage_path , service_agreement_id , did , service_definition_id , price , files , start_time , status = 'pending' ) : conn = sqlite3 . connect ( storage_path ) try : cursor = conn . cursor ( ) cursor . execute ( ) cursor . execute ( 'INSERT OR REPLACE INTO service_agreements VALUES (?,?... | Records the given pending service agreement . |
235,371 | def update_service_agreement_status ( storage_path , service_agreement_id , status = 'pending' ) : conn = sqlite3 . connect ( storage_path ) try : cursor = conn . cursor ( ) cursor . execute ( 'UPDATE service_agreements SET status=? WHERE id=?' , ( status , service_agreement_id ) , ) conn . commit ( ) finally : conn . ... | Update the service agreement status . |
235,372 | def setup_logging ( default_path = 'logging.yaml' , default_level = logging . INFO , env_key = 'LOG_CFG' ) : 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 : config = yaml . safe_load ( file . read ( ) ) logging... | Logging setup . |
235,373 | def encrypt ( self , document_id , content , account ) : return self . _secret_store ( account ) . encrypt_document ( document_id , content ) | Encrypt string data using the DID as an secret store id if secret store is enabled then return the result from secret store encryption |
235,374 | def get_resolve_url ( self , did_bytes ) : data = self . _did_registry . get_registered_attribute ( did_bytes ) if not ( data and data . get ( 'value' ) ) : return None return data [ 'value' ] | Return a did value and value type from the block chain event record using did . |
235,375 | def get_instance ( cls , dependencies = None ) : assert cls is not ContractBase , 'ContractBase is not meant to be used directly.' assert cls . CONTRACT_NAME , 'CONTRACT_NAME must be set to a valid keeper contract name.' return cls ( cls . CONTRACT_NAME , dependencies ) | Return an instance for a contract name . |
235,376 | def get_tx_receipt ( tx_hash ) : try : Web3Provider . get_web3 ( ) . eth . waitForTransactionReceipt ( tx_hash , timeout = 20 ) except Timeout : logger . info ( 'Waiting for transaction receipt timed out.' ) return return Web3Provider . get_web3 ( ) . eth . getTransactionReceipt ( tx_hash ) | Get the receipt of a tx . |
235,377 | def subscribe_to_event ( self , event_name , timeout , event_filter , callback = False , timeout_callback = None , args = None , wait = False ) : from squid_py . keeper . event_listener import EventListener return EventListener ( self . CONTRACT_NAME , event_name , args , filters = event_filter ) . listen_once ( callba... | Create a listener for the event choose . |
235,378 | def refund_reward ( event , agreement_id , did , service_agreement , price , consumer_account , publisher_address , condition_ids ) : logger . debug ( f"trigger refund after event {event}." ) access_id , lock_id = condition_ids [ : 2 ] name_to_parameter = { param . name : param for param in service_agreement . conditio... | Refund the reward to the publisher address . |
235,379 | def consume_asset ( event , agreement_id , did , service_agreement , consumer_account , consume_callback ) : logger . debug ( f"consuming asset after event {event}." ) if consume_callback : config = ConfigProvider . get_config ( ) secret_store = SecretStoreProvider . get_secret_store ( config . secret_store_url , confi... | Consumption of an asset after get the event call . |
235,380 | def verify_contracts ( ) : artifacts_path = ConfigProvider . get_config ( ) . keeper_path logger . info ( f'Keeper contract artifacts (JSON abi files) at: {artifacts_path}' ) if os . environ . get ( 'KEEPER_NETWORK_NAME' ) : logger . warning ( f'The `KEEPER_NETWORK_NAME` env var is set to ' f'{os.environ.get("KEEPER_NE... | Verify that the contracts are deployed correctly in the network . |
235,381 | def create_access_service ( price , service_endpoint , consume_endpoint , timeout = None ) : timeout = timeout or 3600 service = ServiceDescriptor . access_service_descriptor ( price , service_endpoint , consume_endpoint , timeout , '' ) return service | Publish an asset with an Access service according to the supplied attributes . |
235,382 | def lock_reward ( self , agreement_id , amount , account ) : return self . _keeper . lock_reward_condition . fulfill ( agreement_id , self . _keeper . escrow_reward_condition . address , amount , account ) | Lock reward condition . |
235,383 | def grant_access ( self , agreement_id , did , grantee_address , account ) : return self . _keeper . access_secret_store_condition . fulfill ( agreement_id , add_0x_prefix ( did_to_id ( did ) ) , grantee_address , account ) | Grant access condition . |
235,384 | def release_reward ( self , agreement_id , amount , account ) : agreement_values = self . _keeper . agreement_manager . get_agreement ( agreement_id ) consumer , provider = self . _keeper . escrow_access_secretstore_template . get_agreement_data ( agreement_id ) access_id , lock_id = agreement_values . condition_ids [ ... | Release reward condition . |
235,385 | def refund_reward ( self , agreement_id , amount , account ) : return self . release_reward ( agreement_id , amount , account ) | Refund reaward condition . |
235,386 | def from_json_file ( cls , path ) : with open ( path ) as jsf : template_json = json . load ( jsf ) return cls ( template_json = template_json ) | Return a template from a json allocated in a path . |
235,387 | def parse_template_json ( self , template_json ) : assert template_json [ 'type' ] == self . DOCUMENT_TYPE , '' self . template_id = template_json [ 'templateId' ] self . name = template_json . get ( 'name' ) self . creator = template_json . get ( 'creator' ) self . template = template_json [ 'serviceAgreementTemplate'... | Parse a template from a json . |
235,388 | def as_dictionary ( self ) : template = { 'contractName' : self . contract_name , 'events' : [ e . as_dictionary ( ) for e in self . agreement_events ] , 'fulfillmentOrder' : self . fulfillment_order , 'conditionDependency' : self . condition_dependency , 'conditions' : [ cond . as_dictionary ( ) for cond in self . con... | Return the service agreement template as a dictionary . |
235,389 | def request ( self , account , amount ) : return self . _keeper . dispenser . request_tokens ( amount , account ) | Request a number of tokens to be minted and transfered to account |
235,390 | def transfer ( self , receiver_address , amount , sender_account ) : self . _keeper . token . token_approve ( receiver_address , amount , sender_account ) self . _keeper . token . transfer ( receiver_address , amount , sender_account ) | Transfer a number of tokens from sender_account to receiver_address |
235,391 | def list_assets ( self ) : response = self . requests_session . get ( self . _base_url ) . content if not response : return { } try : asset_list = json . loads ( response ) except TypeError : asset_list = None except ValueError : raise ValueError ( response . decode ( 'UTF-8' ) ) if not asset_list : return [ ] if 'ids'... | List all the assets registered in the aquarius instance . |
235,392 | def get_asset_ddo ( self , did ) : response = self . requests_session . get ( f'{self.url}/{did}' ) . content if not response : return { } try : parsed_response = json . loads ( response ) except TypeError : parsed_response = None except ValueError : raise ValueError ( response . decode ( 'UTF-8' ) ) if parsed_response... | Retrieve asset ddo for a given did . |
235,393 | def get_asset_metadata ( self , did ) : response = self . requests_session . get ( f'{self._base_url}/metadata/{did}' ) . content if not response : return { } try : parsed_response = json . loads ( response ) except TypeError : parsed_response = None except ValueError : raise ValueError ( response . decode ( 'UTF-8' ) ... | Retrieve asset metadata for a given did . |
235,394 | def list_assets_ddo ( self ) : return json . loads ( self . requests_session . get ( self . url ) . content ) | List all the ddos registered in the aquarius instance . |
235,395 | def publish_asset_ddo ( self , ddo ) : try : asset_did = ddo . did response = self . requests_session . post ( self . url , data = ddo . as_text ( ) , headers = self . _headers ) except AttributeError : raise AttributeError ( 'DDO invalid. Review that all the required parameters are filled.' ) if response . status_code... | Register asset ddo in aquarius . |
235,396 | def update_asset_ddo ( self , did , ddo ) : response = self . requests_session . put ( f'{self.url}/{did}' , data = ddo . as_text ( ) , headers = self . _headers ) if response . status_code == 200 or response . status_code == 201 : return json . loads ( response . content ) else : raise Exception ( f'Unable to update D... | Update the ddo of a did already registered . |
235,397 | def text_search ( self , text , sort = None , offset = 100 , page = 1 ) : assert page >= 1 , f'Invalid page value {page}. Required page >= 1.' payload = { "text" : text , "sort" : sort , "offset" : offset , "page" : page } response = self . requests_session . get ( f'{self.url}/query' , params = payload , headers = sel... | Search in aquarius using text query . |
235,398 | def query_search ( self , search_query , sort = None , offset = 100 , page = 1 ) : assert page >= 1 , f'Invalid page value {page}. Required page >= 1.' search_query [ 'sort' ] = sort search_query [ 'offset' ] = offset search_query [ 'page' ] = page response = self . requests_session . post ( f'{self.url}/query' , data ... | Search using a query . |
235,399 | def retire_asset_ddo ( self , did ) : response = self . requests_session . delete ( f'{self.url}/{did}' , headers = self . _headers ) if response . status_code == 200 : logging . debug ( f'Removed asset DID: {did} from metadata store' ) return response raise AquariusGenericError ( f'Unable to remove DID: {response}' ) | Retire asset ddo of Aquarius . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.