forked from GenerEOSAus/airdrop-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturnSnapshot.js
123 lines (105 loc) · 3.19 KB
/
returnSnapshot.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Eos = require('eosjs');
fs = require("fs");
Papa = require("papaparse");
filename = "payment-" + Date.now() + ".csv";
process.on('unhandledRejection', error => {
// Nodejs generic handler
});
airdropConfig = {
contract: 'democoindrop',
privKey: '',
symbol: 'DEMO',
precision: 4,
minimum: '1.0000 DEMO', //minimum award
threshold: 1, //minimum awarded to anyone below this threshold
memo: "Have a DEMO coin",
}
eosConfig = {
chainId: '038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca', // 32 byte (64 char) hex string
keyProvider: [airdropConfig.privKey], // WIF string or array of keys..
httpEndpoint: 'http://jungle.cryptolions.io:38888', //probably localhost
expireInSeconds: 60,
broadcast: true, //set to false for testing
verbose: false, // API and transactions
debug: false,
sign: true,
//mockTransactions: () => 'fail', //use this to test success and fail
}
eosClient = Eos(eosConfig);
async function Payment(tr,name,quantity) {
return tr.recover(
name.toString().trim(), //the person losing the airdrop
`${airdropConfig.precision},${airdropConfig.symbol}`, //the symbol
{authorization: airdropConfig.contract}
);
}
async function IssuePayment(names) {
//we create a transaction with multiple issue actions
return eosClient.transaction(airdropConfig.contract,tr => {
for(let i = 0; i < names.length; i++) {
if(names[i][0] !== "") {
Payment(tr,names[i][0],names[i][1]);
}
}
},{broadcast: eosConfig.broadcast});
}
async function PayAllAccounts() {
//read the snapshot.csv file
fs.readFile(__dirname + '/' + 'snapshot.csv', 'utf8', async function (err,csv) {
if (err) {
return console.log(err);
}
var data = Papa.parse(csv).data;
let total = data.length;
let start = Date.now();
console.log(start);
console.log("Found " + total + " accounts.");
let proc = 0;
fs.appendFile(__dirname + '/' + filename, 'name,payment,processed', (err) => {
if (err) throw err;
});
//we get a chunk of 30 payments at a time
while(data.length > 0) {
let names = data.splice(0,30);
let success = false;
let done = false;
let attempts = 0;
proc += names.length;
while(!done) {
if(attempts < 3) {
try {
await IssuePayment(names);
success = true;
done = true;
} catch(e) {
console.log("Failed, retrying segement " + proc + "...");
attempts++;
}
} else {
done = true;
}
}
names.map(name => {
let formatted = {
name: name[0],
payment: name[1],
processed: success
};
var write = Papa.unparse([formatted],{header:false});
fs.appendFile(__dirname + '/' + filename, '\n'+write, (err) => {
if (err) throw err;
});
})
process.stdout.write("Have processed " + proc + " of " + total + "\r");
}
let end = Date.now();
console.log(end);
console.log("Have processed " + proc + " of " + total);
console.log("Done");
});
}
async function run() {
await PayAllAccounts();
}
// Let's do it!!!
run();