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

32 lines
1008 B
TypeScript
Raw Normal View History

2018-10-09 15:24:36 +02:00
import AssetModel from "../models/Asset"
2018-10-05 12:34:31 +02:00
import Logger from "../utils/Logger"
2018-10-09 10:55:53 +02:00
import OceanBase from "./OceanBase"
2018-10-09 10:55:53 +02:00
export default class Asset extends OceanBase {
2018-10-05 12:34:31 +02:00
public async isAssetActive(assetId: string): Promise<boolean> {
2018-10-02 10:06:26 +02:00
const {market} = this.keeper
return market.isAssetActive(assetId)
}
2018-10-05 12:34:31 +02:00
public async registerAsset(name: string, description: string,
2018-10-09 15:24:36 +02:00
price: number, publisherAddress: string): Promise<AssetModel> {
2018-10-05 12:34:31 +02:00
const {market} = this.keeper
// generate an id
const assetId = await market.generateId(name + description)
2018-10-09 15:24:36 +02:00
Logger.log(`Registering: ${assetId} with price ${price}`)
2018-10-05 12:34:31 +02:00
// register asset in the market
const result = await market.register(assetId, price, publisherAddress)
2018-10-09 15:24:36 +02:00
Logger.log("Registered:", assetId, "in block", result.blockNumber)
2018-10-05 12:34:31 +02:00
2018-10-09 15:24:36 +02:00
return {
assetId,
publisherId: publisherAddress,
price,
} as AssetModel
2018-10-05 12:34:31 +02:00
}
}