UNPKG

@newfound8ion/newcoin.pools-js

Version:

js module to fetch data from the newcoin.pools smart contract

106 lines (105 loc) 3.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChainApi = void 0; class ChainApi { constructor(nodeos_url, contract, fetch) { this.nodeos_url = nodeos_url; this.contract = contract; this.fetch = fetch; } async getCurrencyStats(payload) { return await this.fetch(`${this.nodeos_url}/v1/chain/get_currency_stats`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); } async getCurrencyBalance(payload) { return await this.fetch(`${this.nodeos_url}/v1/chain/get_currency_balance`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); } async getTableRows(payload) { return await this.fetch(`${this.nodeos_url}/v1/chain/get_table_rows`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); } async getPool(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "pools", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getPoolByCode(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "pools", table_key: opts.code, lower_bound: opts.code, upper_bound: opts.code, key_type: "i64", index_position: "2", }); } async getPoolByOwner(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "pools", table_key: opts.owner, lower_bound: opts.owner, upper_bound: opts.owner, key_type: "name", index_position: "3", }); } async getPoolByDescription(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "pools", table_key: opts.description_sha256, lower_bound: opts.description_sha256, upper_bound: opts.description_sha256, key_type: "sha256", index_position: "4", }); } async getWhiteList(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.pool_id, table: "whitelist", }); } async getWhiteListByUser(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.pool_id, table: "whitelist", table_key: opts.user, lower_bound: opts.user, upper_bound: opts.user, key_type: "name", index_position: "1", }); } } exports.ChainApi = ChainApi;