def setup_agreements_environment(): consumer_acc = get_consumer_account() publisher_acc = get_publisher_account() keeper = Keeper.get_instance() ddo = get_ddo_sample() ddo._did = DID.did({"0": "0x12341234"}) keeper.did_registry.register( ddo.asset_id, checksum=Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id), url='aquarius:5000', account=publisher_acc, providers=None) registered_ddo = ddo asset_id = registered_ddo.asset_id service_agreement = ServiceAgreement.from_ddo(ServiceTypes.ASSET_ACCESS, ddo) agreement_id = ServiceAgreement.create_new_agreement_id() price = service_agreement.get_price() (lock_cond_id, access_cond_id, escrow_cond_id) = service_agreement.generate_agreement_condition_ids( agreement_id, asset_id, consumer_acc.address, publisher_acc.address, keeper) return ( keeper, publisher_acc, consumer_acc, agreement_id, asset_id, price, service_agreement, (lock_cond_id, access_cond_id, escrow_cond_id), )
def place_order(publisher_account, ddo, consumer_account, service_type): keeper = keeper_instance() agreement_id = ServiceAgreement.create_new_agreement_id() publisher_address = publisher_account.address # balance = keeper.token.get_token_balance(consumer_account.address)/(2**18) # if balance < 20: # keeper.dispenser.request_tokens(100, consumer_account) service_agreement = ServiceAgreement.from_ddo(service_type, ddo) condition_ids = service_agreement.generate_agreement_condition_ids( agreement_id, ddo.asset_id, consumer_account.address, publisher_address, keeper) time_locks = service_agreement.conditions_timelocks time_outs = service_agreement.conditions_timeouts template_name = keeper.template_manager.SERVICE_TO_TEMPLATE_NAME[ service_type] template_id = keeper.template_manager.create_template_id(template_name) actor_map = { 'consumer': consumer_account.address, 'provider': publisher_address } actors = [ actor_map[_type] for _type in get_template_actor_types(keeper, template_id) ] assert keeper.template_manager.contract_concise.isTemplateIdApproved( template_id), f'template {template_id} is not approved.' keeper_instance().agreement_manager.create_agreement( agreement_id, ddo.asset_id, template_id, condition_ids, time_locks, time_outs, actors, consumer_account) return agreement_id
def place_order(publisher_account, ddo, consumer_account): keeper = keeper_instance() agreement_id = ServiceAgreement.create_new_agreement_id() agreement_template = keeper.escrow_access_secretstore_template publisher_address = publisher_account.address service_agreement = ServiceAgreement.from_ddo(ServiceTypes.ASSET_ACCESS, ddo) condition_ids = service_agreement.generate_agreement_condition_ids( agreement_id, ddo.asset_id, consumer_account.address, publisher_address, keeper) time_locks = service_agreement.conditions_timelocks time_outs = service_agreement.conditions_timeouts agreement_template.create_agreement(agreement_id, ddo.asset_id, condition_ids, time_locks, time_outs, consumer_account.address, consumer_account) return agreement_id
def new(): return ServiceAgreement.create_new_agreement_id()