-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightning-address-pay.js
More file actions
47 lines (43 loc) · 1.74 KB
/
lightning-address-pay.js
File metadata and controls
47 lines (43 loc) · 1.74 KB
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
import { validateLightningAddress, LIGHTNING_ADDRESS_INVALID, getRestOptionsGot, getLightningAddressUri, getGot, logQrCode } from './util.js';
import { question } from 'readline-sync';
const main = async function () {
const lightningAddress = process.argv[2];
if (!validateLightningAddress(lightningAddress)) {
console.error(LIGHTNING_ADDRESS_INVALID);
process.exit();
}
let options = getRestOptionsGot(getLightningAddressUri(lightningAddress));
let response = await getGot(options);
let body = response.body;
if ('payRequest' == body.tag) {
console.log('Min', body.minSendable);
console.log('Max', body.maxSendable);
const amount = question('Amount [msat] ');
if (amount >= body.minSendable && amount <= body.maxSendable) {
console.log('Max Comment', body.commentAllowed);
const comment = question('Comment ');
if (comment.length >= 0 && comment.length <= body.commentAllowed) {
options = getRestOptionsGot(body.callback + '?amount=' + amount + '&comment=' + comment);
response = await getGot(options);
if (200 === response.statusCode) {
body = response.body;
if ('ERROR' === body.status) {
console.error(body);
} else {
logQrCode(body.pr);
}
} else {
console.error('Error', response);
}
} else {
console.error('Comment invalid!');
}
} else {
console.error('Amount invalid!');
}
} else {
console.error('Pay not possible!');
}
process.exit();
}
main();