Skip to content

Commit 6af8f29

Browse files
committed
bolt11: better message when you try to 'lightning-cli pay' an onchain addr.
Give a clear error at the beginning if it's not bolt11 payment, rather than falling foul of other checks. This will work at least until some altcoin adapts the 'ln' prefix :) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e2f4359 commit 6af8f29

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

common/bolt11.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,11 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
467467

468468
b11->routes = tal_arr(b11, struct route_info *, 0);
469469

470-
if (strlen(str) < 8)
471-
return decode_fail(b11, fail, "Bad bech32 string");
470+
if (!strstarts(str, "ln"))
471+
return decode_fail(b11, fail, "Invoices must start with ln");
472472

473-
hrp = tal_arr(tmpctx, char, strlen(str) - 6);
474-
data = tal_arr(tmpctx, u5, strlen(str) - 8);
473+
hrp = tal_arr(tmpctx, char, strlen(str));
474+
data = tal_arr(tmpctx, u5, strlen(str));
475475

476476
if (!bech32_decode(hrp, data, &data_len, str, (size_t)-1))
477477
return decode_fail(b11, fail, "Bad bech32 string");

0 commit comments

Comments
 (0)