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

85 lines
2.4 KiB
JavaScript
Raw Normal View History

import { networkAddresses } from './addresses'
import helpers from './helpers'
2018-12-17 10:09:59 -08:00
import { constants } from '../utils/constants'
2017-12-18 07:22:19 -08:00
export default class VotingToChangeMinThreshold {
async init({ web3, netId }) {
const { VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS } = networkAddresses()
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
const votingToChangeMinThresholdABI = await helpers.getABI(
constants.NETWORKS[netId].BRANCH,
'VotingToChangeMinThreshold'
)
2018-10-11 02:02:47 -07:00
this.instance = new web3.eth.Contract(votingToChangeMinThresholdABI, VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
this.address = VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
2017-12-18 07:22:19 -08:00
}
2017-12-26 02:07:55 -08:00
//setters
createBallot({ startTime, endTime, proposedValue, memo }) {
let method
2018-10-11 02:02:47 -07:00
if (this.instance.methods.createBallot) {
method = this.instance.methods.createBallot
} else {
2018-10-11 02:02:47 -07:00
method = this.instance.methods.createBallotToChangeThreshold
}
return method(startTime, endTime, proposedValue, memo).encodeABI()
2017-12-18 07:22:19 -08:00
}
vote(_id, choice) {
2018-10-11 02:02:47 -07:00
return this.instance.methods.vote(_id, choice).encodeABI()
2017-12-18 07:22:19 -08:00
}
finalize(_id) {
2018-10-11 02:02:47 -07:00
return this.instance.methods.finalize(_id).encodeABI()
2017-12-26 02:07:55 -08:00
}
//getters
2018-06-13 03:44:04 -07:00
doesMethodExist(methodName) {
2018-10-11 02:02:47 -07:00
if (this.instance.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() {
2018-10-11 02:02:47 -07:00
return this.instance.methods.nextBallotId().call()
2018-06-14 05:41:01 -07:00
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
2018-10-11 02:02:47 -07:00
return this.instance.methods.getBallotInfo(_id, _votingKey).call()
}
2018-10-11 02:02:47 -07:00
return this.instance.methods.votingState(_id).call()
}
2018-03-22 06:33:01 -07:00
hasAlreadyVoted(_id, votingKey) {
2018-10-11 02:02:47 -07:00
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
2018-03-22 06:33:01 -07:00
}
2017-12-26 02:07:55 -08:00
isValidVote(_id, votingKey) {
2018-10-11 02:02:47 -07:00
return this.instance.methods.isValidVote(_id, votingKey).call()
2017-12-26 02:07:55 -08:00
}
isActive(_id) {
2018-10-11 02:02:47 -07:00
return this.instance.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')) {
2018-10-11 02:02:47 -07:00
return this.instance.methods.canBeFinalizedNow(_id).call()
2018-06-13 03:44:04 -07:00
}
return null
}
async getBallotLimit(_miningKey, _limitPerValidator) {
2018-10-11 02:02:47 -07:00
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
return _limitPerValidator - _activeBallots
}
async minBallotDuration() {
return await this.instance.methods.minBallotDuration().call()
}
2017-12-18 07:22:19 -08:00
}