2017-12-18 07:22:19 -08:00
|
|
|
import Web3 from 'web3';
|
2018-03-20 14:57:28 -07:00
|
|
|
import { networkAddresses } from './addresses';
|
2018-01-29 11:11:26 -08:00
|
|
|
import helpers from "./helpers";
|
2017-12-18 07:22:19 -08:00
|
|
|
|
|
|
|
export default class VotingToChangeMinThreshold {
|
2018-01-29 11:11:26 -08:00
|
|
|
async init({web3, netId}) {
|
|
|
|
const {VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS} = networkAddresses(netId);
|
|
|
|
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS);
|
2018-01-04 13:12:23 -08:00
|
|
|
let web3_10 = new Web3(web3.currentProvider);
|
2018-01-29 11:11:26 -08:00
|
|
|
|
|
|
|
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}) {
|
2018-06-13 05:02:31 -07:00
|
|
|
let method;
|
|
|
|
if (this.votingToChangeMinThresholdInstance.methods.createBallot) {
|
|
|
|
method = this.votingToChangeMinThresholdInstance.methods.createBallot;
|
|
|
|
} else {
|
|
|
|
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold;
|
|
|
|
}
|
|
|
|
return method(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
|
2018-06-13 03:44:04 -07:00
|
|
|
doesMethodExist(methodName) {
|
|
|
|
if (this.votingToChangeMinThresholdInstance.methods[methodName]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-26 02:07:55 -08:00
|
|
|
getStartTime(_id) {
|
|
|
|
return this.votingToChangeMinThresholdInstance.methods.getStartTime(_id).call();
|
|
|
|
}
|
|
|
|
|
|
|
|
getEndTime(_id) {
|
|
|
|
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
|
|
|
|
}
|
|
|
|
|
|
|
|
votingState(_id) {
|
2018-06-13 03:44:04 -07:00
|
|
|
if (this.doesMethodExist('votingState')) {
|
2018-05-08 01:49:56 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCreator(_id) {
|
2018-06-13 03:44:04 -07:00
|
|
|
if (this.doesMethodExist('getCreator')) {
|
2018-05-08 01:49:56 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-06-08 08:27:19 -07:00
|
|
|
canBeFinalizedNow(_id) {
|
2018-06-13 03:44:04 -07:00
|
|
|
if (this.doesMethodExist('canBeFinalizedNow')) {
|
|
|
|
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call();
|
|
|
|
}
|
|
|
|
return null;
|
2018-06-08 08:27:19 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2018-01-03 19:34:22 -08:00
|
|
|
|
|
|
|
getMiningByVotingKey(_votingKey) {
|
|
|
|
return this.votingToChangeMinThresholdInstance.methods.getMiningByVotingKey(_votingKey).call();
|
|
|
|
}
|
|
|
|
|
2018-01-19 14:59:07 -08:00
|
|
|
getMemo(_id) {
|
|
|
|
return this.votingToChangeMinThresholdInstance.methods.getMemo(_id).call();
|
|
|
|
}
|
|
|
|
|
2018-01-03 19:34:22 -08:00
|
|
|
async getValidatorActiveBallots(_votingKey) {
|
2018-01-16 16:05:12 -08:00
|
|
|
let miningKey;
|
|
|
|
try {
|
|
|
|
miningKey = await this.getMiningByVotingKey(_votingKey);
|
2018-03-22 03:04:05 -07:00
|
|
|
} catch(e) {
|
2018-01-16 16:05:12 -08:00
|
|
|
miningKey = "0x0000000000000000000000000000000000000000";
|
|
|
|
}
|
2018-01-03 19:34:22 -08:00
|
|
|
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);
|
2018-01-03 19:34:22 -08:00
|
|
|
}
|
2017-12-18 07:22:19 -08:00
|
|
|
}
|