(Fix) Use web3 1.0 by default

This commit is contained in:
Vadim Arasev 2018-10-11 12:02:47 +03:00
parent 3564270dcb
commit b088f0a26f
16 changed files with 108 additions and 145 deletions

View File

@ -7,7 +7,7 @@ import { BallotCard } from './BallotCard.jsx'
export class BallotEmissionFundsCard extends React.Component { export class BallotEmissionFundsCard extends React.Component {
render() { render() {
const { id, votingState, pos, contractsStore } = this.props const { id, votingState, pos, contractsStore } = this.props
const amount = contractsStore.web3Instance.fromWei(votingState.amount, 'ether') const amount = contractsStore.web3Instance.utils.fromWei(votingState.amount, 'ether')
return ( return (
<BallotCard votingType="votingToManageEmissionFunds" votingState={votingState} id={id} pos={pos}> <BallotCard votingType="votingToManageEmissionFunds" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_proposed_receiver"> <div className="ballots-about-i ballots-about-i_proposed_receiver">

View File

@ -16,7 +16,7 @@ export class BallotEmissionFundsMetadata extends React.Component {
getEmissionFundsBalance = async () => { getEmissionFundsBalance = async () => {
const { contractsStore } = this.props const { contractsStore } = this.props
this.emissionFundsBalance = this.emissionFundsBalance =
contractsStore.web3Instance.fromWei(await contractsStore.emissionFunds.balance(), 'ether') + ' POA' contractsStore.web3Instance.utils.fromWei(await contractsStore.emissionFunds.balance(), 'ether') + ' POA'
} }
@action('Get VotingToManageEmissionFunds.noActiveBallotExists') @action('Get VotingToManageEmissionFunds.noActiveBallotExists')

View File

@ -100,7 +100,7 @@ export class NewBallot extends React.Component {
} }
} }
let isAffectedKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.affectedKey) let isAffectedKeyAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotKeys.affectedKey)
if (!isAffectedKeyAddress) { if (!isAffectedKeyAddress) {
swal('Warning!', messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG, 'warning') swal('Warning!', messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG, 'warning')
@ -108,7 +108,7 @@ export class NewBallot extends React.Component {
return false return false
} }
let isMiningKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.miningKey.value) let isMiningKeyAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotKeys.miningKey.value)
if (!isMiningKeyAddress) { if (!isMiningKeyAddress) {
swal('Warning!', messages.MINING_KEY_IS_NOT_ADDRESS_MSG, 'warning') swal('Warning!', messages.MINING_KEY_IS_NOT_ADDRESS_MSG, 'warning')
commonStore.hideLoading() commonStore.hideLoading()
@ -135,7 +135,7 @@ export class NewBallot extends React.Component {
} }
} }
const isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotProxy.proposedAddress) const isAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotProxy.proposedAddress)
if (!isAddress) { if (!isAddress) {
swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning') swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning')
@ -151,7 +151,7 @@ export class NewBallot extends React.Component {
return false return false
} }
const isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotEmissionFunds.receiver) const isAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotEmissionFunds.receiver)
if (!isAddress) { if (!isAddress) {
swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning') swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning')
@ -320,17 +320,17 @@ export class NewBallot extends React.Component {
case ballotStore.BallotType.keys: case ballotStore.BallotType.keys:
methodToCreateBallot = this.createBallotForKeys methodToCreateBallot = this.createBallotForKeys
contractType = 'votingToChangeKeys' contractType = 'votingToChangeKeys'
contractInstance = contractsStore.votingToChangeKeys.votingToChangeKeysInstance contractInstance = contractsStore.votingToChangeKeys.instance
break break
case ballotStore.BallotType.minThreshold: case ballotStore.BallotType.minThreshold:
methodToCreateBallot = this.createBallotForMinThreshold methodToCreateBallot = this.createBallotForMinThreshold
contractType = 'votingToChangeMinThreshold' contractType = 'votingToChangeMinThreshold'
contractInstance = contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance contractInstance = contractsStore.votingToChangeMinThreshold.instance
break break
case ballotStore.BallotType.proxy: case ballotStore.BallotType.proxy:
methodToCreateBallot = this.createBallotForProxy methodToCreateBallot = this.createBallotForProxy
contractType = 'votingToChangeProxy' contractType = 'votingToChangeProxy'
contractInstance = contractsStore.votingToChangeProxy.votingToChangeProxyInstance contractInstance = contractsStore.votingToChangeProxy.instance
break break
case ballotStore.BallotType.emissionFunds: case ballotStore.BallotType.emissionFunds:
methodToCreateBallot = this.createBallotForEmissionFunds methodToCreateBallot = this.createBallotForEmissionFunds

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,19 +6,16 @@ export default class BallotsStorage {
async init({ web3, netId }) { async init({ web3, netId }) {
const { BALLOTS_STORAGE_ADDRESS } = networkAddresses() const { BALLOTS_STORAGE_ADDRESS } = networkAddresses()
console.log('Ballots Storage address', BALLOTS_STORAGE_ADDRESS) console.log('Ballots Storage address', BALLOTS_STORAGE_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const ballotsStorageAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'BallotStorage') const ballotsStorageAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'BallotStorage')
this.ballotsStorageInstance = new web3_10.eth.Contract(ballotsStorageAbi, BALLOTS_STORAGE_ADDRESS) this.instance = new web3.eth.Contract(ballotsStorageAbi, BALLOTS_STORAGE_ADDRESS)
} }
areKeysBallotParamsValid({ ballotType, affectedKeyType, affectedKey, miningKey }) { areKeysBallotParamsValid({ ballotType, affectedKeyType, affectedKey, miningKey }) {
if (!this.ballotsStorageInstance.methods.areKeysBallotParamsValid) { if (!this.instance.methods.areKeysBallotParamsValid) {
return null return null
} }
return this.ballotsStorageInstance.methods return this.instance.methods.areKeysBallotParamsValid(ballotType, affectedKeyType, affectedKey, miningKey).call()
.areKeysBallotParamsValid(ballotType, affectedKeyType, affectedKey, miningKey)
.call()
} }
} }

View File

@ -1,15 +1,14 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
export default class EmissionFunds { export default class EmissionFunds {
async init({ web3, netId }) { async init({ web3, netId }) {
const { EMISSION_FUNDS_ADDRESS } = networkAddresses() const { EMISSION_FUNDS_ADDRESS } = networkAddresses()
console.log('EmissionFunds address', EMISSION_FUNDS_ADDRESS) console.log('EmissionFunds address', EMISSION_FUNDS_ADDRESS)
this.web3_10 = new Web3(web3.currentProvider) this.web3 = web3
this.address = EMISSION_FUNDS_ADDRESS this.address = EMISSION_FUNDS_ADDRESS
} }
balance() { balance() {
return this.web3_10.eth.getBalance(this.address) return this.web3.eth.getBalance(this.address)
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,11 +6,10 @@ export default class KeysManager {
async init({ web3, netId }) { async init({ web3, netId }) {
const { KEYS_MANAGER_ADDRESS } = networkAddresses() const { KEYS_MANAGER_ADDRESS } = networkAddresses()
console.log('KeysManager address', KEYS_MANAGER_ADDRESS) console.log('KeysManager address', KEYS_MANAGER_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const keysManagerABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'KeysManager') const keysManagerABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'KeysManager')
this.instance = new web3_10.eth.Contract(keysManagerABI, KEYS_MANAGER_ADDRESS) this.instance = new web3.eth.Contract(keysManagerABI, KEYS_MANAGER_ADDRESS)
this.address = KEYS_MANAGER_ADDRESS this.address = KEYS_MANAGER_ADDRESS
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,14 +6,13 @@ export default class PoaConsensus {
async init({ web3, netId }) { async init({ web3, netId }) {
const { POA_ADDRESS } = networkAddresses() const { POA_ADDRESS } = networkAddresses()
console.log('POA address', POA_ADDRESS) console.log('POA address', POA_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const poaConsensusAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'PoaNetworkConsensus') const poaConsensusAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'PoaNetworkConsensus')
this.poaInstance = new web3_10.eth.Contract(poaConsensusAbi, POA_ADDRESS) this.instance = new web3.eth.Contract(poaConsensusAbi, POA_ADDRESS)
} }
async getValidators() { async getValidators() {
return await this.poaInstance.methods.getValidators().call() return await this.instance.methods.getValidators().call()
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,14 +6,13 @@ export default class ProxyStorage {
async init({ web3, netId }) { async init({ web3, netId }) {
const { PROXY_ADDRESS } = networkAddresses() const { PROXY_ADDRESS } = networkAddresses()
console.log('Proxy Storage address', PROXY_ADDRESS) console.log('Proxy Storage address', PROXY_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const proxyStorageAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'ProxyStorage') const proxyStorageAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'ProxyStorage')
this.proxyStorageInstance = new web3_10.eth.Contract(proxyStorageAbi, PROXY_ADDRESS) this.instance = new web3.eth.Contract(proxyStorageAbi, PROXY_ADDRESS)
} }
doesMethodExist(methodName) { doesMethodExist(methodName) {
return this.proxyStorageInstance && this.proxyStorageInstance.methods[methodName] return this.instance && this.instance.methods[methodName]
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { toAscii } from '../helpers' import { toAscii } from '../helpers'
@ -8,19 +7,18 @@ export default class ValidatorMetadata {
async init({ web3, netId }) { async init({ web3, netId }) {
const { METADATA_ADDRESS } = networkAddresses() const { METADATA_ADDRESS } = networkAddresses()
console.log('Metadata address', METADATA_ADDRESS) console.log('Metadata address', METADATA_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const MetadataAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'ValidatorMetadata') const MetadataAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'ValidatorMetadata')
this.metadataInstance = new web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS) this.instance = new web3.eth.Contract(MetadataAbi, METADATA_ADDRESS)
} }
async getValidatorFullName(miningKey) { async getValidatorFullName(miningKey) {
let validator let validator
if (this.metadataInstance.methods.getValidatorName) { if (this.instance.methods.getValidatorName) {
validator = await this.metadataInstance.methods.getValidatorName(miningKey).call() validator = await this.instance.methods.getValidatorName(miningKey).call()
} else { } else {
validator = await this.metadataInstance.methods.validators(miningKey).call() validator = await this.instance.methods.validators(miningKey).call()
} }
return { return {
firstName: toAscii(validator.firstName), firstName: toAscii(validator.firstName),

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,40 +6,37 @@ export default class VotingToChangeKeys {
async init({ web3, netId }) { async init({ web3, netId }) {
const { VOTING_TO_CHANGE_KEYS_ADDRESS } = networkAddresses() const { VOTING_TO_CHANGE_KEYS_ADDRESS } = networkAddresses()
console.log('VotingToChangeKeys address', VOTING_TO_CHANGE_KEYS_ADDRESS) console.log('VotingToChangeKeys address', VOTING_TO_CHANGE_KEYS_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToChangeKeysABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'VotingToChangeKeys') const votingToChangeKeysABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'VotingToChangeKeys')
this.votingToChangeKeysInstance = new web3_10.eth.Contract(votingToChangeKeysABI, VOTING_TO_CHANGE_KEYS_ADDRESS) this.instance = new web3.eth.Contract(votingToChangeKeysABI, VOTING_TO_CHANGE_KEYS_ADDRESS)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.address = VOTING_TO_CHANGE_KEYS_ADDRESS this.address = VOTING_TO_CHANGE_KEYS_ADDRESS
this.instance = this.votingToChangeKeysInstance
} }
//setters //setters
createBallot({ startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo }) { createBallot({ startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo }) {
if (this.votingToChangeKeysInstance.methods.createBallot) { if (this.instance.methods.createBallot) {
return this.votingToChangeKeysInstance.methods return this.instance.methods
.createBallot(startTime, endTime, ballotType, affectedKeyType, memo, affectedKey, miningKey) .createBallot(startTime, endTime, ballotType, affectedKeyType, memo, affectedKey, miningKey)
.encodeABI() .encodeABI()
} }
return this.votingToChangeKeysInstance.methods return this.instance.methods
.createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo) .createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo)
.encodeABI() .encodeABI()
} }
createBallotToAddNewValidator({ startTime, endTime, memo, affectedKey, newVotingKey, newPayoutKey }) { createBallotToAddNewValidator({ startTime, endTime, memo, affectedKey, newVotingKey, newPayoutKey }) {
return this.votingToChangeKeysInstance.methods return this.instance.methods
.createBallotToAddNewValidator(startTime, endTime, memo, affectedKey, newVotingKey, newPayoutKey) .createBallotToAddNewValidator(startTime, endTime, memo, affectedKey, newVotingKey, newPayoutKey)
.encodeABI() .encodeABI()
} }
vote(_id, choice) { vote(_id, choice) {
return this.votingToChangeKeysInstance.methods.vote(_id, choice).encodeABI() return this.instance.methods.vote(_id, choice).encodeABI()
} }
finalize(_id) { finalize(_id) {
return this.votingToChangeKeysInstance.methods.finalize(_id).encodeABI() return this.instance.methods.finalize(_id).encodeABI()
} }
//getters //getters
@ -48,47 +44,45 @@ export default class VotingToChangeKeys {
if (!this.doesMethodExist('areBallotParamsValid')) { if (!this.doesMethodExist('areBallotParamsValid')) {
return null return null
} }
return this.votingToChangeKeysInstance.methods return this.instance.methods.areBallotParamsValid(ballotType, affectedKey, affectedKeyType, miningKey).call()
.areBallotParamsValid(ballotType, affectedKey, affectedKeyType, miningKey)
.call()
} }
doesMethodExist(methodName) { doesMethodExist(methodName) {
return this.votingToChangeKeysInstance && this.votingToChangeKeysInstance.methods[methodName] return this.instance && this.instance.methods[methodName]
} }
nextBallotId() { nextBallotId() {
return this.votingToChangeKeysInstance.methods.nextBallotId().call() return this.instance.methods.nextBallotId().call()
} }
getBallotInfo(_id, _votingKey) { getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) { if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeKeysInstance.methods.getBallotInfo(_id).call() return this.instance.methods.getBallotInfo(_id).call()
} }
return this.votingToChangeKeysInstance.methods.votingState(_id).call() return this.instance.methods.votingState(_id).call()
} }
hasAlreadyVoted(_id, votingKey) { hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeKeysInstance.methods.hasAlreadyVoted(_id, votingKey).call() return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
} }
isValidVote(_id, votingKey) { isValidVote(_id, votingKey) {
return this.votingToChangeKeysInstance.methods.isValidVote(_id, votingKey).call() return this.instance.methods.isValidVote(_id, votingKey).call()
} }
isActive(_id) { isActive(_id) {
return this.votingToChangeKeysInstance.methods.isActive(_id).call() return this.instance.methods.isActive(_id).call()
} }
canBeFinalizedNow(_id) { canBeFinalizedNow(_id) {
if (this.doesMethodExist('canBeFinalizedNow')) { if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeKeysInstance.methods.canBeFinalizedNow(_id).call() return this.instance.methods.canBeFinalizedNow(_id).call()
} }
return null return null
} }
async getBallotLimit(_miningKey, _limitPerValidator) { async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeKeysInstance.methods.validatorActiveBallots(_miningKey).call() const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
return _limitPerValidator - _activeBallots return _limitPerValidator - _activeBallots
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,83 +6,75 @@ export default class VotingToChangeMinThreshold {
async init({ web3, netId }) { async init({ web3, netId }) {
const { VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS } = networkAddresses() const { VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS } = networkAddresses()
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS) console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToChangeMinThresholdABI = await helpers.getABI( const votingToChangeMinThresholdABI = await helpers.getABI(
constants.NETWORKS[netId].BRANCH, constants.NETWORKS[netId].BRANCH,
'VotingToChangeMinThreshold' 'VotingToChangeMinThreshold'
) )
this.votingToChangeMinThresholdInstance = new web3_10.eth.Contract( this.instance = new web3.eth.Contract(votingToChangeMinThresholdABI, VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
votingToChangeMinThresholdABI,
VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.address = VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS this.address = VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
this.instance = this.votingToChangeMinThresholdInstance
} }
//setters //setters
createBallot({ startTime, endTime, proposedValue, memo }) { createBallot({ startTime, endTime, proposedValue, memo }) {
let method let method
if (this.votingToChangeMinThresholdInstance.methods.createBallot) { if (this.instance.methods.createBallot) {
method = this.votingToChangeMinThresholdInstance.methods.createBallot method = this.instance.methods.createBallot
} else { } else {
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold method = this.instance.methods.createBallotToChangeThreshold
} }
return method(startTime, endTime, proposedValue, memo).encodeABI() return method(startTime, endTime, proposedValue, memo).encodeABI()
} }
vote(_id, choice) { vote(_id, choice) {
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).encodeABI() return this.instance.methods.vote(_id, choice).encodeABI()
} }
finalize(_id) { finalize(_id) {
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).encodeABI() return this.instance.methods.finalize(_id).encodeABI()
} }
//getters //getters
doesMethodExist(methodName) { doesMethodExist(methodName) {
if (this.votingToChangeMinThresholdInstance.methods[methodName]) { if (this.instance.methods[methodName]) {
return true return true
} }
return false return false
} }
nextBallotId() { nextBallotId() {
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call() return this.instance.methods.nextBallotId().call()
} }
getBallotInfo(_id, _votingKey) { getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) { if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call() return this.instance.methods.getBallotInfo(_id, _votingKey).call()
} }
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call() return this.instance.methods.votingState(_id).call()
} }
hasAlreadyVoted(_id, votingKey) { hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call() return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
} }
isValidVote(_id, votingKey) { isValidVote(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call() return this.instance.methods.isValidVote(_id, votingKey).call()
} }
isActive(_id) { isActive(_id) {
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call() return this.instance.methods.isActive(_id).call()
} }
canBeFinalizedNow(_id) { canBeFinalizedNow(_id) {
if (this.doesMethodExist('canBeFinalizedNow')) { if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call() return this.instance.methods.canBeFinalizedNow(_id).call()
} }
return null return null
} }
async getBallotLimit(_miningKey, _limitPerValidator) { async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeMinThresholdInstance.methods const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
.validatorActiveBallots(_miningKey)
.call()
return _limitPerValidator - _activeBallots return _limitPerValidator - _activeBallots
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,76 +6,71 @@ export default class VotingToChangeProxy {
async init({ web3, netId }) { async init({ web3, netId }) {
const { VOTING_TO_CHANGE_PROXY_ADDRESS } = networkAddresses() const { VOTING_TO_CHANGE_PROXY_ADDRESS } = networkAddresses()
console.log('VotingToChangeProxy address', VOTING_TO_CHANGE_PROXY_ADDRESS) console.log('VotingToChangeProxy address', VOTING_TO_CHANGE_PROXY_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToChangeProxyABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'VotingToChangeProxyAddress') const votingToChangeProxyABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'VotingToChangeProxyAddress')
this.votingToChangeProxyInstance = new web3_10.eth.Contract(votingToChangeProxyABI, VOTING_TO_CHANGE_PROXY_ADDRESS) this.instance = new web3.eth.Contract(votingToChangeProxyABI, VOTING_TO_CHANGE_PROXY_ADDRESS)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.address = VOTING_TO_CHANGE_PROXY_ADDRESS this.address = VOTING_TO_CHANGE_PROXY_ADDRESS
this.instance = this.votingToChangeProxyInstance
} }
//setters //setters
createBallot({ startTime, endTime, proposedValue, contractType, memo }) { createBallot({ startTime, endTime, proposedValue, contractType, memo }) {
if (!this.votingToChangeProxyInstance.methods.createBallot) { if (!this.instance.methods.createBallot) {
return this.votingToChangeProxyInstance.methods return this.instance.methods
.createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType, memo) .createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType, memo)
.encodeABI() .encodeABI()
} }
return this.votingToChangeProxyInstance.methods return this.instance.methods.createBallot(startTime, endTime, contractType, memo, proposedValue).encodeABI()
.createBallot(startTime, endTime, contractType, memo, proposedValue)
.encodeABI()
} }
vote(_id, choice) { vote(_id, choice) {
return this.votingToChangeProxyInstance.methods.vote(_id, choice).encodeABI() return this.instance.methods.vote(_id, choice).encodeABI()
} }
finalize(_id) { finalize(_id) {
return this.votingToChangeProxyInstance.methods.finalize(_id).encodeABI() return this.instance.methods.finalize(_id).encodeABI()
} }
//getters //getters
doesMethodExist(methodName) { doesMethodExist(methodName) {
if (this.votingToChangeProxyInstance.methods[methodName]) { if (this.instance.methods[methodName]) {
return true return true
} }
return false return false
} }
nextBallotId() { nextBallotId() {
return this.votingToChangeProxyInstance.methods.nextBallotId().call() return this.instance.methods.nextBallotId().call()
} }
getBallotInfo(_id, _votingKey) { getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) { if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeProxyInstance.methods.getBallotInfo(_id, _votingKey).call() return this.instance.methods.getBallotInfo(_id, _votingKey).call()
} }
return this.votingToChangeProxyInstance.methods.votingState(_id).call() return this.instance.methods.votingState(_id).call()
} }
hasAlreadyVoted(_id, votingKey) { hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeProxyInstance.methods.hasAlreadyVoted(_id, votingKey).call() return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
} }
isValidVote(_id, votingKey) { isValidVote(_id, votingKey) {
return this.votingToChangeProxyInstance.methods.isValidVote(_id, votingKey).call() return this.instance.methods.isValidVote(_id, votingKey).call()
} }
isActive(_id) { isActive(_id) {
return this.votingToChangeProxyInstance.methods.isActive(_id).call() return this.instance.methods.isActive(_id).call()
} }
canBeFinalizedNow(_id) { canBeFinalizedNow(_id) {
if (this.doesMethodExist('canBeFinalizedNow')) { if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeProxyInstance.methods.canBeFinalizedNow(_id).call() return this.instance.methods.canBeFinalizedNow(_id).call()
} }
return null return null
} }
async getBallotLimit(_miningKey, _limitPerValidator) { async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeProxyInstance.methods.validatorActiveBallots(_miningKey).call() const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
return _limitPerValidator - _activeBallots return _limitPerValidator - _activeBallots
} }
} }

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses' import { networkAddresses } from './addresses'
import helpers from './helpers' import helpers from './helpers'
import { constants } from '../constants' import { constants } from '../constants'
@ -7,14 +6,13 @@ export default class VotingToManageEmissionFunds {
async init({ web3, netId }) { async init({ web3, netId }) {
const { VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS } = networkAddresses() const { VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS } = networkAddresses()
console.log('VotingToManageEmissionFunds address', VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS) console.log('VotingToManageEmissionFunds address', VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToManageEmissionFundsABI = await helpers.getABI( const votingToManageEmissionFundsABI = await helpers.getABI(
constants.NETWORKS[netId].BRANCH, constants.NETWORKS[netId].BRANCH,
'VotingToManageEmissionFunds' 'VotingToManageEmissionFunds'
) )
this.instance = new web3_10.eth.Contract(votingToManageEmissionFundsABI, VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS) this.instance = new web3.eth.Contract(votingToManageEmissionFundsABI, VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS)
this.address = VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS this.address = VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS
} }

View File

@ -1,3 +1,4 @@
import Web3 from 'web3'
import { messages } from './messages' import { messages } from './messages'
import { constants } from './constants' import { constants } from './constants'
@ -9,7 +10,7 @@ let getWeb3 = () => {
// Checking if Web3 has been injected by the browser (Mist/MetaMask) // Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (window.ethereum) { if (window.ethereum) {
web3 = new window.Web3(window.ethereum) web3 = new Web3(window.ethereum)
console.log('Injected web3 detected.') console.log('Injected web3 detected.')
try { try {
await window.ethereum.enable() await window.ethereum.enable()
@ -19,7 +20,7 @@ let getWeb3 = () => {
return return
} }
} else if (typeof window.web3 !== 'undefined') { } else if (typeof window.web3 !== 'undefined') {
web3 = new window.Web3(window.web3.currentProvider) web3 = new Web3(window.web3.currentProvider)
console.log('Injected web3 detected.') console.log('Injected web3 detected.')
} else { } else {
console.error('Metamask not found') console.error('Metamask not found')
@ -27,40 +28,41 @@ let getWeb3 = () => {
return return
} }
web3.version.getNetwork((err, netId) => { const netId = await web3.eth.net.getId()
let netIdName console.log('netId', netId)
let errorMsg = null
console.log('netId', netId) let netIdName
let errorMsg = null
if (netId in constants.NETWORKS) { if (netId in constants.NETWORKS) {
netIdName = constants.NETWORKS[netId].NAME netIdName = constants.NETWORKS[netId].NAME
console.log(`This is ${netIdName}`) console.log(`This is ${netIdName}`)
} else { } else {
netIdName = 'ERROR' netIdName = 'ERROR'
errorMsg = messages.WRONG_NETWORK_MSG errorMsg = messages.WRONG_NETWORK_MSG
console.log('This is an unknown network.') console.log('This is an unknown network.')
} }
document.title = `${netIdName} - POA Network Governance DApp` document.title = `${netIdName} - POA Network Governance DApp`
if (errorMsg !== null) { if (errorMsg !== null) {
reject({ message: errorMsg }) reject({ message: errorMsg })
return return
} }
var defaultAccount = web3.eth.defaultAccount || null const accounts = await web3.eth.getAccounts()
if (defaultAccount === null) {
reject({ message: messages.NO_METAMASK_MSG })
return
}
resolve({ var defaultAccount = accounts[0] || null
web3Instance: web3, if (defaultAccount === null) {
netIdName, reject({ message: messages.NO_METAMASK_MSG })
netId, return
defaultAccount }
})
resolve({
web3Instance: web3,
netIdName,
netId,
defaultAccount
}) })
}) })
}) })

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import swal from 'sweetalert2' import swal from 'sweetalert2'
import { constants } from './constants' import { constants } from './constants'
@ -23,7 +22,7 @@ function sleep(ms) {
function sendTransactionByVotingKey(props, to, data, cb, warning) { function sendTransactionByVotingKey(props, to, data, cb, warning) {
const { commonStore, contractsStore } = props const { commonStore, contractsStore } = props
const web3 = new Web3(contractsStore.web3Instance.currentProvider) const web3 = contractsStore.web3Instance
web3.eth.sendTransaction( web3.eth.sendTransaction(
{ {

View File

@ -61,13 +61,13 @@ class ContractsStore {
@action('Get keys ballot threshold') @action('Get keys ballot threshold')
getKeysBallotThreshold = async () => { getKeysBallotThreshold = async () => {
this.keysBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getBallotThreshold(1).call() this.keysBallotThreshold = await this.ballotsStorage.instance.methods.getBallotThreshold(1).call()
this.minThresholdBallotThreshold = this.keysBallotThreshold this.minThresholdBallotThreshold = this.keysBallotThreshold
} }
@action('Get proxy ballot threshold') @action('Get proxy ballot threshold')
getProxyBallotThreshold = async () => { getProxyBallotThreshold = async () => {
this.proxyBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getProxyThreshold().call() this.proxyBallotThreshold = await this.ballotsStorage.instance.methods.getProxyThreshold().call()
this.emissionFundsBallotThreshold = this.proxyBallotThreshold this.emissionFundsBallotThreshold = this.proxyBallotThreshold
} }
@ -176,7 +176,7 @@ class ContractsStore {
@action('Get validators length') @action('Get validators length')
getValidatorsLength = async () => { getValidatorsLength = async () => {
this.validatorsLength = await this.poaConsensus.poaInstance.methods.getCurrentValidatorsLength().call() this.validatorsLength = await this.poaConsensus.instance.methods.getCurrentValidatorsLength().call()
} }
@action('Set voting key') @action('Set voting key')
@ -389,9 +389,7 @@ class ContractsStore {
@action @action
async getBallotsLimits() { async getBallotsLimits() {
if (this.web3Instance && this.netId) { if (this.web3Instance && this.netId) {
const limitPerValidator = await this.ballotsStorage.ballotsStorageInstance.methods const limitPerValidator = await this.ballotsStorage.instance.methods.getBallotLimitPerValidator().call()
.getBallotLimitPerValidator()
.call()
let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.miningKey, limitPerValidator) let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.miningKey, limitPerValidator)
let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(this.miningKey, limitPerValidator) let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(this.miningKey, limitPerValidator)