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

78 lines
2.6 KiB
JavaScript
Raw Normal View History

import votingToChangeMinThresholdABI from './votingToChangeMinThreshold.abi.json'
2017-12-18 07:22:19 -08:00
import Web3 from 'web3';
import {VOTING_TO_CHANGE_MIN_THRESHOLD} from './addresses'
console.log('VotingToChangeMinThreshold ', VOTING_TO_CHANGE_MIN_THRESHOLD)
export default class VotingToChangeMinThreshold {
constructor(){
if(window.web3.currentProvider){
let web3_10 = new Web3(window.web3.currentProvider);
this.votingToChangeMinThresholdInstance = new web3_10.eth.Contract(votingToChangeMinThresholdABI, VOTING_TO_CHANGE_MIN_THRESHOLD);
}
}
2017-12-26 02:07:55 -08:00
//setters
2017-12-25 02:10:35 -08:00
createBallotToChangeThreshold(startTime, endTime, proposedValue, sender) {
2017-12-18 07:22:19 -08:00
return this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold(startTime, endTime, proposedValue).send({from: sender})
}
2017-12-26 02:07:55 -08:00
vote(_id, choice, sender) {
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).send({from: sender})
2017-12-18 07:22:19 -08:00
}
2017-12-26 02:07:55 -08:00
finalize(_id, sender) {
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).send({from: sender})
}
//getters
getStartTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
}
votingState(_id) {
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
}
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();
}
isValidVote(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call();
}
isActive(_id) {
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call();
}
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();
}
async getValidatorActiveBallots(_votingKey) {
const miningKey = await this.getMiningByVotingKey(_votingKey);
return await this.votingToChangeMinThresholdInstance.methods.validatorActiveBallots(miningKey).call();
}
async getBallotLimit(_votingKey) {
const currentLimit = await this.votingToChangeMinThresholdInstance.methods.getBallotLimitPerValidator().call();
return currentLimit - await this.getValidatorActiveBallots(_votingKey)
}
2017-12-18 07:22:19 -08:00
}