-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergeSendReceive.js
46 lines (43 loc) · 1.14 KB
/
mergeSendReceive.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
// Merges SEND with the immediate next RECEIVE. These transactions moves fund
// between the accounts that I own.
const fs = require('fs');
const csv = require('csv')
const Line = require('./line.js');
const argv = require('yargs')
.option('input', {
demandOption: true,
describe: 'The path of the input file'
})
.help()
.strict()
.argv
lines = []
fs.createReadStream(argv.input)
.pipe(csv.parse())
.on('data', (row) => {
if (row === null) {
return;
}
lines.push(new Line(...row))
})
.on('end', () => {
var i = 0;
while (i < lines.length-1) {
let n = i;
if ((lines[n].action === 'SEND' && lines[n+1].action === 'RECEIVE' ||
lines[n].action === 'RECEIVE' && lines[n+1].action === 'SEND') &&
lines[n].volume.gte(lines[n+1].volume)) {
lines[n].merge(lines[n+1]);
i += 1;
}
i += 1
if (lines[n].volume.eq(0) && lines[n].fee.eq(0)) {
continue;
}
if (lines[n].action === 'SEND' && lines[n].volume.eq(0)) {
lines[n].action = 'FEE';
}
console.log(lines[n].toString());
}
console.log(lines[i].toString());
})