-
Notifications
You must be signed in to change notification settings - Fork 41
/
rankGYA.js
52 lines (46 loc) · 1.38 KB
/
rankGYA.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
const Web3 = require('web3');
const GYAContract = require('./data/GyaanToken.js');
const colors = require('colors/safe');
const students = require('./addresses.json');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://gyaan.network:8545'));
var abi = JSON.parse(GYAContract.abi);
var instance = new web3.eth.Contract(abi, GYAContract.address);
var map = new Map();
var promises = [];
for (i = 0; i < students.length; i++) {
((i) => {
promises.push(
instance.methods.balanceOf(students[i].address.toLowerCase()).call()
.then((result) => {
map.set(students[i].name, result);
return Promise.resolve(0);
})
);
})(i);
}
Promise.all(promises)
.then(() => {
map[Symbol.iterator] = function* () {
yield* [...this.entries()].sort((a, b) => b[1] - a[1]);
}
console.log('');
var counter = 0;
for (let [key, value] of map) { // get data sorted
var ksize = key.length;
var vsize = (''+value).length;
var comp = '';
for (i = 0; i < 40 - ksize - vsize; i++) {
comp += '-';
}
var sp = ' ';
if (counter < 9) sp += ' ';
if (value > 5000) {
console.log(colors.green('\t' + sp + (counter+1) + ' - ' + key + comp + value));
} else {
console.log(colors.yellow('\t' + sp + (counter+1) + ' - ' + key + comp + value));
}
counter++;
}
console.log('');
});