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:
parent
36a77c0d0b
commit
1f6e57fb60
@ -7,7 +7,8 @@ import {
|
|||||||
Condition,
|
Condition,
|
||||||
LockRewardCondition,
|
LockRewardCondition,
|
||||||
EscrowReward,
|
EscrowReward,
|
||||||
AccessSecretStoreCondition
|
AccessSecretStoreCondition,
|
||||||
|
ComputeExecutionCondition
|
||||||
} from './contracts/conditions'
|
} from './contracts/conditions'
|
||||||
import {
|
import {
|
||||||
AgreementTemplate,
|
AgreementTemplate,
|
||||||
@ -66,6 +67,9 @@ export class Keeper extends Instantiable {
|
|||||||
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
|
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
|
||||||
config
|
config
|
||||||
),
|
),
|
||||||
|
computeExecutionCondition: ComputeExecutionCondition.getInstance(
|
||||||
|
config
|
||||||
|
),
|
||||||
// Templates
|
// Templates
|
||||||
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(
|
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(
|
||||||
config
|
config
|
||||||
@ -98,7 +102,9 @@ export class Keeper extends Instantiable {
|
|||||||
lockRewardCondition: keeper.instances.lockRewardCondition,
|
lockRewardCondition: keeper.instances.lockRewardCondition,
|
||||||
escrowReward: keeper.instances.escrowReward,
|
escrowReward: keeper.instances.escrowReward,
|
||||||
accessSecretStoreCondition:
|
accessSecretStoreCondition:
|
||||||
keeper.instances.accessSecretStoreCondition
|
keeper.instances.accessSecretStoreCondition,
|
||||||
|
computeExecutionCondition:
|
||||||
|
keeper.instances.computeExecutionCondition
|
||||||
}
|
}
|
||||||
// Conditions
|
// Conditions
|
||||||
keeper.templates = {
|
keeper.templates = {
|
||||||
@ -163,6 +169,7 @@ export class Keeper extends Instantiable {
|
|||||||
lockRewardCondition: LockRewardCondition
|
lockRewardCondition: LockRewardCondition
|
||||||
escrowReward: EscrowReward
|
escrowReward: EscrowReward
|
||||||
accessSecretStoreCondition: AccessSecretStoreCondition
|
accessSecretStoreCondition: AccessSecretStoreCondition
|
||||||
|
computeExecutionCondition: ComputeExecutionCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
44
src/keeper/contracts/conditions/ComputeExecutionCondition.ts
Normal file
44
src/keeper/contracts/conditions/ComputeExecutionCondition.ts
Normal 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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -2,3 +2,4 @@ export * from './Condition.abstract'
|
|||||||
export { AccessSecretStoreCondition } from './AccessSecretStoreCondition'
|
export { AccessSecretStoreCondition } from './AccessSecretStoreCondition'
|
||||||
export { EscrowReward } from './EscrowReward'
|
export { EscrowReward } from './EscrowReward'
|
||||||
export { LockRewardCondition } from './LockRewardCondition'
|
export { LockRewardCondition } from './LockRewardCondition'
|
||||||
|
export { ComputeExecutionCondition } from './ComputeExecutionCondition'
|
||||||
|
@ -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.
|
* 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.
|
* This should be allowed after access has been given to the consumer and the asset data is downloaded.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user