UNPKG

@q-dev/q-js-sdk

Version:

Typescript Library to interact with Q System Contracts

113 lines 5.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConstitutionVotingInstance = void 0; const param_voting_helper_1 = require("../../../utils/param-voting-helper"); const SystemVotingVetoableInstance_1 = require("../../SystemVotingVetoableInstance"); /** * Constitution voting instance to interact with Constitution voting contract. * See [onchain documentation](@system-contracts-repo/@network/ConstitutionVoting/) for more details. * An instance of this class for a deployed network can be obtained via {@link ContractRegistryInstance.constitutionVoting} */ class ConstitutionVotingInstance extends SystemVotingVetoableInstance_1.SystemVotingVetoableInstance { constructor(signerOrProvider, address) { super(signerOrProvider, ConstitutionVotingInstance.abi, address); this.helper = new param_voting_helper_1.ParamVotingHelper(); } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#hasrootvetoed) */ async hasRootVetoed(proposalId, address) { return this.instance.hasRootVetoed(proposalId, address); } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#hasuservoted) */ async hasUserVoted(proposalId, address) { return this.instance.hasUserVoted(proposalId, address); } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#proposalcounter) */ async proposalCount() { return (await this.instance.proposalCounter()).toString(); } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#createproposal) */ async createProposal(remark, classification, newConstitutionHash, parameters, txOptions) { const mappedParameters = parameters.map(p => this.helper.mapParameterToOnChainJson(p)); return this.submitTransaction('createProposal', [remark, classification, newConstitutionHash, mappedParameters], txOptions); } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#proposals) */ async getProposal(proposalId) { const proposal = await this.instance.proposals(proposalId); return { base: { remark: proposal.base.remark, executed: proposal.base.executed, params: { votingStartTime: proposal.base.params.votingStartTime.toString(), votingEndTime: proposal.base.params.votingEndTime.toString(), vetoEndTime: proposal.base.params.vetoEndTime.toString(), proposalExecutionP: proposal.base.params.proposalExecutionP.toString(), requiredQuorum: proposal.base.params.requiredQuorum.toString(), requiredMajority: proposal.base.params.requiredMajority.toString(), requiredSMajority: proposal.base.params.requiredSMajority.toString(), requiredSQuorum: proposal.base.params.requiredSQuorum.toString(), }, counters: { weightFor: proposal.base.counters.weightFor.toString(), weightAgainst: proposal.base.counters.weightAgainst.toString(), vetosCount: proposal.base.counters.vetosCount.toString(), }, }, parametersSize: proposal.parametersSize.toString(), classification: proposal.classification, newConstitutionHash: proposal.newConstitutionHash, currentConstitutionHash: proposal.currentConstitutionHash }; } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#getparametersarr) */ async getParametersArr(proposalId) { const params = await this.instance.getParametersArr(proposalId); return params.map((i) => ({ paramKey: i.paramKey, paramType: i.paramType.toString(), addrValue: i.addrValue, boolValue: i.boolValue, bytes32Value: i.bytes32Value, strValue: i.strValue, uintValue: i.uintValue.toString(), })); } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#getconstitutionhash) */ async getConstitutionHash(proposalId) { return this.instance.getConstitutionHash(proposalId); } /** * Retrieve proposal parameters. * @param proposalId chosen proposal id * @returns Proposal parameters */ async getProposedParameters(proposalId) { const rawParameters = await this.getParametersArr(proposalId); const proposedParameters = rawParameters.map(raw => this.helper.mapOnChainJsonToParameter(raw)); return proposedParameters; } /** * [External documentation](@system-contracts-repo/@network/ConstitutionVoting/#constitutionhash) */ async constitutionHash() { return this.instance.constitutionHash(); } } exports.ConstitutionVotingInstance = ConstitutionVotingInstance; ConstitutionVotingInstance.registryKey = 'governance.constitution.parametersVoting'; ConstitutionVotingInstance.abi = 'ConstitutionVoting.json'; //# sourceMappingURL=ConstitutionVotingInstance.js.map