Updated proxy to support new votes processes

This commit is contained in:
Kirill Fedoseev 2019-10-02 18:50:46 +03:00
parent f34b372ea7
commit 5f380fb9b8
2 changed files with 37 additions and 1 deletions

View File

@ -188,6 +188,7 @@ contract Bridge {
votes[keccak256(abi.encodePacked(uint(6), nextEpoch, msg.sender))] = true;
if (++votesCount[keccak256(abi.encodePacked(uint(6), nextEpoch))] == getThreshold() + 1) {
nextEpoch++;
status = 1;
states[nextEpoch].threshold = threshold;
states[nextEpoch].validators = validators;
}

View File

@ -50,10 +50,12 @@ const votesProxyApp = express()
votesProxyApp.use(express.json())
votesProxyApp.use(express.urlencoded({ extended: true }))
votesProxyApp.get('/vote/startVoting', voteStartVoting)
votesProxyApp.get('/vote/startKeygen', voteStartKeygen)
votesProxyApp.get('/vote/cancelKeygen', voteCancelKeygen)
votesProxyApp.get('/vote/addValidator/:validator', voteAddValidator)
votesProxyApp.get('/vote/removeValidator/:validator', voteRemoveValidator)
votesProxyApp.get('/vote/changeThreshold/:threshold', voteChangeThreshold)
votesProxyApp.get('/info', info)
async function main () {
@ -269,6 +271,18 @@ function parseError (message) {
return result ? result[0] : ''
}
async function voteStartVoting (req, res) {
console.log('Voting for starting new epoch voting process')
const query = bridge.methods.voteStartVoting()
try {
await homeSendQuery(query)
} catch (e) {
console.log(e)
}
res.send('Voted')
console.log('Voted successfully')
}
async function voteStartKeygen (req, res) {
console.log('Voting for starting new epoch keygen')
const query = bridge.methods.voteStartKeygen()
@ -305,6 +319,18 @@ async function voteAddValidator (req, res) {
console.log('Voted successfully')
}
async function voteChangeThreshold (req, res) {
console.log('Voting for changing threshold')
const query = bridge.methods.voteChangeThreshold(req.params.theshold)
try {
await homeSendQuery(query)
} catch (e) {
console.log(e)
}
res.send('Voted')
console.log('Voted successfully')
}
async function voteRemoveValidator (req, res) {
console.log('Voting for removing validator')
const query = bridge.methods.voteRemoveValidator(req.params.validator)
@ -317,6 +343,15 @@ async function voteRemoveValidator (req, res) {
console.log('Voted successfully')
}
function decodeStatus(status) {
switch (status) {
case 0: return 'ready'
case 1: return 'voting'
case 2: return 'keygen'
case 3: return 'funds_transfer'
}
}
async function info (req, res) {
console.log('Info start')
const [ x, y, epoch, nextEpoch, threshold, nextThreshold, validators, nextValidators, homeBalance, status ] = await Promise.all([
@ -345,7 +380,7 @@ async function info (req, res) {
homeBalance,
foreignBalanceTokens: parseFloat(balances[FOREIGN_ASSET]) || 0,
foreignBalanceNative: parseFloat(balances['BNB']) || 0,
bridgeStatus: status ? (status === 1 ? 'keygen' : 'funds transfer') : 'ready'
bridgeStatus: decodeStatus(status)
})
console.log('Info end')
}