2018-07-13 07:32:22 -07:00
|
|
|
import Web3 from 'web3'
|
|
|
|
import { networkAddresses } from './addresses'
|
|
|
|
import helpers from './helpers'
|
2017-12-18 07:22:19 -08:00
|
|
|
|
|
|
|
export default class VotingToChangeMinThreshold {
|
2018-07-13 07:32:22 -07: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-08-10 01:13:28 -07:00
|
|
|
const web3_10 = new Web3(web3.currentProvider)
|
2018-01-29 11:11:26 -08:00
|
|
|
|
2018-07-13 07:32:22 -07:00
|
|
|
const branch = helpers.getBranch(netId)
|
2018-01-29 11:11:26 -08:00
|
|
|
|
2018-08-10 01:13:28 -07:00
|
|
|
const votingToChangeMinThresholdABI = await helpers.getABI(branch, 'VotingToChangeMinThreshold')
|
2018-01-29 11:11:26 -08:00
|
|
|
|
2018-07-13 07:32:22 -07:00
|
|
|
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
|
2018-08-04 03:41:34 -07:00
|
|
|
this.instance = this.votingToChangeMinThresholdInstance
|
2017-12-18 07:22:19 -08:00
|
|
|
}
|
|
|
|
|
2017-12-26 02:07:55 -08:00
|
|
|
//setters
|
2018-07-13 07:32:22 -07:00
|
|
|
createBallot({ startTime, endTime, proposedValue, memo }) {
|
|
|
|
let method
|
2018-06-13 05:02:31 -07:00
|
|
|
if (this.votingToChangeMinThresholdInstance.methods.createBallot) {
|
2018-07-13 07:32:22 -07:00
|
|
|
method = this.votingToChangeMinThresholdInstance.methods.createBallot
|
2018-06-13 05:02:31 -07:00
|
|
|
} else {
|
2018-07-13 07:32:22 -07:00
|
|
|
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold
|
2018-06-13 05:02:31 -07:00
|
|
|
}
|
2018-07-13 07:32:22 -07:00
|
|
|
return method(startTime, endTime, proposedValue, memo).encodeABI()
|
2017-12-18 07:22:19 -08:00
|
|
|
}
|
|
|
|
|
2018-07-13 07:32:22 -07: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
|
|
|
}
|
|
|
|
|
2018-07-13 07:32:22 -07: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]) {
|
2018-07-13 07:32:22 -07:00
|
|
|
return true
|
2018-06-13 03:44:04 -07:00
|
|
|
}
|
2018-07-13 07:32:22 -07:00
|
|
|
return false
|
2018-06-13 03:44:04 -07:00
|
|
|
}
|
|
|
|
|
2018-06-14 05:41:01 -07:00
|
|
|
nextBallotId() {
|
2018-07-13 07:32:22 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call()
|
2018-06-14 05:41:01 -07:00
|
|
|
}
|
|
|
|
|
2018-06-19 01:42:01 -07:00
|
|
|
getBallotInfo(_id, _votingKey) {
|
|
|
|
if (this.doesMethodExist('getBallotInfo')) {
|
2018-07-13 07:32:22 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call()
|
2018-06-19 01:42:01 -07:00
|
|
|
}
|
2018-07-13 07:32:22 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call()
|
2018-05-08 01:49:56 -07:00
|
|
|
}
|
|
|
|
|
2018-03-22 06:33:01 -07:00
|
|
|
hasAlreadyVoted(_id, votingKey) {
|
2018-07-13 07:32:22 -07:00
|
|
|
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) {
|
2018-07-13 07:32:22 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call()
|
2017-12-26 02:07:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
isActive(_id) {
|
2018-07-13 07:32:22 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call()
|
2017-12-26 02:07:55 -08:00
|
|
|
}
|
|
|
|
|
2018-06-08 08:27:19 -07:00
|
|
|
canBeFinalizedNow(_id) {
|
2018-06-13 03:44:04 -07:00
|
|
|
if (this.doesMethodExist('canBeFinalizedNow')) {
|
2018-07-13 07:32:22 -07:00
|
|
|
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call()
|
2018-06-13 03:44:04 -07:00
|
|
|
}
|
2018-07-13 07:32:22 -07:00
|
|
|
return null
|
2018-06-08 08:27:19 -07:00
|
|
|
}
|
|
|
|
|
2018-08-04 03:41:34 -07:00
|
|
|
async getBallotLimit(_miningKey, _limitPerValidator) {
|
|
|
|
const _activeBallots = await this.votingToChangeMinThresholdInstance.methods
|
|
|
|
.validatorActiveBallots(_miningKey)
|
|
|
|
.call()
|
|
|
|
return _limitPerValidator - _activeBallots
|
2018-01-03 19:34:22 -08:00
|
|
|
}
|
2017-12-18 07:22:19 -08:00
|
|
|
}
|