@swaptoshi/governance-module
Version:
Klayr governance on-chain module
81 lines • 4.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GovernanceMethod = void 0;
const klayr_framework_1 = require("klayr-framework");
const config_1 = require("./config");
const proposal_1 = require("./stores/proposal");
const context_1 = require("./stores/context");
const queue_1 = require("./stores/queue");
const boosted_account_1 = require("./stores/boosted_account");
const delegated_vote_1 = require("./stores/delegated_vote");
const next_available_proposal_id_1 = require("./stores/next_available_proposal_id");
const casted_vote_1 = require("./stores/casted_vote");
const vote_score_1 = require("./stores/vote_score");
class GovernanceMethod extends klayr_framework_1.Modules.BaseMethod {
init(governableConfig) {
this._governableConfig = governableConfig;
}
registerGovernableConfig(args, moduleName, governableConfig) {
if (!this._governableConfig)
throw new Error('GovernanceMethod is not initialized');
governableConfig.register(this.events, this, args);
this._governableConfig.register(moduleName, governableConfig);
}
unregisterGovernableConfig(moduleName, governableConfig) {
if (!this._governableConfig)
throw new Error('GovernanceMethod is not initialized');
governableConfig.unregister();
this._governableConfig.unregister(moduleName);
}
getGovernableConfig(module) {
if (!this._governableConfig)
throw new Error('GovernanceMethod is not initialized');
return this._governableConfig.get(module);
}
async getConfig(context) {
const configStore = this.stores.get(config_1.GovernanceGovernableConfig);
const config = await configStore.getConfig(context);
return config;
}
async getCastedVote(context, address) {
const castedVoteStore = this.stores.get(casted_vote_1.CastedVoteStore);
const castedVote = await castedVoteStore.getOrDefault(context, address);
return castedVote;
}
async getBaseVoteScore(context, address) {
const baseVoteStore = this.stores.get(vote_score_1.VoteScoreStore);
const baseVote = await baseVoteStore.getVoteScore(context, address);
return baseVote;
}
async createProposal(context, senderAddress, height, title, summary, actions, attributes) {
const proposalStore = this.stores.get(proposal_1.ProposalStore);
const _context = (0, context_1.methodGovernanceContext)(context, senderAddress, height);
await proposalStore.createProposal(_context, { title, summary, actions, attributes });
}
async getProposalInstance(context, senderAddress, height, proposalId) {
const proposalStore = this.stores.get(proposal_1.ProposalStore);
const _context = (0, context_1.methodGovernanceContext)(context, senderAddress, height);
return proposalStore.getMutableProposal(_context, proposalId);
}
async getProposalQueueInstance(context, senderAddress, height) {
const proposalQueueStore = this.stores.get(queue_1.ProposalQueueStore);
const _context = (0, context_1.methodGovernanceContext)(context, senderAddress, height);
return proposalQueueStore.getInstance(_context);
}
async getBoostedAccountInstance(context, address, height) {
const boostedAccountStore = this.stores.get(boosted_account_1.BoostedAccountStore);
const _context = (0, context_1.methodGovernanceContext)(context, address, height);
return boostedAccountStore.getMutableBoostedAccount(_context);
}
async getDelegatedVoteInstance(context, address, height) {
const delegatedVoteStore = this.stores.get(delegated_vote_1.DelegatedVoteStore);
const _context = (0, context_1.methodGovernanceContext)(context, address, height);
return delegatedVoteStore.getMutableDelegatedVote(_context);
}
async getNextAvailableProposalId(context) {
const nextAvailableIdStore = this.stores.get(next_available_proposal_id_1.NextAvailableProposalIdStore);
return nextAvailableIdStore.getOrDefault(context);
}
}
exports.GovernanceMethod = GovernanceMethod;
//# sourceMappingURL=method.js.map