UNPKG

@newfound8ion/newcoin.daos-js

Version:

JS Library to read data from newcoin.daos smart contract.

276 lines (275 loc) 8.28 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 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 getDAOByID(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "daos", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getDAOByOwner(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "daos", table_key: opts.owner, lower_bound: opts.owner, upper_bound: opts.owner, key_type: "name", index_position: "2", }); } async getDAOByDescription(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "daos", table_key: opts.descriptionSHA256, lower_bound: opts.descriptionSHA256, upper_bound: opts.descriptionSHA256, key_type: "sha256", index_position: "3", }); } async getDAOWhiteList(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.id, table: "whitelist", key_type: "name", index_position: "1" }); } async getProposalByID(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "proposals", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getProposalByProposer(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "proposals", table_key: opts.proposer, lower_bound: opts.proposer, upper_bound: opts.proposer, key_type: "name", index_position: "2", }); } // async getNFTProposal(opts: ProposalPayload): Promise<any> { // return this.getTableRows({ // json: true, // code: this.contract, // scope: opts.daoID, // table: "nftproposals", // table_key: opts.id, // lower_bound: opts.id, // upper_bound: opts.id, // key_type: "i64", // index_position: "1", // }); // } // async getNFTProposalByProposer(opts: ProposalPayload): Promise<any> { // return this.getTableRows({ // json: true, // code: this.contract, // scope: opts.daoID, // table: "nftproposals", // table_key: opts.proposer, // lower_bound: opts.proposer, // upper_bound: opts.proposer, // key_type: "name", // index_position: "2", // }); // } async getStakeProposal(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "stakeprpls", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getStakeProposalByProposer(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "stakeprpls", table_key: opts.proposer, lower_bound: opts.proposer, upper_bound: opts.proposer, key_type: "name", index_position: "2", }); } async getInflateProposal(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "inflateprpls", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getInflateProposalByProposer(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "inflateprpls", table_key: opts.proposer, lower_bound: opts.proposer, upper_bound: opts.proposer, key_type: "name", index_position: "2", }); } async getDeflateProposal(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "deflateprpls", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getDeflateProposalByProposer(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "deflateprpls", table_key: opts.proposer, lower_bound: opts.proposer, upper_bound: opts.proposer, key_type: "name", index_position: "2", }); } async getWhiteListProposal(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "whlistprpls", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getWhiteListProposalByProposer(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "whlistprpls", table_key: opts.proposer, lower_bound: opts.proposer, upper_bound: opts.proposer, key_type: "name", index_position: "2", }); } async getRemoveWhiteListProposal(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "rmvwhltprpls", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getRemoveWhiteListProposalByProposer(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.daoID, table: "rmvwhltprpls", table_key: opts.proposer, lower_bound: opts.proposer, upper_bound: opts.proposer, key_type: "name", index_position: "2", }); } async getVote(opts) { return this.getTableRows({ json: true, code: this.contract, scope: opts.owner, table: "votes", table_key: opts.id, lower_bound: opts.id, upper_bound: opts.id, key_type: "i64", index_position: "1", }); } async getVoteBySHA256(opts) { return this.getTableRows({ json: true, code: this.contract, scope: this.contract, table: "votes", table_key: opts.votingSHA256, lower_bound: opts.votingSHA256, upper_bound: opts.votingSHA256, key_type: "sha256", index_position: "2", }); } } exports.ChainApi = ChainApi;