1
0
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:
ssallam 2020-01-15 21:17:05 +01:00
commit 5439021e4a
13 changed files with 208 additions and 282 deletions

View File

@ -22,9 +22,9 @@ before_script:
- git clone https://github.com/oceanprotocol/barge
- cd barge
- 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 EVENTS_HANDLER_VERSION=v0.4.0
- export EVENTS_HANDLER_VERSION=v0.4.1
- export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"
- rm -rf "${HOME}/.ocean/keeper-contracts/artifacts"
- bash -x start_ocean.sh --no-commons --no-dashboard 2>&1 > start_ocean.log &

View File

@ -11,7 +11,7 @@
},
{
"name": "brizo",
"version": "~0.8.0"
"version": "~0.8.1"
},
{
"name": "aquarius",
@ -19,7 +19,7 @@
},
{
"name": "events-handler",
"version": "~0.4.0"
"version": "~0.4.1"
}
]
}

View File

@ -62,14 +62,7 @@ export class Keeper extends Instantiable {
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
config
),
computeExecutionCondition: ComputeExecutionCondition.getInstance(config),
// Templates
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(
config
),
escrowComputeExecutionTemplate: EscrowComputeExecutionTemplate.getInstance(
config
)
computeExecutionCondition: ComputeExecutionCondition.getInstance(config)
})
keeper.connected = true
@ -107,6 +100,19 @@ export class Keeper extends Instantiable {
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
keeper.utils = {
eventHandler: new EventHandler(config)

View File

@ -1,5 +1,5 @@
import { Condition } from './Condition.abstract'
import { zeroX, didZeroX, didPrefixed } from '../../../utils'
import { zeroX, didZeroX } from '../../../utils'
import { InstantiableConfig } from '../../../Instantiable.abstract'
export class ComputeExecutionCondition extends Condition {

View File

@ -15,11 +15,11 @@ export class AgreementStoreManager extends ContractBase {
public static async getInstance(
config: InstantiableConfig
): Promise<AgreementStoreManager> {
const templateStoreManeger: AgreementStoreManager = new AgreementStoreManager(
const templateStoreManager: AgreementStoreManager = new AgreementStoreManager(
'AgreementStoreManager'
)
await templateStoreManeger.init(config)
return templateStoreManeger
await templateStoreManager.init(config)
return templateStoreManager
}
public getOwner(): Promise<string> {
@ -44,4 +44,42 @@ export class AgreementStoreManager extends ContractBase {
blockNumberUpdated: +blockNumberUpdated
} 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
)
}
}

View File

@ -34,38 +34,6 @@ export abstract class AgreementTemplate extends ContractBase {
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.
* @return {Promise<string[]>} Conditions address.
@ -91,7 +59,7 @@ export abstract class AgreementTemplate extends ContractBase {
* @param {string} from Consumer address.
* @return {Promise<string[]>} Condition IDs.
*/
public abstract getAgreementIdsFromDDO(
public abstract getConditionIdsFromDDO(
agreementId: string,
ddo: DDO,
consumer: string,

View 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
}
}

View File

@ -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)])
}
}

View File

@ -1,6 +1,6 @@
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
export const escrowAccessSecretStoreTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = {
contractName: 'EscrowAccessSecretStoreTemplate',
events: [
{

View File

@ -1,108 +1,26 @@
import { AgreementTemplate } from './AgreementTemplate.abstract'
import { BaseEscrowTemplate } from './BaseEscrowTemplate.abstract'
import { DDO } from '../../../ddo/DDO'
import { generateId, zeroX } from '../../../utils'
import { InstantiableConfig } from '../../../Instantiable.abstract'
import { AgreementTemplateBase } from './AgreementTemplateBase'
import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate'
import { escrowAccessSecretStoreTemplateServiceAgreementTemplate } from './EscrowAccessSecretStoreTemplate.serviceAgreementTemplate'
export class EscrowAccessSecretStoreTemplate extends BaseEscrowTemplate {
public static async getInstance(
config: InstantiableConfig
): Promise<EscrowAccessSecretStoreTemplate> {
return AgreementTemplate.getInstance(
config,
'EscrowAccessSecretStoreTemplate',
EscrowAccessSecretStoreTemplate
)
}
export class EscrowAccessSecretStoreTemplate extends AgreementTemplateBase {
public static templateName: 'EscrowAccessSecretStoreTemplate'
public async getServiceAgreementTemplate() {
return escrowAccessSecretStoreTemplateServiceAgreementTemplate
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 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(
protected async createFullAgreementData(
agreementId: string,
did: string,
amount: number | string,
consumer: string
) {
const { didRegistry, conditions } = this.ocean.keeper
const {
accessSecretStoreCondition,
lockRewardCondition,
accessSecretStoreCondition,
escrowReward
} = conditions
} = this.conditions
const publisher = await didRegistry.getDIDOwner(did)
const publisher = await this.didRegistry.getDIDOwner(did)
const lockRewardConditionId = await lockRewardCondition.generateIdHash(
agreementId,
@ -123,10 +41,6 @@ export class EscrowAccessSecretStoreTemplate extends BaseEscrowTemplate {
accessSecretStoreConditionId
)
return {
lockRewardConditionId,
accessSecretStoreConditionId,
escrowRewardId
}
return [lockRewardConditionId, accessSecretStoreConditionId, escrowRewardId]
}
}

View File

@ -1,6 +1,6 @@
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
export const escrowComputeExecutionTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = {
contractName: 'EscrowComputeExecutionTemplate',
events: [
{

View File

@ -1,108 +1,26 @@
import { AgreementTemplate } from './AgreementTemplate.abstract'
import { BaseEscrowTemplate } from './BaseEscrowTemplate.abstract'
import { DDO } from '../../../ddo/DDO'
import { generateId, zeroX } from '../../../utils'
import { InstantiableConfig } from '../../../Instantiable.abstract'
import { AgreementTemplateBase } from './AgreementTemplateBase'
import { escrowComputeServiceAgreementTemplate } from './EscrowCompute.serviceAgreementTemplate'
import { escrowComputeExecutionTemplateServiceAgreementTemplate } from './EscrowComputeExecutionTemplate.serviceAgreementTemplate'
export class EscrowComputeExecutionTemplate extends BaseEscrowTemplate {
public static async getInstance(
config: InstantiableConfig
): Promise<EscrowComputeExecutionTemplate> {
return AgreementTemplate.getInstance(
config,
'EscrowComputeExecutionTemplate',
EscrowComputeExecutionTemplate
)
}
export class EscrowComputeExecutionTemplate extends AgreementTemplateBase {
public static templateName: 'EscrowComputeExecutionTemplate'
public async getServiceAgreementTemplate() {
return escrowComputeExecutionTemplateServiceAgreementTemplate
return escrowComputeServiceAgreementTemplate
}
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 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(
protected async createFullAgreementData(
agreementId: string,
did: string,
amount: number | string,
consumer: string
) {
const { didRegistry, conditions } = this.ocean.keeper
const {
computeExecutionCondition,
lockRewardCondition,
computeExecutionCondition,
escrowReward
} = conditions
} = this.conditions
const publisher = await didRegistry.getDIDOwner(did)
const publisher = await this.didRegistry.getDIDOwner(did)
const lockRewardConditionId = await lockRewardCondition.generateIdHash(
agreementId,

View File

@ -57,7 +57,7 @@ export class OceanAgreements extends Instantiable {
.serviceAgreementTemplate.contractName
const agreementConditionsIds = await this.ocean.keeper
.getTemplateByName(templateName)
.getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
.getConditionIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
const signature = await this.ocean.utils.agreements.signServiceAgreement(
ddo,