mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
changed returning data of asset.create
This commit is contained in:
parent
14f3955ed0
commit
2d4cd891b3
@ -14,7 +14,7 @@ describe("Buy Asset", () => {
|
||||
|
||||
let ddo: DDO
|
||||
let did: DID
|
||||
let serviceAgreementSignatureResult: {serviceAgreementId: string, serviceAgreementSignature: string}
|
||||
let agreementId: string
|
||||
let serviceAgreement: ServiceAgreement
|
||||
|
||||
before(async () => {
|
||||
@ -83,11 +83,9 @@ describe("Buy Asset", () => {
|
||||
it("should sign the service agreement", async () => {
|
||||
const accessService = ddo.findServiceByType("Access")
|
||||
|
||||
serviceAgreementSignatureResult = await ocean.assets.order(ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
agreementId = await ocean.assets.order(ddo.id, accessService.serviceDefinitionId, consumer)
|
||||
|
||||
const {serviceAgreementId, serviceAgreementSignature} = serviceAgreementSignatureResult
|
||||
assert.match(serviceAgreementId, /^[a-f0-9]{64}$/, "Service agreement ID seems not valid")
|
||||
assert.match(serviceAgreementSignature, /^0x[a-f0-9]{130}$/, "Service agreement signature seems not valid")
|
||||
assert.match(agreementId, /^[a-f0-9]{64}$/, "Service agreement ID seems not valid")
|
||||
})
|
||||
|
||||
it("should execute the service agreement", async () => {
|
||||
|
@ -172,20 +172,20 @@ export default class OceanAssets {
|
||||
* @param {string} did Decentralized ID.
|
||||
* @param {string} serviceDefinitionId Service definition ID.
|
||||
* @param {Account} consumer Consumer account.
|
||||
* @return {Promise<{serviceAgreementId: string, serviceAgreementSignature: string}>}
|
||||
* @return {Promise<string>} Returns Agreement ID
|
||||
*/
|
||||
public async order(
|
||||
did: string,
|
||||
serviceDefinitionId: string,
|
||||
consumer: Account,
|
||||
): Promise<{serviceAgreementId: string, serviceAgreementSignature: string}> {
|
||||
): Promise<string> {
|
||||
|
||||
const d: DID = DID.parse(did as string)
|
||||
const ddo = await AquariusProvider.getAquarius().retrieveDDO(d)
|
||||
const serviceAgreementId: string = IdGenerator.generateId()
|
||||
|
||||
try {
|
||||
const serviceAgreementSignature: string = await ServiceAgreement.signServiceAgreement(
|
||||
await ServiceAgreement.signServiceAgreement(
|
||||
ddo, serviceDefinitionId, serviceAgreementId, consumer)
|
||||
|
||||
const accessService: Service = ddo.findServiceByType("Access")
|
||||
@ -204,23 +204,18 @@ export default class OceanAssets {
|
||||
})
|
||||
|
||||
event.listenOnce(async (data) => {
|
||||
|
||||
const sa: ServiceAgreement = new ServiceAgreement(data.returnValues.agreementId)
|
||||
await sa.payAsset(
|
||||
d.getId(),
|
||||
metadataService.metadata.base.price,
|
||||
consumer,
|
||||
)
|
||||
Logger.log("Completed asset payment, now access should be granted.")
|
||||
})
|
||||
|
||||
return {
|
||||
serviceAgreementId,
|
||||
serviceAgreementSignature,
|
||||
}
|
||||
return serviceAgreementId
|
||||
|
||||
} catch (err) {
|
||||
Logger.error("Signing ServiceAgreement failed!", err)
|
||||
throw new Error("Signing ServiceAgreement failed: " + err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user