mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
caseing
This commit is contained in:
parent
78311773ca
commit
426dc4c959
@ -1,7 +1,7 @@
|
||||
import Config from "../models/Config";
|
||||
import OceanAuth from "./Auth";
|
||||
import OceanMarket from "./Market";
|
||||
import OceanToken from "./Token";
|
||||
import OceanAuth from "./Auth_";
|
||||
import OceanMarket from "./Market_";
|
||||
import OceanToken from "./Token_";
|
||||
import Web3Helper from "./Web3Helper";
|
||||
|
||||
export default class Keeper {
|
||||
|
@ -1,38 +0,0 @@
|
||||
import BigNumber from "bignumber.js";
|
||||
import Asset from "../models/Asset";
|
||||
import Config from "../models/Config";
|
||||
import ContractBaseWrapper from "./ContractWrapperBase";
|
||||
import Web3Helper from "./Web3Helper";
|
||||
|
||||
export default class OceanAuth extends ContractBaseWrapper {
|
||||
|
||||
public static async getInstance(config: Config, web3Helper: Web3Helper) {
|
||||
const auth = new OceanAuth(config, "OceanAuth", web3Helper);
|
||||
await auth.init();
|
||||
return auth;
|
||||
}
|
||||
|
||||
public async getOrderStatus(orderId: string): Promise<number> {
|
||||
return this.contract.statusOfAccessRequest.call(orderId)
|
||||
.then((status: BigNumber) => status.toNumber());
|
||||
}
|
||||
|
||||
public async cancelAccessRequest(orderId: string, senderAddress: string) {
|
||||
return this.contract.cancelAccessRequest.send(orderId, {
|
||||
from: senderAddress,
|
||||
});
|
||||
}
|
||||
|
||||
public async getEncryptedAccessToken(orderId: string, senderAddress: string) {
|
||||
return this.contract.getEncryptedAccessToken.send(orderId, {
|
||||
from: senderAddress,
|
||||
});
|
||||
}
|
||||
|
||||
public async initiateAccessRequest(asset: Asset, publicKey: string, timeout, buyerAddress: string) {
|
||||
return this.contract.initiateAccessRequest.send(
|
||||
asset.assetId, asset.publisherId, publicKey, timeout, {
|
||||
from: buyerAddress, gas: this.config.defaultGas,
|
||||
});
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
import Asset from "../models/Asset";
|
||||
import Config from "../models/Config";
|
||||
import Order from "../models/Order";
|
||||
import Logger from "../utils/Logger";
|
||||
import ContractWrapperBase from "./ContractWrapperBase";
|
||||
import Web3Helper from "./Web3Helper";
|
||||
|
||||
export default class OceanMarket extends ContractWrapperBase {
|
||||
|
||||
public static async getInstance(config: Config, web3Helper: Web3Helper) {
|
||||
|
||||
const market = new OceanMarket(config, "OceanMarket", web3Helper);
|
||||
await market.init();
|
||||
return market;
|
||||
}
|
||||
|
||||
// call functions (costs no gas)
|
||||
public async isAssetActive(assetId: string): Promise<boolean> {
|
||||
return this.contract.methods.checkAsset(assetId).call;
|
||||
}
|
||||
|
||||
public async verifyOrderPayment(orderId: string): Promise<boolean> {
|
||||
return this.contract.methods.verifyPaymentReceived(orderId).call;
|
||||
}
|
||||
|
||||
public async getAssetPrice(assetId: string): Promise<number> {
|
||||
return this.contract.methods.getAssetPrice(assetId).call().then((result) => result.toNumber());
|
||||
}
|
||||
|
||||
public async requestTokens(amount: number, receiverAddress: string): Promise<boolean> {
|
||||
return this.contract.methods.requestTokens(amount).send({
|
||||
from: receiverAddress,
|
||||
});
|
||||
}
|
||||
|
||||
public async registerAsset(name: string, description: string,
|
||||
price: number, publisherAddress: string): Promise<string> {
|
||||
const assetId = await this.contract.methods.generateId(name + description).call();
|
||||
Logger.log("Registering: ", assetId);
|
||||
const result = await this.contract.methods.register(assetId, price).send({
|
||||
from: publisherAddress,
|
||||
gas: this.config.defaultGas,
|
||||
},
|
||||
);
|
||||
Logger.log("Registered: ", result);
|
||||
return assetId;
|
||||
}
|
||||
|
||||
public async payAsset(asset: Asset, order: Order, buyerAddress: string): Promise<boolean> {
|
||||
Logger.log("Sending payment");
|
||||
return this.contract.methods.sendPayment(order.id, asset.publisherId, asset.price, order.timeout).send({
|
||||
from: buyerAddress,
|
||||
gas: this.config.defaultGas,
|
||||
});
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
import Config from "../models/config";
|
||||
import Logger from "../utils/Logger";
|
||||
import ContractBaseWrapper from "./ContractWrapperBase";
|
||||
import Web3Helper from "./Web3Helper";
|
||||
|
||||
export default class OceanToken extends ContractBaseWrapper {
|
||||
|
||||
public static async getInstance(config: Config, web3Helper: Web3Helper) {
|
||||
const token = new OceanToken(config, "OceanToken", web3Helper);
|
||||
await token.init();
|
||||
return token;
|
||||
}
|
||||
|
||||
public async getTokenBalance(accountAddress: string) {
|
||||
return this.contract.methods.balanceOf(accountAddress).call();
|
||||
}
|
||||
|
||||
public async getEthBalance(account: string): Promise<number> {
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
// Logger.log("getting balance for", account);
|
||||
this.web3Helper.getWeb3().eth.getBalance(account, "latest", (err: any, balance: number) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
// Logger.log("balance", balance);
|
||||
resolve(balance);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async approve(marketAddress: string, price: number, buyerAddress: string) {
|
||||
return this.contract.methods.approve(marketAddress, price).send({
|
||||
from: buyerAddress,
|
||||
gas: this.config.defaultGas,
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user