forked from coderofstuff/kaspa-transaction-report
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (44 loc) · 1.65 KB
/
index.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
const fs = require('fs');
const readline = require('readline');
const {validateAddress} = require('./src/utils');
const {generateReport} = require('./src/report');
function writeToFile(txs, outputFile) {
const writer = fs.createWriteStream(outputFile);
writer.write('"Date","Sent Amount","Sent Currency","Received Amount","Received Currency","Fee Amount","Fee Currency","TxHash"\n');
let prev = null;
txs[0].forEach((tx) => {
if (prev && prev.txHash == tx.txHash) {
return;
}
if (!tx.compound && !tx.sendToSelf) {
writer.write(`"${tx.timestamp}","${tx.sendAmount || ''}","${tx.sendAmount ? 'KLS' : ''}","${tx.receiveAmount || ''}","${tx.receiveAmount ? 'KLS' : ''}","${tx.sendAmount ? tx.feeAmount : ''}","${tx.sendAmount ? 'KLS' : ''}","${tx.txHash}"\n`);
}
prev = tx;
});
if (txs[1].length !== 0) {
console.info('Additional addresses found which may also belong to you:')
txs[1].forEach((address) => {
console.info(address);
});
}
writer.end();
}
async function parseAddresses() {
const addresses = [];
const readStream = fs.createReadStream('./addresses.txt');
const readLineInterface = readline.createInterface({
input: readStream,
crlfDelay: Infinity,
});
for await (const address of readLineInterface) {
if (validateAddress(address)) {
addresses.push(address);
}
}
return addresses;
}
if (require.main === module) {
parseAddresses()
.then(generateReport)
.then((processedTxs) => writeToFile(processedTxs, 'karlsen-transactions.csv'));
}