From 136250b70c26ca9dbd803e0ebbee694d5a8186e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Thu, 7 Mar 2019 15:57:43 +0100 Subject: [PATCH] Move access service template used on the DDO to each agreement template. --- src/brizo/Brizo.ts | 1 + .../templates/AgreementTemplate.abstract.ts | 8 + ...tStoreTemplate.serviceAgreementTemplate.ts | 145 ++++++++++++++++++ .../EscrowAccessSecretStoreTemplate.ts | 7 + 4 files changed, 161 insertions(+) create mode 100644 src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index be8265d..0e5669d 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -55,6 +55,7 @@ export default class Brizo { decodeURI(JSON.stringify(args)), ) } catch (e) { + Logger.error(e) throw new Error("HTTP request failed") } } diff --git a/src/keeper/contracts/templates/AgreementTemplate.abstract.ts b/src/keeper/contracts/templates/AgreementTemplate.abstract.ts index 081ad12..659c7bb 100644 --- a/src/keeper/contracts/templates/AgreementTemplate.abstract.ts +++ b/src/keeper/contracts/templates/AgreementTemplate.abstract.ts @@ -1,6 +1,7 @@ import ContractBase from "../ContractBase" import { Condition } from "../conditions/Condition.abstract" import Keeper from "../../Keeper" +import { ServiceAgreementTemplate, ServiceAgreementTemplateCondition } from '../../../ddo/ServiceAgreementTemplate' import { zeroX } from "../../../utils" export abstract class AgreementTemplate extends ContractBase { @@ -50,4 +51,11 @@ export abstract class AgreementTemplate extends ContractBase { .map(address => keeper.getConditionByAddress(address)) } + + abstract getServiceAgreementTemplate(): Promise + + public async getServiceAgreementTemplateConditions(): Promise { + const serviceAgreementTemplate = await this.getServiceAgreementTemplate() + return serviceAgreementTemplate.conditions + } } diff --git a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts new file mode 100644 index 0000000..a04ac65 --- /dev/null +++ b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts @@ -0,0 +1,145 @@ +import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate' + +export const escrowAccessSecretStoreTemplateServiceAgreementTemplate: ServiceAgreementTemplate = { + "contractName": "EscrowAccessSecretStoreTemplate", + "events": [ + { + "name": "AgreementCreated", + "actorType": "consumer", + "handler": { + "moduleName": "escrowAccessSecretStoreTemplate", + "functionName": "fulfillLockRewardCondition", + "version": "0.1" + } + } + ], + "fulfillmentOrder": [ + "lockReward.fulfill", + "accessSecretStore.fulfill", + "escrowReward.fulfill" + ], + "conditionDependency": { + "lockReward": [], + "grantSecretStoreAccess": [], + "releaseReward": [ + "lockReward", + "accessSecretStore" + ] + }, + "conditions": [ + { + "name": "lockReward", + "timelock": 0, + "timeout": 0, + "contractName": "LockRewardCondition", + "functionName": "fulfill", + "parameters": [ + { + "name": "_rewardAddress", + "type": "address", + "value": "" + }, + { + "name": "_amount", + "type": "uint256", + "value": "" + } + ], + "events": [ + { + "name": "Fulfilled", + "actorType": "publisher", + "handler": { + "moduleName": "lockRewardCondition", + "functionName": "fulfillAccessSecretStoreCondition", + "version": "0.1" + } + } + ] + }, + { + "name": "accessSecretStore", + "timelock": 0, + "timeout": 0, + "contractName": "AccessSecretStoreCondition", + "functionName": "fulfill", + "parameters": [ + { + "name": "_documentId", + "type": "bytes32", + "value": "" + }, + { + "name": "_grantee", + "type": "address", + "value": "" + } + ], + "events": [ + { + "name": "Fulfilled", + "actorType": "publisher", + "handler": { + "moduleName": "accessSecretStore", + "functionName": "fulfillEscrowRewardCondition", + "version": "0.1" + } + }, + { + "name": "TimedOut", + "actorType": "consumer", + "handler": { + "moduleName": "accessSecretStore", + "functionName": "fulfillEscrowRewardCondition", + "version": "0.1" + } + } + ] + }, + { + "name": "escrowReward", + "timelock": 0, + "timeout": 0, + "contractName": "EscrowReward", + "functionName": "fulfill", + "parameters": [ + { + "name": "_amount", + "type": "uint256", + "value": "" + }, + { + "name": "_receiver", + "type": "address", + "value": "" + }, + { + "name": "_sender", + "type": "address", + "value": "" + }, + { + "name": "_lockCondition", + "type": "bytes32", + "value": "" + }, + { + "name": "_releaseCondition", + "type": "bytes32", + "value": "" + } + ], + "events": [ + { + "name": "Fulfilled", + "actorType": "publisher", + "handler": { + "moduleName": "escrowRewardCondition", + "functionName": "verifyRewardTokens", + "version": "0.1" + } + } + ] + } + ] +} diff --git a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts index 742285b..53fef2c 100644 --- a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts +++ b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts @@ -3,12 +3,18 @@ import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from '. import DIDRegistry from '../DIDRegistry' import { generateId } from '../../../utils/GeneratorHelpers' +import { escrowAccessSecretStoreTemplateServiceAgreementTemplate } from "./EscrowAccessSecretStoreTemplate.serviceAgreementTemplate" + export class EscrowAccessSecretStoreTemplate extends AgreementTemplate { public static async getInstance(): Promise { return AgreementTemplate.getInstance("EscrowAccessSecretStoreTemplate", EscrowAccessSecretStoreTemplate) } + public async getServiceAgreementTemplate() { + return escrowAccessSecretStoreTemplateServiceAgreementTemplate + } + /** * Create a agreement using EscrowAccessSecretStoreTemplate. * @param {string} agreementId Generated agreement ID. @@ -69,6 +75,7 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate { conditionIdLock, conditionIdAccess, ) + await this.createAgreement( agreementId, did,