-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.js
83 lines (71 loc) · 2.6 KB
/
init.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
The list of airdrop targets should have this format:
{ "data" :
[
{ address: "T5Jh32mxV89EW5BM12DOpe42PhH", reward: 23 },
{ address: "...........................", reward: 32234 },
]
}
*/
const TronWeb = require('tronweb');
const privateKey = process.env.PK;
const reports = require("./reports.js");
const tronWeb = new TronWeb(
'https://api.trongrid.io',
'https://api.trongrid.io',
'https://api.trongrid.io',
privateKey,
);
var menu = require("./menu.js");
var tronair = require("./airdropper.js");
var cmd = require("./cmd.js");
async function start(){
var airdrop = await cmd.collectData(tronWeb); //Analize command line 'argv' and if airdrop info is provided via command line, collect it..
if(airdrop.human){ //if not, the collect it via human interactive prompt
airdrop = await menu.collectData(tronWeb); //Collect airdrop info via prompt interaction
}
//console.log({airdrop});
var list;
switch(airdrop.criteria){
case airdrop.CRITERIAS.VOTERS_PROPORTIONAL:
case airdrop.CRITERIAS.VOTERS_EQUAL:
var sr = require("./voters.js");
list = await sr.getVoters(airdrop);
break;
case airdrop.CRITERIAS.HOLDERS_PROPORTIONAL:
var token2 = require("./holders.js");
list = await token2.getHolders(airdrop);
break;
case airdrop.CRITERIAS.HOLDERS_EQUAL:
var token2 = require("./holders.js");
list = await token2.getHolders(airdrop);
break;
case airdrop.CRITERIAS.CSV:
// var fileManager = require("./csv.js");
//list = await fileManager.getList(airdrop);
break;
}
if(airdrop.human)
process.stdout.write("Sorting wallets by amount...\r");
list = list.sort(function (a, b) { return b.amount - a.amount; }); //ORDER DESC by amount
//console.log( JSON.stringify(list));
//console.log( {airdrop});
airdrop.list = list;
var yesno = true;
if(airdrop.human){
yesno = await reports.confirmBefore(tronWeb, airdrop);
process.stdout.write("Removing zeros...\r");
}
list = list.filter(function (x) { return x.amount > 0; }); //ORDER DESC by amount
airdrop.list = list;
//console.log(JSON.stringify(list));
if(yesno){ //THE ACTUAL AIRDROP HAPPENS HERE!!!!
var air_results = await tronair.doAirdrop(tronWeb, airdrop, true);
reports.explainResults(airdrop, air_results);
//console.log({air_results});
}
return airdrop;
}
module.exports.start = start;
//var test = false;
//var m = start();