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

28 lines
948 B
TypeScript
Raw Normal View History

2018-11-05 10:01:58 +01:00
import AquariusProvider from "../aquarius/AquariusProvider"
2018-10-16 14:56:18 +02:00
import Account from "./Account"
2018-11-05 10:01:58 +01:00
import IdGenerator from "./IdGenerator"
2018-10-09 10:55:53 +02:00
import OceanBase from "./OceanBase"
2018-11-05 14:56:14 +01:00
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
2018-10-16 14:56:18 +02:00
2018-10-09 10:55:53 +02:00
export default class Asset extends OceanBase {
2018-10-16 14:56:18 +02:00
constructor(public name: string,
public description: string,
public price: number,
public publisher: Account) {
super()
}
2018-11-05 10:01:58 +01:00
public async purchase(consumer: Account): Promise<ServiceAgreement> {
2018-10-16 14:56:18 +02:00
2018-11-05 10:01:58 +01:00
const did = `did:op:${this.getId()}`
const ddo = await AquariusProvider.getAquarius().retrieveDDO(did)
2018-10-16 14:56:18 +02:00
2018-11-05 10:01:58 +01:00
const serviceAgreementId: string = IdGenerator.generateId()
2018-11-05 14:56:14 +01:00
const serviceAgreement: ServiceAgreement = await ServiceAgreement.signServiceAgreement(this.getId(),
2018-11-05 10:01:58 +01:00
ddo, serviceAgreementId, consumer, this.publisher)
2018-10-16 14:56:18 +02:00
2018-11-05 10:01:58 +01:00
return serviceAgreement
2018-10-05 12:34:31 +02:00
}
}