-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
50 lines (42 loc) · 1.31 KB
/
test.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
var fs = require('fs');
var csv = require('fast-csv');
var BigNumber = require('bignumber.js');
var net = require('net');
var Web3 = require('web3');
//change this
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'),net);
// Reading from csv File and push into transferAddress array
let allocData = new Array();
let sentLogs = new Array();
let count = 0;
function readFile() {
return new Promise((resolve, reject) => {
var stream = fs.createReadStream("distribute.csv");
var csvStream = csv()
.on("data", function(data){
if(count > 0) {
let mapObject = {};
let isAddress = web3.utils.isAddress(data[0]);
if(isAddress && data[0]!=null && data[0]!='' ){
console.log(data[0]);
data[1] = parseFloat(data[1]);
if(data[1]!='' && data[1]!=null && data[1]>0){
console.log(data[1]);
mapObject['address'] = data[0];
mapObject['token'] = data[1];
allocData.push(mapObject);
}
}
}
count++;
})
.on("end", function(){
console.log("done");
console.log(allocData)
// printFile();
resolve(allocData);
});
stream.pipe(csvStream);
});
}
readFile()