-
Notifications
You must be signed in to change notification settings - Fork 2
/
blockfiller2.js
54 lines (43 loc) · 1.11 KB
/
blockfiller2.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
const { newtx, listUnspent } = require('./btc');
var count = 0;
main();
async function main() {
console.log('Listing UTXOs');
var s = (await listUnspent({ minamount: 110e-8, minconf: 0 }, false))
.filter(u => u.spendable && u.solvable);
console.log(`Found ${s.length} usable UTXO${s.length == 1 ? '' : 's'}`);
if (s.length < 0) {
console.log('No UTXOs!');
process.exit(1);
}
console.log('Sending TXs of 109.25 vB each');
const work = [];
const workers = 4;
const share = s.length / workers;
for (var i = 0; i < workers; i++) {
work.push(s.slice(i * share, workers - 1 == i ? undefined : ((i+1) * share)));
}
work.forEach((x, i) => {
loop(s, i+1);
});
}
async function loop(s, i) {
while (s.length) {
const u = s.shift();
if (u.amount < 110e-8) {
continue;
}
const amount = parseFloat((u.amount - 110e-8).toFixed(8));
const out = {};
const address = u.address;
out[address] = amount;
try {
const txid = await newtx([ u ], out);
s.push({ txid, vout: 0, address, amount });
count++;
console.log(`(${i}) Sent transaction txid=${txid} (#${count})`);
}
catch (e) {
}
}
}