forked from joticajulian/ocdb-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateDelegators.js
69 lines (58 loc) · 2.12 KB
/
updateDelegators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var firebase = require('firebase-admin');
var config = require('./config.js')
const delegations = require("./ocdb_delegations.json");
firebase.initializeApp({
credential: firebase.credential.cert(config.firebaseCredentials),
databaseURL: 'https://steem-bid-bot.firebaseio.com/'
});
var ref = firebase.database().ref(config.account);
function printDelegator(d) {
const delegator = d.delegator + " ".repeat(20 - d.delegator.length);
const amount = " ".repeat(18 - d.vesting_shares.amount.length) + (parseInt(d.vesting_shares.amount)/1000000).toFixed(6) + " VESTS";
console.log(`${delegator}${amount}`);
}
(async () => {
console.log(`There are ${delegations.length} delegators:`);
console.log("Sorted by delegation")
delegations.sort((a,b) => parseInt(b.vesting_shares.amount) - parseInt(a.vesting_shares.amount));
delegations.forEach(printDelegator);
console.log(`
`)
console.log("Sorted by name")
delegations.sort((a,b) => a.delegator.localeCompare(b.delegator));
delegations.forEach(printDelegator);
for(var i in delegations) {
if(i > 0 && delegations[i].delegator === delegations[i-1].delegator) console.log("repeated "+delegations[i].delegator)
}
const delegators = {};
delegations.forEach(d => {
const delegator = d.delegator.replace(/[.]/g,",");
delegators[delegator] = {
curation_reward_percentage: 100,
donation_sbd: 0,
donation_sp: 0,
donation_steem: 0,
sbd_reward_percentage: 100,
vesting_shares: (parseInt(d.vesting_shares.amount)/1000000).toFixed(6) + " VESTS",
};
switch(delegator) {
case "thejohalfiles":
delegators[delegator].send_to = "singhcapital";
break;
case "blocktrades":
delegators[delegator].send_to = "alpha";
break;
default:
break;
}
});
// check accounts with send_to
/* ref.child("delegators").once("value", function(snapshot) {
const fd = snapshot.val();
for(var i in fd)
if(fd[i].send_to) console.log(fd[i]);
}); */
// update delegations in firebase
/* ref.child('delegators').set(delegators)
console.log("delegators updated in firebase"); */
})()