Ejemplo n.º 1
0
 def check_ddo(self, did, agreement_id, asset_id, consumer_address, keeper, cond_ids, service_type):
     ddo = DIDResolver(keeper.did_registry).resolve(did)
     aservice = ddo.get_service(service_type)
     token_address = aservice.get_param_value_by_name('_tokenAddress')
     if token_address is None or len(token_address) == 0:
         token_address = keeper.token.address
     (id1, id2, id3) = aservice.generate_agreement_condition_ids(agreement_id, asset_id, consumer_address, keeper, token_address)
     ids = [id1, id2, id3]
     if ids != cond_ids:
         raise InvalidClientError(f"ServiceAgreement {agreement_id} doesn't match ddo")
Ejemplo n.º 2
0
    def validate_nft_access(self, agreement_id, did, consumer_address):
        keeper = keeper_instance()

        asset = DIDResolver(keeper.did_registry).resolve(did)

        # check which nft access service type is on the ddo
        service_type = ServiceTypes.NFT_ACCESS
        if asset.get_service(ServiceTypes.NFT721_ACCESS) is not None:
            service_type = ServiceTypes.NFT721_ACCESS

        sa = ServiceAgreement.from_ddo(service_type, asset)
        return self._validate_nft_access(agreement_id, did, consumer_address, sa, service_type)
Ejemplo n.º 3
0
    def process_condition_events(self,
                                 agreement_id,
                                 conditions,
                                 did,
                                 consumer_address,
                                 block_number,
                                 new_agreement=True,
                                 template_id=None):

        ddo = DIDResolver(self._keeper.did_registry).resolve(did)

        cond_order = self._get_conditions_order(template_id)
        agreement_type = self._get_agreement_type(template_id)
        service_agreement = ddo.get_service(agreement_type)
        condition_def_dict = service_agreement.condition_by_name
        price = service_agreement.get_price()
        if new_agreement:
            start_time = int(datetime.now().timestamp())
            self.db.record_service_agreement(
                agreement_id, ddo.did, service_agreement.index, price,
                ddo.metadata.get('encryptedFiles'), consumer_address,
                start_time, block_number, agreement_type,
                service_agreement.condition_by_name.keys())

        condition_ids = service_agreement.generate_agreement_condition_ids(
            agreement_id=agreement_id,
            asset_id=ddo.asset_id,
            consumer_address=consumer_address,
            publisher_address=ddo.publisher,
            keeper=self._keeper)
        cond_to_id = {
            cond_order[i]: _id
            for i, _id in enumerate(condition_ids)
        }
        for cond in conditions:

            if cond == 'lockReward':
                if agreement_type == ServiceTypes.ASSET_ACCESS:
                    condition = lockRewardCondition.fulfillAccessSecretStoreCondition
                else:
                    condition = lockRewardExecutionCondition.fulfillExecComputeCondition
                self._keeper.lock_reward_condition.subscribe_condition_fulfilled(
                    agreement_id,
                    max(condition_def_dict['lockReward'].timeout,
                        self.EVENT_WAIT_TIMEOUT),
                    condition,
                    (agreement_id, ddo.did, service_agreement,
                     consumer_address, self._account, condition_ids[0]),
                    from_block=block_number)

            elif cond == 'accessSecretStore':
                self._keeper.access_secret_store_condition.subscribe_condition_fulfilled(
                    agreement_id,
                    max(condition_def_dict['accessSecretStore'].timeout,
                        self.EVENT_WAIT_TIMEOUT),
                    accessSecretStore.fulfillEscrowRewardCondition,
                    (agreement_id, service_agreement, price, consumer_address,
                     self._account, condition_ids, condition_ids[2]),
                    from_block=block_number)
            elif cond == 'execCompute':
                self._keeper.compute_execution_condition.subscribe_condition_fulfilled(
                    agreement_id,
                    max(condition_def_dict['execCompute'].timeout,
                        self.EVENT_WAIT_TIMEOUT),
                    accessSecretStore.fulfillEscrowRewardCondition,
                    (agreement_id, service_agreement, price, consumer_address,
                     self._account, condition_ids, condition_ids[2]),
                    from_block=block_number)
            elif cond == 'escrowReward':
                self._keeper.escrow_reward_condition.subscribe_condition_fulfilled(
                    agreement_id,
                    max(condition_def_dict['escrowReward'].timeout,
                        self.EVENT_WAIT_TIMEOUT),
                    self._last_condition_fulfilled, (agreement_id, cond_to_id),
                    from_block=block_number)