mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Merge remote-tracking branch 'origin/feature/keeper-0.13' into feature/keeper-0.13
This commit is contained in:
commit
5439021e4a
@ -22,9 +22,9 @@ before_script:
|
|||||||
- git clone https://github.com/oceanprotocol/barge
|
- git clone https://github.com/oceanprotocol/barge
|
||||||
- cd barge
|
- cd barge
|
||||||
- export AQUARIUS_VERSION=v1.0.5
|
- export AQUARIUS_VERSION=v1.0.5
|
||||||
- export BRIZO_VERSION=v0.8.0
|
- export BRIZO_VERSION=v0.8.1
|
||||||
- export KEEPER_VERSION=v0.13.2
|
- export KEEPER_VERSION=v0.13.2
|
||||||
- export EVENTS_HANDLER_VERSION=v0.4.0
|
- export EVENTS_HANDLER_VERSION=v0.4.1
|
||||||
- export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"
|
- export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"
|
||||||
- rm -rf "${HOME}/.ocean/keeper-contracts/artifacts"
|
- rm -rf "${HOME}/.ocean/keeper-contracts/artifacts"
|
||||||
- bash -x start_ocean.sh --no-commons --no-dashboard 2>&1 > start_ocean.log &
|
- bash -x start_ocean.sh --no-commons --no-dashboard 2>&1 > start_ocean.log &
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "brizo",
|
"name": "brizo",
|
||||||
"version": "~0.8.0"
|
"version": "~0.8.1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "aquarius",
|
"name": "aquarius",
|
||||||
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "events-handler",
|
"name": "events-handler",
|
||||||
"version": "~0.4.0"
|
"version": "~0.4.1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -62,14 +62,7 @@ export class Keeper extends Instantiable {
|
|||||||
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
|
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
|
||||||
config
|
config
|
||||||
),
|
),
|
||||||
computeExecutionCondition: ComputeExecutionCondition.getInstance(config),
|
computeExecutionCondition: ComputeExecutionCondition.getInstance(config)
|
||||||
// Templates
|
|
||||||
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(
|
|
||||||
config
|
|
||||||
),
|
|
||||||
escrowComputeExecutionTemplate: EscrowComputeExecutionTemplate.getInstance(
|
|
||||||
config
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
keeper.connected = true
|
keeper.connected = true
|
||||||
@ -107,6 +100,19 @@ export class Keeper extends Instantiable {
|
|||||||
escrowComputeExecutionTemplate:
|
escrowComputeExecutionTemplate:
|
||||||
keeper.instances.escrowComputeExecutionTemplate
|
keeper.instances.escrowComputeExecutionTemplate
|
||||||
}
|
}
|
||||||
|
// Templates
|
||||||
|
keeper.instances.escrowAccessSecretStoreTemplate = new EscrowAccessSecretStoreTemplate(
|
||||||
|
keeper.instances.templateStoreManager,
|
||||||
|
keeper.instances.agreementStoreManager,
|
||||||
|
keeper.instances.didRegistry,
|
||||||
|
keeper.instances.conditions
|
||||||
|
)
|
||||||
|
keeper.instances.escrowComputeExecutionTemplate = new EscrowComputeExecutionTemplate(
|
||||||
|
keeper.instances.templateStoreManager,
|
||||||
|
keeper.instances.agreementStoreManager,
|
||||||
|
keeper.instances.didRegistry,
|
||||||
|
keeper.instances.conditions
|
||||||
|
)
|
||||||
// Utils
|
// Utils
|
||||||
keeper.utils = {
|
keeper.utils = {
|
||||||
eventHandler: new EventHandler(config)
|
eventHandler: new EventHandler(config)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Condition } from './Condition.abstract'
|
import { Condition } from './Condition.abstract'
|
||||||
import { zeroX, didZeroX, didPrefixed } from '../../../utils'
|
import { zeroX, didZeroX } from '../../../utils'
|
||||||
import { InstantiableConfig } from '../../../Instantiable.abstract'
|
import { InstantiableConfig } from '../../../Instantiable.abstract'
|
||||||
|
|
||||||
export class ComputeExecutionCondition extends Condition {
|
export class ComputeExecutionCondition extends Condition {
|
||||||
|
@ -15,11 +15,11 @@ export class AgreementStoreManager extends ContractBase {
|
|||||||
public static async getInstance(
|
public static async getInstance(
|
||||||
config: InstantiableConfig
|
config: InstantiableConfig
|
||||||
): Promise<AgreementStoreManager> {
|
): Promise<AgreementStoreManager> {
|
||||||
const templateStoreManeger: AgreementStoreManager = new AgreementStoreManager(
|
const templateStoreManager: AgreementStoreManager = new AgreementStoreManager(
|
||||||
'AgreementStoreManager'
|
'AgreementStoreManager'
|
||||||
)
|
)
|
||||||
await templateStoreManeger.init(config)
|
await templateStoreManager.init(config)
|
||||||
return templateStoreManeger
|
return templateStoreManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public getOwner(): Promise<string> {
|
public getOwner(): Promise<string> {
|
||||||
@ -44,4 +44,42 @@ export class AgreementStoreManager extends ContractBase {
|
|||||||
blockNumberUpdated: +blockNumberUpdated
|
blockNumberUpdated: +blockNumberUpdated
|
||||||
} as AgreementData
|
} as AgreementData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a agreement using EscrowComputeExecutionTemplate.
|
||||||
|
* @param {string} agreementId Generated agreement ID.
|
||||||
|
* @param {string} did Asset DID.
|
||||||
|
* @param {string} templateId Template ID.
|
||||||
|
* @param {string[]} conditionIds List of conditions IDs.
|
||||||
|
* @param {number[]} timeLocks Timelocks.
|
||||||
|
* @param {number[]} timeOuts Timeouts.
|
||||||
|
* @param {string[]} actors ETH account addresses of provider, consumer, etc.
|
||||||
|
* @param {string} from Action sender.
|
||||||
|
*
|
||||||
|
* @return {any} Transaction receipt.
|
||||||
|
*/
|
||||||
|
public async createAgreement(
|
||||||
|
agreementId: string,
|
||||||
|
did: string,
|
||||||
|
templateId: string,
|
||||||
|
conditionIds: string[],
|
||||||
|
timeLocks: number[],
|
||||||
|
timeOuts: number[],
|
||||||
|
actors: string[],
|
||||||
|
from?: string
|
||||||
|
): Promise<any> {
|
||||||
|
this.sendFrom(
|
||||||
|
'createAgreement',
|
||||||
|
[
|
||||||
|
zeroX(agreementId),
|
||||||
|
zeroX(did),
|
||||||
|
zeroX(templateId),
|
||||||
|
conditionIds.map(zeroX),
|
||||||
|
timeLocks,
|
||||||
|
timeOuts,
|
||||||
|
actors
|
||||||
|
],
|
||||||
|
from
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,38 +34,6 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
super(contractName)
|
super(contractName)
|
||||||
}
|
}
|
||||||
|
|
||||||
public createAgreement(
|
|
||||||
agreementId: string,
|
|
||||||
did: string,
|
|
||||||
conditionIds: string[],
|
|
||||||
timeLocks: number[],
|
|
||||||
timeOuts: number[],
|
|
||||||
...args: any[]
|
|
||||||
)
|
|
||||||
|
|
||||||
public createAgreement(
|
|
||||||
agreementId: string,
|
|
||||||
did: string,
|
|
||||||
conditionIds: string[],
|
|
||||||
timeLocks: number[],
|
|
||||||
timeOuts: number[],
|
|
||||||
extraArgs: any[],
|
|
||||||
from?: string
|
|
||||||
) {
|
|
||||||
return this.sendFrom(
|
|
||||||
'createAgreement',
|
|
||||||
[
|
|
||||||
zeroX(agreementId),
|
|
||||||
zeroX(did),
|
|
||||||
conditionIds.map(zeroX),
|
|
||||||
timeLocks,
|
|
||||||
timeOuts,
|
|
||||||
...extraArgs
|
|
||||||
],
|
|
||||||
from
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conditions address list.
|
* Conditions address list.
|
||||||
* @return {Promise<string[]>} Conditions address.
|
* @return {Promise<string[]>} Conditions address.
|
||||||
@ -91,7 +59,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
* @param {string} from Consumer address.
|
* @param {string} from Consumer address.
|
||||||
* @return {Promise<string[]>} Condition IDs.
|
* @return {Promise<string[]>} Condition IDs.
|
||||||
*/
|
*/
|
||||||
public abstract getAgreementIdsFromDDO(
|
public abstract getConditionIdsFromDDO(
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
ddo: DDO,
|
ddo: DDO,
|
||||||
consumer: string,
|
consumer: string,
|
||||||
|
125
src/keeper/contracts/templates/AgreementTemplateBase.ts
Normal file
125
src/keeper/contracts/templates/AgreementTemplateBase.ts
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate'
|
||||||
|
import { TemplateStoreManager, AgreementStoreManager } from '../managers'
|
||||||
|
import DIDRegistry from '../DIDRegistry'
|
||||||
|
import { LockRewardCondition } from '../conditions/LockRewardCondition'
|
||||||
|
import { AccessSecretStoreCondition } from '../conditions/AccessSecretStoreCondition'
|
||||||
|
import { EscrowReward } from '../conditions/EscrowReward'
|
||||||
|
import { DDO } from '../../../ddo/DDO'
|
||||||
|
import { generateId, zeroX } from '../../../utils'
|
||||||
|
import { ComputeExecutionCondition } from '../conditions'
|
||||||
|
|
||||||
|
export interface Conditions {
|
||||||
|
lockRewardCondition: LockRewardCondition
|
||||||
|
accessSecretStoreCondition?: AccessSecretStoreCondition
|
||||||
|
computeExecutionCondition?: ComputeExecutionCondition
|
||||||
|
escrowReward: EscrowReward
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AgreementTemplateBase {
|
||||||
|
public static templateName: string
|
||||||
|
|
||||||
|
public templateManager: TemplateStoreManager
|
||||||
|
|
||||||
|
public agreementStoreManager: AgreementStoreManager
|
||||||
|
|
||||||
|
public didRegistry: DIDRegistry
|
||||||
|
|
||||||
|
public conditions: Conditions
|
||||||
|
|
||||||
|
public constructor(
|
||||||
|
templateManager: TemplateStoreManager,
|
||||||
|
agreementStoreManager: AgreementStoreManager,
|
||||||
|
didRegistry: DIDRegistry,
|
||||||
|
conditions: Conditions
|
||||||
|
) {
|
||||||
|
this.templateManager = templateManager
|
||||||
|
this.agreementStoreManager = agreementStoreManager
|
||||||
|
this.didRegistry = didRegistry
|
||||||
|
this.conditions = conditions
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getServiceAgreementTemplate() {
|
||||||
|
return escrowAccessServiceAgreementTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createAgreementFromDDO(
|
||||||
|
agreementId: string,
|
||||||
|
ddo: DDO,
|
||||||
|
consumer: string,
|
||||||
|
from?: string
|
||||||
|
) {
|
||||||
|
return !!(await this.createFullAgreement(
|
||||||
|
ddo.shortId(),
|
||||||
|
ddo.findServiceByType('metadata').attributes.main.price,
|
||||||
|
consumer,
|
||||||
|
from,
|
||||||
|
agreementId
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getConditionIdsFromDDO(
|
||||||
|
agreementId: string,
|
||||||
|
ddo: DDO,
|
||||||
|
consumer: string,
|
||||||
|
from?: string
|
||||||
|
) {
|
||||||
|
const conditionIds = await this.createFullAgreementData(
|
||||||
|
agreementId,
|
||||||
|
ddo.shortId(),
|
||||||
|
ddo.findServiceByType('metadata').attributes.main.price,
|
||||||
|
consumer
|
||||||
|
)
|
||||||
|
return conditionIds
|
||||||
|
}
|
||||||
|
|
||||||
|
public getId() {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a agreement using EscrowAccessSecretStoreTemplate using only the most important information.
|
||||||
|
* @param {string} did Asset DID.
|
||||||
|
* @param {number} amount Asset price.
|
||||||
|
* @param {string} from Consumer address.
|
||||||
|
*
|
||||||
|
* @return {Promise<string>} Agreement ID.
|
||||||
|
*/
|
||||||
|
public async createFullAgreement(
|
||||||
|
did: string,
|
||||||
|
amount: number | string,
|
||||||
|
consumer: string,
|
||||||
|
from?: string,
|
||||||
|
agreementId: string = generateId()
|
||||||
|
): Promise<string> {
|
||||||
|
const conditionIds = await this.createFullAgreementData(
|
||||||
|
agreementId,
|
||||||
|
did,
|
||||||
|
amount,
|
||||||
|
consumer
|
||||||
|
)
|
||||||
|
|
||||||
|
const publisher = await this.didRegistry.getDIDOwner(did)
|
||||||
|
|
||||||
|
await this.agreementStoreManager.createAgreement(
|
||||||
|
agreementId,
|
||||||
|
did,
|
||||||
|
this.getId(),
|
||||||
|
conditionIds,
|
||||||
|
[0, 0, 0],
|
||||||
|
[0, 0, 0],
|
||||||
|
[consumer, publisher],
|
||||||
|
from
|
||||||
|
)
|
||||||
|
|
||||||
|
return zeroX(agreementId)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async createFullAgreementData(
|
||||||
|
agreementId: string,
|
||||||
|
did: string,
|
||||||
|
amount: number | string,
|
||||||
|
consumer: string
|
||||||
|
): Promise<any> {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +0,0 @@
|
|||||||
import { AgreementTemplate } from './AgreementTemplate.abstract'
|
|
||||||
import { DDO } from '../../../ddo/DDO'
|
|
||||||
import { generateId, zeroX } from '../../../utils'
|
|
||||||
import { InstantiableConfig } from '../../../Instantiable.abstract'
|
|
||||||
|
|
||||||
// import { EscrowComputeExecutionTemplateServiceAgreementTemplate } from './EscrowComputeExecutionTemplate.serviceAgreementTemplate'
|
|
||||||
|
|
||||||
export abstract class BaseEscrowTemplate extends AgreementTemplate {
|
|
||||||
/**
|
|
||||||
* Create a agreement using EscrowComputeExecutionTemplate.
|
|
||||||
* @param {string} agreementId Generated agreement ID.
|
|
||||||
* @param {string} did Asset DID.
|
|
||||||
* @param {string[]} conditionIds List of conditions IDs.
|
|
||||||
* @param {number[]} timeLocks Timelocks.
|
|
||||||
* @param {number[]} timeOuts Timeouts.
|
|
||||||
* @param {string} accessConsumer Consumer address.
|
|
||||||
* @param {string} from Action sender.
|
|
||||||
* @param {any} Transaction receipt.
|
|
||||||
*/
|
|
||||||
public createAgreement(
|
|
||||||
agreementId: string,
|
|
||||||
did: string,
|
|
||||||
conditionIds: string[],
|
|
||||||
timeLocks: number[],
|
|
||||||
timeOuts: number[],
|
|
||||||
accessConsumer: string,
|
|
||||||
from?: string
|
|
||||||
) {
|
|
||||||
return super.createAgreement(
|
|
||||||
agreementId,
|
|
||||||
did,
|
|
||||||
conditionIds,
|
|
||||||
timeLocks,
|
|
||||||
timeOuts,
|
|
||||||
[accessConsumer],
|
|
||||||
from
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getAgreementData(agreementId: string) {
|
|
||||||
return this.call<any>('getAgreementData', [zeroX(agreementId)])
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
||||||
|
|
||||||
export const escrowAccessSecretStoreTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
|
export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = {
|
||||||
contractName: 'EscrowAccessSecretStoreTemplate',
|
contractName: 'EscrowAccessSecretStoreTemplate',
|
||||||
events: [
|
events: [
|
||||||
{
|
{
|
@ -1,108 +1,26 @@
|
|||||||
import { AgreementTemplate } from './AgreementTemplate.abstract'
|
import { AgreementTemplateBase } from './AgreementTemplateBase'
|
||||||
import { BaseEscrowTemplate } from './BaseEscrowTemplate.abstract'
|
import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate'
|
||||||
import { DDO } from '../../../ddo/DDO'
|
|
||||||
import { generateId, zeroX } from '../../../utils'
|
|
||||||
import { InstantiableConfig } from '../../../Instantiable.abstract'
|
|
||||||
|
|
||||||
import { escrowAccessSecretStoreTemplateServiceAgreementTemplate } from './EscrowAccessSecretStoreTemplate.serviceAgreementTemplate'
|
export class EscrowAccessSecretStoreTemplate extends AgreementTemplateBase {
|
||||||
|
public static templateName: 'EscrowAccessSecretStoreTemplate'
|
||||||
export class EscrowAccessSecretStoreTemplate extends BaseEscrowTemplate {
|
|
||||||
public static async getInstance(
|
|
||||||
config: InstantiableConfig
|
|
||||||
): Promise<EscrowAccessSecretStoreTemplate> {
|
|
||||||
return AgreementTemplate.getInstance(
|
|
||||||
config,
|
|
||||||
'EscrowAccessSecretStoreTemplate',
|
|
||||||
EscrowAccessSecretStoreTemplate
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getServiceAgreementTemplate() {
|
public async getServiceAgreementTemplate() {
|
||||||
return escrowAccessSecretStoreTemplateServiceAgreementTemplate
|
return escrowAccessServiceAgreementTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createAgreementFromDDO(
|
protected async createFullAgreementData(
|
||||||
agreementId: string,
|
|
||||||
ddo: DDO,
|
|
||||||
consumer: string,
|
|
||||||
from?: string
|
|
||||||
) {
|
|
||||||
return !!(await this.createFullAgreement(
|
|
||||||
ddo.shortId(),
|
|
||||||
ddo.findServiceByType('metadata').attributes.main.price,
|
|
||||||
consumer,
|
|
||||||
from,
|
|
||||||
agreementId
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getAgreementIdsFromDDO(
|
|
||||||
agreementId: string,
|
|
||||||
ddo: DDO,
|
|
||||||
consumer: string,
|
|
||||||
from?: string
|
|
||||||
) {
|
|
||||||
const {
|
|
||||||
accessSecretStoreConditionId,
|
|
||||||
lockRewardConditionId,
|
|
||||||
escrowRewardId
|
|
||||||
} = await this.createFullAgreementData(
|
|
||||||
agreementId,
|
|
||||||
ddo.shortId(),
|
|
||||||
ddo.findServiceByType('metadata').attributes.main.price,
|
|
||||||
consumer
|
|
||||||
)
|
|
||||||
return [accessSecretStoreConditionId, lockRewardConditionId, escrowRewardId]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a agreement using EscrowAccessSecretStoreTemplate using only the most important information.
|
|
||||||
* @param {string} did Asset DID.
|
|
||||||
* @param {number} amount Asset price.
|
|
||||||
* @param {string} from Consumer address.
|
|
||||||
* @return {Promise<string>} Agreement ID.
|
|
||||||
*/
|
|
||||||
public async createFullAgreement(
|
|
||||||
did: string,
|
|
||||||
amount: number | string,
|
|
||||||
consumer: string,
|
|
||||||
from?: string,
|
|
||||||
agreementId: string = generateId()
|
|
||||||
): Promise<string> {
|
|
||||||
const {
|
|
||||||
accessSecretStoreConditionId,
|
|
||||||
lockRewardConditionId,
|
|
||||||
escrowRewardId
|
|
||||||
} = await this.createFullAgreementData(agreementId, did, amount, consumer)
|
|
||||||
|
|
||||||
await this.createAgreement(
|
|
||||||
agreementId,
|
|
||||||
did,
|
|
||||||
[accessSecretStoreConditionId, lockRewardConditionId, escrowRewardId],
|
|
||||||
[0, 0, 0],
|
|
||||||
[0, 0, 0],
|
|
||||||
consumer,
|
|
||||||
from
|
|
||||||
)
|
|
||||||
|
|
||||||
return zeroX(agreementId)
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createFullAgreementData(
|
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
did: string,
|
did: string,
|
||||||
amount: number | string,
|
amount: number | string,
|
||||||
consumer: string
|
consumer: string
|
||||||
) {
|
) {
|
||||||
const { didRegistry, conditions } = this.ocean.keeper
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
accessSecretStoreCondition,
|
|
||||||
lockRewardCondition,
|
lockRewardCondition,
|
||||||
|
accessSecretStoreCondition,
|
||||||
escrowReward
|
escrowReward
|
||||||
} = conditions
|
} = this.conditions
|
||||||
|
|
||||||
const publisher = await didRegistry.getDIDOwner(did)
|
const publisher = await this.didRegistry.getDIDOwner(did)
|
||||||
|
|
||||||
const lockRewardConditionId = await lockRewardCondition.generateIdHash(
|
const lockRewardConditionId = await lockRewardCondition.generateIdHash(
|
||||||
agreementId,
|
agreementId,
|
||||||
@ -123,10 +41,6 @@ export class EscrowAccessSecretStoreTemplate extends BaseEscrowTemplate {
|
|||||||
accessSecretStoreConditionId
|
accessSecretStoreConditionId
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return [lockRewardConditionId, accessSecretStoreConditionId, escrowRewardId]
|
||||||
lockRewardConditionId,
|
|
||||||
accessSecretStoreConditionId,
|
|
||||||
escrowRewardId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
||||||
|
|
||||||
export const escrowComputeExecutionTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
|
export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = {
|
||||||
contractName: 'EscrowComputeExecutionTemplate',
|
contractName: 'EscrowComputeExecutionTemplate',
|
||||||
events: [
|
events: [
|
||||||
{
|
{
|
@ -1,108 +1,26 @@
|
|||||||
import { AgreementTemplate } from './AgreementTemplate.abstract'
|
import { AgreementTemplateBase } from './AgreementTemplateBase'
|
||||||
import { BaseEscrowTemplate } from './BaseEscrowTemplate.abstract'
|
import { escrowComputeServiceAgreementTemplate } from './EscrowCompute.serviceAgreementTemplate'
|
||||||
import { DDO } from '../../../ddo/DDO'
|
|
||||||
import { generateId, zeroX } from '../../../utils'
|
|
||||||
import { InstantiableConfig } from '../../../Instantiable.abstract'
|
|
||||||
|
|
||||||
import { escrowComputeExecutionTemplateServiceAgreementTemplate } from './EscrowComputeExecutionTemplate.serviceAgreementTemplate'
|
export class EscrowComputeExecutionTemplate extends AgreementTemplateBase {
|
||||||
|
public static templateName: 'EscrowComputeExecutionTemplate'
|
||||||
export class EscrowComputeExecutionTemplate extends BaseEscrowTemplate {
|
|
||||||
public static async getInstance(
|
|
||||||
config: InstantiableConfig
|
|
||||||
): Promise<EscrowComputeExecutionTemplate> {
|
|
||||||
return AgreementTemplate.getInstance(
|
|
||||||
config,
|
|
||||||
'EscrowComputeExecutionTemplate',
|
|
||||||
EscrowComputeExecutionTemplate
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getServiceAgreementTemplate() {
|
public async getServiceAgreementTemplate() {
|
||||||
return escrowComputeExecutionTemplateServiceAgreementTemplate
|
return escrowComputeServiceAgreementTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createAgreementFromDDO(
|
protected async createFullAgreementData(
|
||||||
agreementId: string,
|
|
||||||
ddo: DDO,
|
|
||||||
consumer: string,
|
|
||||||
from?: string
|
|
||||||
) {
|
|
||||||
return !!(await this.createFullAgreement(
|
|
||||||
ddo.shortId(),
|
|
||||||
ddo.findServiceByType('metadata').attributes.main.price,
|
|
||||||
consumer,
|
|
||||||
from,
|
|
||||||
agreementId
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getAgreementIdsFromDDO(
|
|
||||||
agreementId: string,
|
|
||||||
ddo: DDO,
|
|
||||||
consumer: string,
|
|
||||||
from?: string
|
|
||||||
) {
|
|
||||||
const {
|
|
||||||
computeExecutionConditionId,
|
|
||||||
lockRewardConditionId,
|
|
||||||
escrowRewardId
|
|
||||||
} = await this.createFullAgreementData(
|
|
||||||
agreementId,
|
|
||||||
ddo.shortId(),
|
|
||||||
ddo.findServiceByType('metadata').attributes.main.price,
|
|
||||||
consumer
|
|
||||||
)
|
|
||||||
return [computeExecutionConditionId, lockRewardConditionId, escrowRewardId]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a agreement using EscrowAccess____SecretStoreTemplate using only the most important information.
|
|
||||||
* @param {string} did Asset DID.
|
|
||||||
* @param {number} amount Asset price.
|
|
||||||
* @param {string} from Consumer address.
|
|
||||||
* @return {Promise<string>} Agreement ID.
|
|
||||||
*/
|
|
||||||
public async createFullAgreement(
|
|
||||||
did: string,
|
|
||||||
amount: number | string,
|
|
||||||
consumer: string,
|
|
||||||
from?: string,
|
|
||||||
agreementId: string = generateId()
|
|
||||||
): Promise<string> {
|
|
||||||
const {
|
|
||||||
computeExecutionConditionId,
|
|
||||||
lockRewardConditionId,
|
|
||||||
escrowRewardId
|
|
||||||
} = await this.createFullAgreementData(agreementId, did, amount, consumer)
|
|
||||||
|
|
||||||
await this.createAgreement(
|
|
||||||
agreementId,
|
|
||||||
did,
|
|
||||||
[computeExecutionConditionId, lockRewardConditionId, escrowRewardId],
|
|
||||||
[0, 0, 0],
|
|
||||||
[0, 0, 0],
|
|
||||||
consumer,
|
|
||||||
from
|
|
||||||
)
|
|
||||||
|
|
||||||
return zeroX(agreementId)
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createFullAgreementData(
|
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
did: string,
|
did: string,
|
||||||
amount: number | string,
|
amount: number | string,
|
||||||
consumer: string
|
consumer: string
|
||||||
) {
|
) {
|
||||||
const { didRegistry, conditions } = this.ocean.keeper
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
computeExecutionCondition,
|
|
||||||
lockRewardCondition,
|
lockRewardCondition,
|
||||||
|
computeExecutionCondition,
|
||||||
escrowReward
|
escrowReward
|
||||||
} = conditions
|
} = this.conditions
|
||||||
|
|
||||||
const publisher = await didRegistry.getDIDOwner(did)
|
const publisher = await this.didRegistry.getDIDOwner(did)
|
||||||
|
|
||||||
const lockRewardConditionId = await lockRewardCondition.generateIdHash(
|
const lockRewardConditionId = await lockRewardCondition.generateIdHash(
|
||||||
agreementId,
|
agreementId,
|
||||||
|
@ -57,7 +57,7 @@ export class OceanAgreements extends Instantiable {
|
|||||||
.serviceAgreementTemplate.contractName
|
.serviceAgreementTemplate.contractName
|
||||||
const agreementConditionsIds = await this.ocean.keeper
|
const agreementConditionsIds = await this.ocean.keeper
|
||||||
.getTemplateByName(templateName)
|
.getTemplateByName(templateName)
|
||||||
.getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
|
.getConditionIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
|
||||||
|
|
||||||
const signature = await this.ocean.utils.agreements.signServiceAgreement(
|
const signature = await this.ocean.utils.agreements.signServiceAgreement(
|
||||||
ddo,
|
ddo,
|
||||||
|
Loading…
Reference in New Issue
Block a user