Skip to content

Commit aa9f551

Browse files
committed
extend bitcoin-cli: getlninvoice [sats] [--msat N]
1 parent 02ebdd1 commit aa9f551

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

docker/bitcoin-cli

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Commands:
2727
send [amount] [address] [-m N] Send to address and optionally mine N blocks (default: 1)
2828
getInvoice <amount> Get a new BIP21 URI with a bech32 address
2929
LND:
30+
getlninvoice [sats] [--msat N] Create Lightning invoice (supports msat precision)
3031
getinfo Show LND node info (for connectivity debugging)
3132
openchannel <node_id> [amount] Open channel from LND to node (default: 500000 sats)
3233
payinvoice <invoice> [amount] Pay a Lightning invoice via LND
@@ -198,6 +199,80 @@ if [[ "$command" = "getinfo" ]]; then
198199
exit
199200
fi
200201

202+
# Create a Lightning invoice (LND)
203+
if [[ "$command" = "getlninvoice" ]]; then
204+
shift
205+
206+
sats=""
207+
msat=""
208+
memo=""
209+
210+
while [[ $# -gt 0 ]]; do
211+
case "$1" in
212+
--msat)
213+
msat="${2:-}"
214+
shift 2
215+
;;
216+
--sats)
217+
sats="${2:-}"
218+
shift 2
219+
;;
220+
-m|--memo)
221+
memo="${2:-}"
222+
shift 2
223+
;;
224+
-*)
225+
echo "Unknown option $1"
226+
echo "Usage: $CLI_NAME getlninvoice [sats] [--msat N] [--memo TEXT]"
227+
exit 1
228+
;;
229+
*)
230+
# Positional value is treated as sats if numeric.
231+
if [[ "$1" =~ ^[0-9]+$ ]]; then
232+
sats="$1"
233+
shift
234+
else
235+
echo "Invalid amount '$1' (expected integer sats)"
236+
exit 1
237+
fi
238+
;;
239+
esac
240+
done
241+
242+
if [[ -n "$sats" && -n "$msat" ]]; then
243+
echo "Use either sats or --msat, not both."
244+
exit 1
245+
fi
246+
247+
if [[ -n "$msat" ]]; then
248+
echo "→ Creating Lightning invoice (${msat} msat)..."
249+
result=$("${LNCLI_CMD[@]}" addinvoice --amt_msat "$msat" --memo "$memo" 2>&1) || true
250+
elif [[ -n "$sats" ]]; then
251+
echo "→ Creating Lightning invoice (${sats} sats)..."
252+
result=$("${LNCLI_CMD[@]}" addinvoice --amt "$sats" --memo "$memo" 2>&1) || true
253+
else
254+
echo "→ Creating amountless Lightning invoice..."
255+
result=$("${LNCLI_CMD[@]}" addinvoice --memo "$memo" 2>&1) || true
256+
fi
257+
258+
payment_request=$(echo "$result" | jq -r '.payment_request // empty' 2>/dev/null) || payment_request=""
259+
if [ -z "$payment_request" ]; then
260+
echo "${result:-LND command produced no output}"
261+
exit 1
262+
fi
263+
264+
echo ""
265+
echo "$payment_request"
266+
echo ""
267+
268+
if command -v pbcopy &>/dev/null; then
269+
echo "$payment_request" | pbcopy
270+
echo "Invoice copied to clipboard."
271+
fi
272+
273+
exit
274+
fi
275+
201276
# Open channel from LND to a node
202277
if [[ "$command" = "openchannel" ]]; then
203278
shift

0 commit comments

Comments
 (0)