1
0
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:
Pedro Gutiérrez 2019-02-13 13:05:08 +01:00 committed by Pedro Gutiérrez
parent 14f3955ed0
commit 2d4cd891b3
2 changed files with 8 additions and 15 deletions

View File

@ -14,7 +14,7 @@ describe("Buy Asset", () => {
let ddo: DDO let ddo: DDO
let did: DID let did: DID
let serviceAgreementSignatureResult: {serviceAgreementId: string, serviceAgreementSignature: string} let agreementId: string
let serviceAgreement: ServiceAgreement let serviceAgreement: ServiceAgreement
before(async () => { before(async () => {
@ -83,11 +83,9 @@ describe("Buy Asset", () => {
it("should sign the service agreement", async () => { it("should sign the service agreement", async () => {
const accessService = ddo.findServiceByType("Access") 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(agreementId, /^[a-f0-9]{64}$/, "Service agreement ID seems not valid")
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")
}) })
it("should execute the service agreement", async () => { it("should execute the service agreement", async () => {

View File

@ -172,20 +172,20 @@ export default class OceanAssets {
* @param {string} did Decentralized ID. * @param {string} did Decentralized ID.
* @param {string} serviceDefinitionId Service definition ID. * @param {string} serviceDefinitionId Service definition ID.
* @param {Account} consumer Consumer account. * @param {Account} consumer Consumer account.
* @return {Promise<{serviceAgreementId: string, serviceAgreementSignature: string}>} * @return {Promise<string>} Returns Agreement ID
*/ */
public async order( public async order(
did: string, did: string,
serviceDefinitionId: string, serviceDefinitionId: string,
consumer: Account, consumer: Account,
): Promise<{serviceAgreementId: string, serviceAgreementSignature: string}> { ): Promise<string> {
const d: DID = DID.parse(did as string) const d: DID = DID.parse(did as string)
const ddo = await AquariusProvider.getAquarius().retrieveDDO(d) const ddo = await AquariusProvider.getAquarius().retrieveDDO(d)
const serviceAgreementId: string = IdGenerator.generateId() const serviceAgreementId: string = IdGenerator.generateId()
try { try {
const serviceAgreementSignature: string = await ServiceAgreement.signServiceAgreement( await ServiceAgreement.signServiceAgreement(
ddo, serviceDefinitionId, serviceAgreementId, consumer) ddo, serviceDefinitionId, serviceAgreementId, consumer)
const accessService: Service = ddo.findServiceByType("Access") const accessService: Service = ddo.findServiceByType("Access")
@ -204,23 +204,18 @@ export default class OceanAssets {
}) })
event.listenOnce(async (data) => { event.listenOnce(async (data) => {
const sa: ServiceAgreement = new ServiceAgreement(data.returnValues.agreementId) const sa: ServiceAgreement = new ServiceAgreement(data.returnValues.agreementId)
await sa.payAsset( await sa.payAsset(
d.getId(), d.getId(),
metadataService.metadata.base.price, metadataService.metadata.base.price,
consumer, consumer,
) )
Logger.log("Completed asset payment, now access should be granted.")
}) })
return { return serviceAgreementId
serviceAgreementId,
serviceAgreementSignature,
}
} catch (err) { } catch (err) {
Logger.error("Signing ServiceAgreement failed!", err) throw new Error("Signing ServiceAgreement failed: " + err)
} }
} }