From fc46592fe90edd27292dee18854b06efa9641ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Mon, 28 Jan 2019 15:41:19 +0100 Subject: [PATCH] replaced OceanMarket with Dispenser --- src/keeper/Keeper.ts | 8 +++---- src/keeper/contracts/Dispenser.ts | 15 ++++++++++++ src/keeper/contracts/Market.ts | 38 ------------------------------- src/ocean/Account.ts | 2 +- test/keeper/Keeper.test.ts | 4 ++-- 5 files changed, 22 insertions(+), 45 deletions(-) create mode 100644 src/keeper/contracts/Dispenser.ts delete mode 100644 src/keeper/contracts/Market.ts diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index f8b6aef..017e475 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -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. diff --git a/src/keeper/contracts/Dispenser.ts b/src/keeper/contracts/Dispenser.ts new file mode 100644 index 0000000..74c91e2 --- /dev/null +++ b/src/keeper/contracts/Dispenser.ts @@ -0,0 +1,15 @@ +import {Receipt} from "web3-utils" +import ContractBase from "./ContractBase" + +export default class Dispenser extends ContractBase { + + public static async getInstance(): Promise { + const market: Dispenser = new Dispenser("Dispenser") + await market.init() + return market + } + + public async requestTokens(amount: number, receiverAddress: string): Promise { + return this.send("requestTokens", receiverAddress, [amount]) + } +} diff --git a/src/keeper/contracts/Market.ts b/src/keeper/contracts/Market.ts deleted file mode 100644 index 3376ff3..0000000 --- a/src/keeper/contracts/Market.ts +++ /dev/null @@ -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 { - const market: OceanMarket = new OceanMarket("OceanMarket") - await market.init() - return market - } - - // call functions (costs no gas) - public async isAssetActive(assetId: string): Promise { - return this.call("checkAsset", [assetId]) - } - - public async verifyOrderPayment(orderId: string): Promise { - return this.call("verifyPaymentReceived", [orderId]) - } - - public async getAssetPrice(assetId: string): Promise { - return this.call("getAssetPrice", [assetId]) - .then((price: string) => new BigNumber(price).toNumber()) - } - - public async requestTokens(amount: number, receiverAddress: string): Promise { - return this.send("requestTokens", receiverAddress, [amount]) - } - - public async generateId(input: string): Promise { - return this.call("generateId", [input]) - } - - public async register(assetId: string, price: number, publisherAddress: string): Promise { - return this.send("register", publisherAddress, [assetId, price]) - } -} diff --git a/src/ocean/Account.ts b/src/ocean/Account.ts index 1473488..d8f662d 100644 --- a/src/ocean/Account.ts +++ b/src/ocean/Account.ts @@ -60,7 +60,7 @@ export default class Account extends OceanBase { public async requestTokens(amount: number): Promise { try { await (await Keeper.getInstance()) - .market + .dispenser .requestTokens(amount, this.id) } catch (e) { Logger.error(e) diff --git a/test/keeper/Keeper.test.ts b/test/keeper/Keeper.test.ts index 00027a5..6a53c84 100644 --- a/test/keeper/Keeper.test.ts +++ b/test/keeper/Keeper.test.ts @@ -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", () => {