1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Add ComputeExecutionCondition.

This commit is contained in:
Pedro Gutiérrez 2019-09-05 13:32:56 +02:00 committed by Matthias Kretschmann
parent 36a77c0d0b
commit 1f6e57fb60
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 82 additions and 2 deletions

View File

@ -7,7 +7,8 @@ import {
Condition,
LockRewardCondition,
EscrowReward,
AccessSecretStoreCondition
AccessSecretStoreCondition,
ComputeExecutionCondition
} from './contracts/conditions'
import {
AgreementTemplate,
@ -66,6 +67,9 @@ export class Keeper extends Instantiable {
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
config
),
computeExecutionCondition: ComputeExecutionCondition.getInstance(
config
),
// Templates
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(
config
@ -98,7 +102,9 @@ export class Keeper extends Instantiable {
lockRewardCondition: keeper.instances.lockRewardCondition,
escrowReward: keeper.instances.escrowReward,
accessSecretStoreCondition:
keeper.instances.accessSecretStoreCondition
keeper.instances.accessSecretStoreCondition,
computeExecutionCondition:
keeper.instances.computeExecutionCondition
}
// Conditions
keeper.templates = {
@ -163,6 +169,7 @@ export class Keeper extends Instantiable {
lockRewardCondition: LockRewardCondition
escrowReward: EscrowReward
accessSecretStoreCondition: AccessSecretStoreCondition
computeExecutionCondition: ComputeExecutionCondition
}
/**

View File

@ -0,0 +1,44 @@
import { Condition } from './Condition.abstract'
import { zeroX, didZeroX, didPrefixed } from '../../../utils'
import { InstantiableConfig } from '../../../Instantiable.abstract'
export class ComputeExecutionCondition extends Condition {
public static async getInstance(
config: InstantiableConfig
): Promise<ComputeExecutionCondition> {
return Condition.getInstance(
config,
'ComputeExecutionCondition',
ComputeExecutionCondition
)
}
public hashValues(did: string, computeConsumer: string) {
return super.hashValues(didZeroX(did), zeroX(computeConsumer))
}
public fulfill(
agreementId: string,
did: string,
computeConsumer: string,
from?: string
) {
return super.fulfill(
agreementId,
[didZeroX(did), computeConsumer].map(zeroX),
from
)
}
public wasComputeTriggered(
did: string,
computeConsumer: string,
from?: string
) {
return this.call<boolean>(
'wasComputeTriggered',
[didZeroX(did), computeConsumer].map(zeroX),
from
)
}
}

View File

@ -2,3 +2,4 @@ export * from './Condition.abstract'
export { AccessSecretStoreCondition } from './AccessSecretStoreCondition'
export { EscrowReward } from './EscrowReward'
export { LockRewardCondition } from './LockRewardCondition'
export { ComputeExecutionCondition } from './ComputeExecutionCondition'

View File

@ -83,6 +83,34 @@ export class OceanAgreementsConditions extends Instantiable {
}
}
/**
* Authorize the consumer defined in the agreement to execute a remote service associated with this asset.
* @param {string} agreementId Agreement ID.
* @param {string} did Asset ID.
* @param {string} grantee Consumer address.
* @param {Account} from Account of sender.
*/
public async grantServiceExecution(
agreementId: string,
did: string,
grantee: string,
from?: Account
) {
try {
const { computeExecutionCondition } = this.ocean.keeper.conditions
const receipt = await computeExecutionCondition.fulfill(
agreementId,
did,
grantee,
from && from.getId()
)
return !!receipt.events.Fulfilled
} catch {
return false
}
}
/**
* Transfer the escrow or locked tokens from the LockRewardCondition contract to the publisher's account.
* This should be allowed after access has been given to the consumer and the asset data is downloaded.