2018-10-02 10:06:26 +02:00
|
|
|
import Keeper from "../keeper/Keeper"
|
2018-10-05 12:34:31 +02:00
|
|
|
import Logger from "../utils/Logger"
|
2018-10-01 18:10:26 +02:00
|
|
|
|
|
|
|
export default class Asset {
|
|
|
|
|
2018-10-02 10:06:26 +02:00
|
|
|
private keeper: Keeper
|
2018-10-01 18:10:26 +02:00
|
|
|
|
|
|
|
constructor(keeper: Keeper) {
|
2018-10-02 10:06:26 +02:00
|
|
|
this.keeper = keeper
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
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-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async registerAsset(name: string, description: string,
|
|
|
|
price: number, publisherAddress: string): Promise<string> {
|
|
|
|
const {market} = this.keeper
|
|
|
|
|
|
|
|
// generate an id
|
|
|
|
const assetId = await market.generateId(name + description)
|
|
|
|
Logger.log("Registering: ", assetId)
|
|
|
|
|
|
|
|
// register asset in the market
|
|
|
|
const result = await market.register(assetId, price, publisherAddress)
|
|
|
|
Logger.log("Registered: ", assetId, "in block", result.blockNumber)
|
|
|
|
|
|
|
|
return assetId
|
|
|
|
}
|
|
|
|
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|