@swaptoshi/governance-module
Version:
Klayr governance on-chain module
83 lines • 4.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GovernanceEndpoint = void 0;
const klayr_framework_1 = require("klayr-framework");
const cryptography = require("@klayr/cryptography");
const validator = require("@klayr/validator");
const config_1 = require("./config");
const utils_1 = require("@swaptoshi/utils");
const schema_1 = require("./schema");
const casted_vote_1 = require("./stores/casted_vote");
const vote_score_1 = require("./stores/vote_score");
const proposal_1 = require("./stores/proposal");
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");
class GovernanceEndpoint extends klayr_framework_1.Modules.BaseEndpoint {
init(governableConfig) {
this._governableConfig = governableConfig;
}
async getConfig(_context) {
const configStore = this.stores.get(config_1.GovernanceGovernableConfig);
const config = await configStore.getConfig(_context);
return utils_1.object.serializer(config, schema_1.getConfigEndpointResponseSchema);
}
async getRegisteredGovernableConfig(_context) {
if (!this._governableConfig)
throw new Error('GovernanceEndpoint is not initialized');
const response = {
modules: [...this._governableConfig.keys()],
};
return utils_1.object.serializer(response, schema_1.getRegisteredGovernableConfigEndpointResponseSchema);
}
async getCastedVote(context) {
const params = context.params;
validator.validator.validate(schema_1.getCastedVoteEndpointRequestSchema, params);
const store = this.stores.get(casted_vote_1.CastedVoteStore);
const data = await store.getOrDefault(context, cryptography.address.getAddressFromKlayr32Address(params.address));
return utils_1.object.serializer(data, schema_1.getCastedVoteEndpointResponseSchema);
}
async getBaseVoteScore(context) {
const params = context.params;
validator.validator.validate(schema_1.getBaseVoteScoreEndpointRequestSchema, params);
const store = this.stores.get(vote_score_1.VoteScoreStore);
const data = await store.getVoteScore(context, cryptography.address.getAddressFromKlayr32Address(params.address));
return utils_1.object.serializer({ score: data }, schema_1.getBaseVoteScoreEndpointResponseSchema);
}
async getProposal(context) {
const params = context.params;
validator.validator.validate(schema_1.getProposalEndpointRequestSchema, params);
const store = this.stores.get(proposal_1.ProposalStore);
const data = await store.getOrDefault(context, utils_1.bytes.numberToBytes(params.proposalId));
return utils_1.object.serializer(data, schema_1.getProposalEndpointResponseSchema);
}
async getProposalQueue(context) {
const params = context.params;
validator.validator.validate(schema_1.getProposalQueueEndpointRequestSchema, params);
const store = this.stores.get(queue_1.ProposalQueueStore);
const data = await store.getOrDefault(context, utils_1.bytes.numberToBytes(params.height));
return utils_1.object.serializer(data, schema_1.getProposalQueueEndpointResponseSchema);
}
async getBoostedAccount(context) {
const params = context.params;
validator.validator.validate(schema_1.getBoostedAccountEndpointRequestSchema, params);
const store = this.stores.get(boosted_account_1.BoostedAccountStore);
const data = await store.getOrDefault(context, cryptography.address.getAddressFromKlayr32Address(params.address));
return utils_1.object.serializer(data, schema_1.getBoostedAccountEndpointResponseSchema);
}
async getDelegatedVote(context) {
const params = context.params;
validator.validator.validate(schema_1.getDelegatedVoteEndpointRequestSchema, params);
const store = this.stores.get(delegated_vote_1.DelegatedVoteStore);
const data = await store.getOrDefault(context, cryptography.address.getAddressFromKlayr32Address(params.address));
return utils_1.object.serializer(data, schema_1.getDelegatedVoteEndpointResponseSchema);
}
async getNextAvailableProposalId(context) {
const store = this.stores.get(next_available_proposal_id_1.NextAvailableProposalIdStore);
const data = await store.getOrDefault(context);
return utils_1.object.serializer(data, schema_1.getNextAvailableProposalIdEndpointResponseSchema);
}
}
exports.GovernanceEndpoint = GovernanceEndpoint;
//# sourceMappingURL=endpoint.js.map