diff --git a/CHANGELOG.md b/CHANGELOG.md index de847c1..3640018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,4 @@ v.2 - updated database structure - shell script update - crypto sig on auth +- support 2n passphrase diff --git a/README.md b/README.md index fd6ef1c..ea9f565 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ http://host_ip:3007/ ``` cd rewarder +sh stop.sh git pull +npm install sh restart.sh ``` diff --git a/routes/v2/api.js b/routes/v2/api.js index 0867f62..1b07036 100644 --- a/routes/v2/api.js +++ b/routes/v2/api.js @@ -77,6 +77,7 @@ class Reward { data.day = config.day; data.minVote = config.minVote; data.daysLeft = daysLeft; + data.daysPending = config.daysPending; data.port = config.port; data.totalForged = (await this.getForged()).forged / 10 ** 8; @@ -91,7 +92,6 @@ class Reward { } - /** sign & send delegate stats on server statistics **/ async sendGlobalStats() { let data = { @@ -174,7 +174,7 @@ class Reward { /** Remove from active if unvote **/ for (let j = 0; j < activeVotersArray.length; j++) { let removeVote = true; - for (let i=0; i < voters.length; i++) { + for (let i = 0; i < voters.length; i++) { if (activeVotersArray[j].address === voters[i].address) { removeVote = false; break; @@ -230,13 +230,16 @@ class Reward { async calcPercents() { let delegate = await dbUtils.dbGet(db, 'DELEGATE'); - let voters = await dbUtils.dbArray(db, '1', '2'); - let forPay = delegate.roundForged * (config.percent / 100); - for (let i = 0; i < voters.length; i++) { - voters[i].percent = (100 / delegate.vote * voters[i].balance).toFixed(2) * 1; - voters[i].waitPay = (voters[i].percent / 100 * forPay).toFixed(3) * 1; - await db.put('1x' + voters[i].address, voters[i]) + if (delegate) { + let voters = await dbUtils.dbArray(db, '1', '2'); + let forPay = delegate.roundForged * (config.percent / 100); + for (let i = 0; i < voters.length; i++) { + voters[i].percent = (100 / delegate.vote * voters[i].balance).toFixed(2) * 1; + voters[i].waitPay = (voters[i].percent / 100 * forPay).toFixed(3) * 1; + await db.put('1x' + voters[i].address, voters[i]) + } } + } @@ -279,16 +282,19 @@ class Reward { let activeVoters = await dbUtils.dbObj(db, '1', '2'); for (let i = 0; i < voters.length; i++) { if (!activeVoters['1x' + voters[i].address] && !pendingVoters['0x' + voters[i].address]) { + let balance = parseInt((voters[i].balance / 10 ** 8).toFixed(0)); /** set in pending voter **/ - await db.put('0x' + voters[i].address, { - username: voters[i].username, - address: voters[i].address, - publicKey: voters[i].publicKey, - balance: parseInt((voters[i].balance / 10 ** 8).toFixed(0)), - timestamp: Math.floor(Date.now() / 1000), - }); - console.log('new pending voter', voters[i]); - await this.calcPercents(); + if (balance >= config.minVote) { + await db.put('0x' + voters[i].address, { + username: voters[i].username, + address: voters[i].address, + publicKey: voters[i].publicKey, + balance: balance, + timestamp: Math.floor(Date.now() / 1000), + }); + console.log('new pending voter', voters[i]); + await this.calcPercents(); + } } } } @@ -427,5 +433,4 @@ router.get('/total-info', async function (req, res, next) { }); - module.exports = router; diff --git a/stop.sh b/stop.sh index b5145b0..9775cd2 100644 --- a/stop.sh +++ b/stop.sh @@ -1,2 +1 @@ forever stop bin/www -forever stop worker.js