-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.js
executable file
·201 lines (172 loc) · 6.02 KB
/
cli.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const log = require("debug")("pewpew");
import qrcode from "qrcode-terminal"
import program from "commander"
const readline = require("readline");
import { fire } from "./fire"
import * as bit from "./bit"
import * as utxos from "./utxos"
import * as split from "./split"
import { B2P2PBackend, BitworkBackend } from "./backends"
program.on('--help', function(){
console.log('')
console.log('Usage:');
console.log(' $ pewpew generate');
console.log(' $ pewpew address');
console.log(' $ pewpew split');
console.log(' $ pewpew fire 1Jpgfg9fFNKVVGxYgUhuKhdbxTSKBUnVf4');
console.log('')
});
async function balance() {
let bundle = await bit.fetch();
if (!bundle) {
log(`error finding address information, please inspect you .bit file`);
return;
}
utxos.utxos(bundle.ADDRESS).then(results => {
let balance = 0;
for (const utxo of results) {
balance += utxo.satoshis;
}
console.log(`\nBALANCE ${balance}`);
}).catch(e => {
console.log(`ERROR while fetching utxos ${e.message}`);
});
}
async function showutxos() {
let bundle = await bit.fetch();
if (!bundle) {
log(`error finding address information, please inspect you .bit file`);
return;
}
utxos.utxos(bundle.ADDRESS).then(results => {
let balance = 0;
for (const utxo of results) {
console.log(`${utxo.satoshis} ${utxo.txid}:${utxo.vout}`);
balance += utxo.satoshis;
}
console.log(`UTXOS ${results.length}`);
console.log(`\nBALANCE ${balance}`);
}).catch(e => {
console.log(`ERROR while fetching utxos ${e.message}`);
});
}
async function address() {
let bundle = await bit.fetch();
if (!bundle) {
log(`error finding address information, please inspect you .bit file`);
return;
}
qrcode.generate(`bitcoin:${bundle.ADDRESS}`, function(message) {
console.log("\n");
console.log("🔫 Pew Pew Transaction Shooter Address");
console.log("\n");
console.log(message);
console.log("\nADDRESS", bundle.ADDRESS);
balance();
});
}
program.version("0.0.1");
program
.command("generate")
.description("Generate address")
.action(async function() {
let bundle = await bit.fetch();
if (bundle) {
log(`already generated address`);
} else {
log(`generating address`);
bundle = await bit.generate();
log(`generated address ${bundle.ADDRESS}`);
address();
}
});
program
.command("address")
.description("Display address")
.action(async function() {
address();
});
program
.command("balance")
.description("Display balance for address")
.action(async function() {
balance();
});
program
.command("utxos")
.description("Display utxos for address")
.action(async function() {
showutxos();
});
program
.command("split")
.description("Split utxos in preparation for firing")
.option("-s, --satoshis <satoshis>", "Change the number of satoshis to send, by default 1000")
.option("-l, --limit <limit>", "Maximum number of utxos, by default 25")
.action(async function(args) {
let bundle = await bit.fetch();
if (!bundle) {
log(`error finding address information, please inspect you .bit file`);
return;
}
const satoshis = (args.satoshis ? Number(args.satoshis) : 1000);
const limit = (args.limit ? Number(args.limit) : 25);
split.split(bundle.PRIVATE, limit, satoshis).then(function() {
console.log("FINISHED splitting utxos");
}).catch(e => {
console.log(`ERROR while splitting utxos ${e.message}`);
});
});
program
.command("fire <address> [number]")
.option("-s, --satoshis <satoshis>", "Change the number of satoshis to send, by default 800")
.description("Fire Pew Pew, sending num Bitcoin transactions to an address")
.action(async function(address, number, args) {
let bundle = await bit.fetch();
if (!bundle) {
log(`error finding address information, please inspect you .bit file`);
return;
}
const satoshis = (args.satoshis ? Number(args.satoshis) : 800);
if (!address) {
console.log(`ERROR invalid address`);
process.exit();
}
const num = (number ? Number(number) : 10);
const prompt = readline.createInterface(process.stdin, process.stdout);
console.log("===================================================");
console.log("⚠️ WARNING ⚠️");
console.log(`\nAre you sure you want to FIRE at`);
console.log(`ADDRESS: ${address}`);
console.log(`NUMBER: ${num}`);
console.log(`SATOSHIS: ${satoshis}`);
console.log(`TOTAL SATOSHIS: ${num * satoshis}`);
console.log("\n⚠️ WARNING ⚠️");
console.log("===================================================");
prompt.setPrompt("Are you sure you want to proceed? [y/N]> ");
prompt.prompt();
prompt.on("line", async function(line) {
if (line == "y") {
console.log("🔫 FIRE AT WILL");
const backend = new BitworkBackend();
backend.ready = function() {
console.log("ready");
fire(bundle.PRIVATE, num, satoshis, address, backend).catch(e => {
console.log(`ERROR while firing transactions`);
console.log(e);
});
};
} else {
console.log("\nSkipping... CEASE FIRE\n");
}
prompt.close();
});
});
program.on('command:*', function () {
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
process.exit(1);
});
if (!process.argv.slice(2).length) {
program.outputHelp();
}
program.parse(process.argv);