(Update) Add calling ValidatorMetadata.isValidatorAlreadyVoted

This commit is contained in:
Vadim Arasev 2018-08-07 11:53:06 +03:00
parent da23b16622
commit 422995b51f
4 changed files with 28 additions and 29 deletions

View File

@ -43,14 +43,10 @@ class App extends Component {
this.setIsValidVotingKey.call(this)
}
async setMetadata() {
const currentData = await this.getMetadataContract().getValidatorData({
votingKey: this.getVotingKey()
})
const currentData = await this.getMetadataContract().getValidatorData(this.getMiningKey())
const hasData = currentData.postal_code ? true : false
this.defaultValues = currentData
const pendingChange = await this.getMetadataContract().getPendingChange({
votingKey: this.getVotingKey()
})
const pendingChange = await this.getMetadataContract().getPendingChange(this.getMiningKey())
if (Number(pendingChange.minThreshold) > 0) {
var msg = `
First Name: <b>${pendingChange.firstName}</b> <br/>
@ -91,6 +87,9 @@ class App extends Component {
getVotingKey() {
return this.props.web3Config.votingKey
}
getMiningKey() {
return this.props.web3Config.miningKey
}
checkValidation() {
const isAfter = moment(this.state.form.expirationDate).isAfter(moment())
let keys = Object.keys(this.state.form)

View File

@ -15,4 +15,7 @@ export default class KeysManager {
async isVotingActive(votingKey) {
return await this.keysInstance.methods.isVotingActive(votingKey).call()
}
async miningKeyByVoting(votingKey) {
return await this.keysInstance.methods.miningKeyByVoting(votingKey).call()
}
}

View File

@ -77,8 +77,7 @@ export default class Metadata {
}
}
async getValidatorData({ votingKey, miningKey }) {
miningKey = miningKey || (await this.getMiningByVoting(votingKey))
async getValidatorData(miningKey) {
if (!miningKey) {
helpersGlobal.generateAlert('warning', 'Warning!', messages.invalidaVotingKey)
return {}
@ -102,16 +101,6 @@ export default class Metadata {
}
}
async getMiningByVoting(votingKey) {
let miningKey
try {
miningKey = await this.metadataInstance.methods.getMiningByVotingKey(votingKey).call()
} catch (e) {
console.log(e.message)
}
return miningKey
}
async getAllValidatorsData(netId) {
let all = []
return new Promise(async (resolve, reject) => {
@ -125,7 +114,7 @@ export default class Metadata {
}
data = this.getMocData()
} else {
data = await this.getValidatorData({ miningKey: key })
data = await this.getValidatorData(key)
}
data.address = key
all.push(data)
@ -134,8 +123,7 @@ export default class Metadata {
})
}
async getPendingChange({ votingKey, miningKey }) {
miningKey = miningKey || (await this.getMiningByVoting(votingKey))
async getPendingChange(miningKey) {
if (!miningKey) {
helpersGlobal.generateAlert('warning', 'Warning!', messages.invalidaVotingKey)
return {}
@ -163,7 +151,7 @@ export default class Metadata {
async getAllPendingChanges() {
let pendingChanges = []
for (let key of this.miningKeys) {
let pendingChange = await this.getPendingChange({ miningKey: key })
let pendingChange = await this.getPendingChange(key)
pendingChange.address = key
if (pendingChange.postal_code) {
pendingChanges.push(pendingChange)
@ -172,18 +160,24 @@ export default class Metadata {
return pendingChanges
}
async confirmPendingChange({ miningKeyToConfirm, senderVotingKey }) {
let alreadyConfirmed = await this.metadataInstance.methods
.isAddressAlreadyVoted(miningKeyToConfirm, senderVotingKey)
.call()
async confirmPendingChange({ miningKeyToConfirm, senderVotingKey, senderMiningKey }) {
let alreadyConfirmed
if (this.metadataInstance.methods.isValidatorAlreadyVoted) {
alreadyConfirmed = await this.metadataInstance.methods
.isValidatorAlreadyVoted(miningKeyToConfirm, senderMiningKey)
.call()
} else {
alreadyConfirmed = await this.metadataInstance.methods
.isAddressAlreadyVoted(miningKeyToConfirm, senderVotingKey)
.call()
}
console.log(alreadyConfirmed)
if (alreadyConfirmed) {
throw {
message: `You already confirmed this change.`
}
}
const miningKeySender = await this.getMiningByVoting(senderVotingKey)
if (miningKeySender === miningKeyToConfirm) {
if (senderMiningKey === miningKeyToConfirm) {
throw {
message: `You cannot confirm your own changes.\n
Please ask other validators to verify your new information.`

View File

@ -58,6 +58,7 @@ class AppMainRouter extends Component {
metadataContract: null,
poaConsensus: null,
votingKey: null,
miningKey: null,
loading: true,
searchTerm: '',
injectedWeb3: true,
@ -86,6 +87,7 @@ class AppMainRouter extends Component {
})
this.setState({
votingKey: web3Config.defaultAccount,
miningKey: await keysManager.miningKeyByVoting(web3Config.defaultAccount),
keysManager,
metadataContract,
loading: false,
@ -139,7 +141,8 @@ class AppMainRouter extends Component {
try {
let result = await this.state.metadataContract[methodToCall]({
miningKeyToConfirm: miningKey,
senderVotingKey: this.state.votingKey
senderVotingKey: this.state.votingKey,
senderMiningKey: this.state.miningKey
})
console.log(result)
this.setState({ loading: false })