poa-dapps-voting/src/contracts/VotingToChangeMinThreshold....

110 lines
3.6 KiB
JavaScript
Raw Normal View History

2017-12-18 07:22:19 -08:00
import Web3 from 'web3';
2018-03-20 14:57:28 -07:00
import { networkAddresses } from './addresses';
import helpers from "./helpers";
2017-12-18 07:22:19 -08:00
export default class VotingToChangeMinThreshold {
async init({web3, netId}) {
const {VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS} = networkAddresses(netId);
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS);
let web3_10 = new Web3(web3.currentProvider);
const branch = helpers.getBranch(netId);
let votingToChangeMinThresholdABI = await helpers.getABI(branch, 'VotingToChangeMinThreshold')
this.votingToChangeMinThresholdInstance = new web3_10.eth.Contract(votingToChangeMinThresholdABI, VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS);
2018-03-20 09:35:47 -07:00
this.gasPrice = web3_10.utils.toWei('1', 'gwei');
2017-12-18 07:22:19 -08:00
}
2017-12-26 02:07:55 -08:00
//setters
2018-05-14 23:02:06 -07:00
createBallot({startTime, endTime, proposedValue, sender, memo}) {
return this.votingToChangeMinThresholdInstance.methods.createBallot(startTime, endTime, proposedValue, memo).send({from: sender, gasPrice: this.gasPrice})
2017-12-18 07:22:19 -08:00
}
2017-12-26 02:07:55 -08:00
vote(_id, choice, sender) {
2018-03-20 09:35:47 -07:00
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).send({from: sender, gasPrice: this.gasPrice})
2017-12-18 07:22:19 -08:00
}
2017-12-26 02:07:55 -08:00
finalize(_id, sender) {
2018-03-20 09:35:47 -07:00
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).send({from: sender, gasPrice: this.gasPrice})
2017-12-26 02:07:55 -08:00
}
//getters
getStartTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
}
votingState(_id) {
if (this.votingToChangeMinThresholdInstance.methods.votingState) {
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
}
return null;
}
getCreator(_id) {
if (this.votingToChangeMinThresholdInstance.methods.getCreator) {
return this.votingToChangeMinThresholdInstance.methods.getCreator(_id).call();
}
return null;
2017-12-26 02:07:55 -08:00
}
getTotalVoters(_id) {
return this.votingToChangeMinThresholdInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeMinThresholdInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeMinThresholdInstance.methods.getIsFinalized(_id).call();
}
2018-03-22 06:33:01 -07:00
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call();
}
2017-12-26 02:07:55 -08:00
isValidVote(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call();
}
isActive(_id) {
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call();
}
canBeFinalizedNow(_id) {
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call();
}
2017-12-26 02:07:55 -08:00
getProposedValue(_id) {
return this.votingToChangeMinThresholdInstance.methods.getProposedValue(_id).call();
2017-12-18 07:22:19 -08:00
}
getMiningByVotingKey(_votingKey) {
return this.votingToChangeMinThresholdInstance.methods.getMiningByVotingKey(_votingKey).call();
}
getMemo(_id) {
return this.votingToChangeMinThresholdInstance.methods.getMemo(_id).call();
}
async getValidatorActiveBallots(_votingKey) {
let miningKey;
try {
miningKey = await this.getMiningByVotingKey(_votingKey);
2018-03-22 03:04:05 -07:00
} catch(e) {
miningKey = "0x0000000000000000000000000000000000000000";
}
return await this.votingToChangeMinThresholdInstance.methods.validatorActiveBallots(miningKey).call();
}
async getBallotLimit(_votingKey) {
const currentLimit = await this.votingToChangeMinThresholdInstance.methods.getBallotLimitPerValidator().call();
2018-01-03 20:51:10 -08:00
return currentLimit - await this.getValidatorActiveBallots(_votingKey);
}
2017-12-18 07:22:19 -08:00
}