1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

replaced OceanMarket with Dispenser

This commit is contained in:
Pedro Gutiérrez 2019-01-28 15:41:19 +01:00 committed by Pedro Gutiérrez
parent 64921829f9
commit fc46592fe9
5 changed files with 22 additions and 45 deletions

View File

@ -2,7 +2,7 @@ import OceanAuth from "./contracts/Auth"
import AccessConditions from "./contracts/conditions/AccessConditions"
import PaymentConditions from "./contracts/conditions/PaymentConditions"
import DIDRegistry from "./contracts/DIDRegistry"
import OceanMarket from "./contracts/Market"
import Dispenser from "./contracts/Dispenser"
import ServiceExecutionAgreement from "./contracts/ServiceExecutionAgreement"
import OceanToken from "./contracts/Token"
@ -26,7 +26,7 @@ export default class Keeper {
if (Keeper.instance === null) {
Keeper.instance = new Keeper()
Keeper.instance.market = await OceanMarket.getInstance()
Keeper.instance.dispenser = await Dispenser.getInstance()
Keeper.instance.auth = await OceanAuth.getInstance()
Keeper.instance.token = await OceanToken.getInstance()
Keeper.instance.serviceAgreement = await ServiceExecutionAgreement.getInstance()
@ -51,9 +51,9 @@ export default class Keeper {
/**
* Ocean Market smart contract instance.
* @type {OceanMarket}
* @type {Dispenser}
*/
public market: OceanMarket
public dispenser: Dispenser
/**
* Ocean Auth smart contract instance.

View File

@ -0,0 +1,15 @@
import {Receipt} from "web3-utils"
import ContractBase from "./ContractBase"
export default class Dispenser extends ContractBase {
public static async getInstance(): Promise<Dispenser> {
const market: Dispenser = new Dispenser("Dispenser")
await market.init()
return market
}
public async requestTokens(amount: number, receiverAddress: string): Promise<Receipt> {
return this.send("requestTokens", receiverAddress, [amount])
}
}

View File

@ -1,38 +0,0 @@
import BigNumber from "bignumber.js"
import {Receipt} from "web3-utils"
import ContractBase from "./ContractBase"
export default class OceanMarket extends ContractBase {
public static async getInstance(): Promise<OceanMarket> {
const market: OceanMarket = new OceanMarket("OceanMarket")
await market.init()
return market
}
// call functions (costs no gas)
public async isAssetActive(assetId: string): Promise<boolean> {
return this.call("checkAsset", [assetId])
}
public async verifyOrderPayment(orderId: string): Promise<boolean> {
return this.call("verifyPaymentReceived", [orderId])
}
public async getAssetPrice(assetId: string): Promise<number> {
return this.call("getAssetPrice", [assetId])
.then((price: string) => new BigNumber(price).toNumber())
}
public async requestTokens(amount: number, receiverAddress: string): Promise<Receipt> {
return this.send("requestTokens", receiverAddress, [amount])
}
public async generateId(input: string): Promise<string> {
return this.call("generateId", [input])
}
public async register(assetId: string, price: number, publisherAddress: string): Promise<Receipt> {
return this.send("register", publisherAddress, [assetId, price])
}
}

View File

@ -60,7 +60,7 @@ export default class Account extends OceanBase {
public async requestTokens(amount: number): Promise<number> {
try {
await (await Keeper.getInstance())
.market
.dispenser
.requestTokens(amount, this.id)
} catch (e) {
Logger.error(e)

View File

@ -16,8 +16,8 @@ describe("Keeper", () => {
describe("public interface", () => {
it("should have market", () => {
assert(keeper.market !== null)
it("should have dispenser", () => {
assert(keeper.dispenser !== null)
})
it("should have auth", () => {