Skip to content

Commit

Permalink
Merge pull request #5 from smartholdem/v2.0
Browse files Browse the repository at this point in the history
V2.0
  • Loading branch information
technologiespro authored Sep 26, 2020
2 parents 267c282 + e554d75 commit e8288dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ v.2
- updated database structure
- shell script update
- crypto sig on auth
- support 2n passphrase
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ http://host_ip:3007/

```
cd rewarder
sh stop.sh
git pull
npm install
sh restart.sh
```

Expand Down
41 changes: 23 additions & 18 deletions routes/v2/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -91,7 +92,6 @@ class Reward {
}



/** sign & send delegate stats on server statistics **/
async sendGlobalStats() {
let data = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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])
}
}

}


Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down Expand Up @@ -427,5 +433,4 @@ router.get('/total-info', async function (req, res, next) {
});



module.exports = router;
1 change: 0 additions & 1 deletion stop.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
forever stop bin/www
forever stop worker.js

0 comments on commit e8288dd

Please sign in to comment.