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

88 lines
2.8 KiB
JavaScript
Raw Normal View History

import Web3 from 'web3'
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)
const web3_10 = new Web3(web3.currentProvider)
const branch = helpers.getBranch(netId)
const votingToChangeMinThresholdABI = await helpers.getABI(branch, 'VotingToChangeMinThreshold')
this.votingToChangeMinThresholdInstance = new web3_10.eth.Contract(
votingToChangeMinThresholdABI,
VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.address = VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
this.instance = this.votingToChangeMinThresholdInstance
2017-12-18 07:22:19 -08:00
}
2017-12-26 02:07:55 -08:00
//setters
createBallot({ startTime, endTime, proposedValue, memo }) {
let method
if (this.votingToChangeMinThresholdInstance.methods.createBallot) {
method = this.votingToChangeMinThresholdInstance.methods.createBallot
} else {
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold
}
return method(startTime, endTime, proposedValue, memo).encodeABI()
2017-12-18 07:22:19 -08:00
}
vote(_id, choice) {
2018-07-17 05:15:02 -07:00
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).encodeABI()
2017-12-18 07:22:19 -08:00
}
finalize(_id) {
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).encodeABI()
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
2018-06-13 03:44:04 -07:00
}
return false
2018-06-13 03:44:04 -07:00
}
2018-06-14 05:41:01 -07:00
nextBallotId() {
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call()
2018-06-14 05:41:01 -07:00
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call()
}
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call()
}
2018-03-22 06:33:01 -07:00
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call()
2018-03-22 06:33:01 -07:00
}
2017-12-26 02:07:55 -08:00
isValidVote(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call()
2017-12-26 02:07:55 -08:00
}
isActive(_id) {
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call()
2017-12-26 02:07:55 -08:00
}
canBeFinalizedNow(_id) {
2018-06-13 03:44:04 -07:00
if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call()
2018-06-13 03:44:04 -07:00
}
return null
}
async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeMinThresholdInstance.methods
.validatorActiveBallots(_miningKey)
.call()
return _limitPerValidator - _activeBallots
}
2017-12-18 07:22:19 -08:00
}