1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/src/ocean/Asset.ts
2018-11-05 14:56:14 +01:00

28 lines
948 B
TypeScript

import AquariusProvider from "../aquarius/AquariusProvider"
import Account from "./Account"
import IdGenerator from "./IdGenerator"
import OceanBase from "./OceanBase"
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
export default class Asset extends OceanBase {
constructor(public name: string,
public description: string,
public price: number,
public publisher: Account) {
super()
}
public async purchase(consumer: Account): Promise<ServiceAgreement> {
const did = `did:op:${this.getId()}`
const ddo = await AquariusProvider.getAquarius().retrieveDDO(did)
const serviceAgreementId: string = IdGenerator.generateId()
const serviceAgreement: ServiceAgreement = await ServiceAgreement.signServiceAgreement(this.getId(),
ddo, serviceAgreementId, consumer, this.publisher)
return serviceAgreement
}
}