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

Detect the error when a condition is not correctly fulfilled.

This commit is contained in:
Pedro Gutiérrez 2019-07-09 11:39:22 +02:00
parent 031720ad5d
commit d3f15e361a

View File

@ -35,19 +35,24 @@ export class OceanAgreementsConditions extends Instantiable {
escrowReward escrowReward
} = this.ocean.keeper.conditions } = this.ocean.keeper.conditions
await this.ocean.keeper.token.approve( try {
lockRewardCondition.getAddress(), await this.ocean.keeper.token.approve(
amount, lockRewardCondition.getAddress(),
from.getId() amount,
) from.getId()
)
const receipt = await lockRewardCondition.fulfill( const receipt = await lockRewardCondition.fulfill(
agreementId, agreementId,
escrowReward.getAddress(), escrowReward.getAddress(),
amount, amount,
from && from.getId() from && from.getId()
) )
return !!receipt.events.Fulfilled
return !!receipt.events.Fulfilled
} catch {
return false
}
} }
/** /**
@ -63,15 +68,19 @@ export class OceanAgreementsConditions extends Instantiable {
grantee: string, grantee: string,
from?: Account from?: Account
) { ) {
const { accessSecretStoreCondition } = this.ocean.keeper.conditions try {
const { accessSecretStoreCondition } = this.ocean.keeper.conditions
const receipt = await accessSecretStoreCondition.fulfill( const receipt = await accessSecretStoreCondition.fulfill(
agreementId, agreementId,
did, did,
grantee, grantee,
from && from.getId() from && from.getId()
) )
return !!receipt.events.Fulfilled return !!receipt.events.Fulfilled
} catch {
return false
}
} }
/** /**
@ -95,32 +104,36 @@ export class OceanAgreementsConditions extends Instantiable {
publisher: string, publisher: string,
from?: Account from?: Account
) { ) {
const { try {
escrowReward, const {
accessSecretStoreCondition, escrowReward,
lockRewardCondition accessSecretStoreCondition,
} = this.ocean.keeper.conditions lockRewardCondition
} = this.ocean.keeper.conditions
const conditionIdAccess = await accessSecretStoreCondition.generateIdHash( const conditionIdAccess = await accessSecretStoreCondition.generateIdHash(
agreementId, agreementId,
did, did,
consumer consumer
) )
const conditionIdLock = await lockRewardCondition.generateIdHash( const conditionIdLock = await lockRewardCondition.generateIdHash(
agreementId, agreementId,
escrowReward.getAddress(), escrowReward.getAddress(),
amount amount
) )
const receipt = await escrowReward.fulfill( const receipt = await escrowReward.fulfill(
agreementId, agreementId,
amount, amount,
publisher, publisher,
consumer, consumer,
conditionIdLock, conditionIdLock,
conditionIdAccess, conditionIdAccess,
from && from.getId() from && from.getId()
) )
return !!receipt.events.Fulfilled return !!receipt.events.Fulfilled
} catch {
return false
}
} }
} }