commit f351632440e6cf0ffd4bc605138b25b97bda31c7
parent 69ccc214a6b071c5ede6eac1c22584771fcfe052
Author: William Casarin <jb55@jb55.com>
Date: Mon, 19 Dec 2022 22:24:39 -0800
bolt11: parse lightning prefixes on lightning invoice
Changelog-Fixed: Parse lightning prefixes on lightning invoice
Diffstat:
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/damus-c/damus.c b/damus-c/damus.c
@@ -213,6 +213,9 @@ static int parse_invoice(struct cursor *cur, struct block *block) {
struct bolt11 *bolt11;
start = cur->p;
+ // optional
+ parse_str(cur, "lightning:");
+
if (!parse_str(cur, "lnbc"))
return 0;
diff --git a/damusTests/InvoiceTests.swift b/damusTests/InvoiceTests.swift
@@ -34,6 +34,24 @@ final class InvoiceTests: XCTestCase {
XCTAssertEqual(invoice.string, invstr)
}
+ func testParseInvoiceWithPrefix() throws {
+ let invstr = "lightning:lnbc100n1p357sl0sp5t9n56wdztun39lgdqlr30xqwksg3k69q4q2rkr52aplujw0esn0qpp5mrqgljk62z20q4nvgr6lzcyn6fhylzccwdvu4k77apg3zmrkujjqdpzw35xjueqd9ejqcfqv3jhxcmjd9c8g6t0dcxqyjw5qcqpjrzjqt56h4gvp5yx36u2uzqa6qwcsk3e2duunfxppzj9vhypc3wfe2wswz607uqq3xqqqsqqqqqqqqqqqlqqyg9qyysgqagx5h20aeulj3gdwx3kxs8u9f4mcakdkwuakasamm9562ffyr9en8yg20lg0ygnr9zpwp68524kmda0t5xp2wytex35pu8hapyjajxqpsql29r"
+ let parsed = parse_mentions(content: invstr, tags: [])
+
+ XCTAssertNotNil(parsed)
+ XCTAssertEqual(parsed.count, 1)
+ XCTAssertNotNil(parsed[0].is_invoice)
+ }
+
+ func testParseInvoiceWithPrefixCapitalized() throws {
+ let invstr = "LIGHTNING:LNBC100N1P357SL0SP5T9N56WDZTUN39LGDQLR30XQWKSG3K69Q4Q2RKR52APLUJW0ESN0QPP5MRQGLJK62Z20Q4NVGR6LZCYN6FHYLZCCWDVU4K77APG3ZMRKUJJQDPZW35XJUEQD9EJQCFQV3JHXCMJD9C8G6T0DCXQYJW5QCQPJRZJQT56H4GVP5YX36U2UZQA6QWCSK3E2DUUNFXPPZJ9VHYPC3WFE2WSWZ607UQQ3XQQQSQQQQQQQQQQQLQQYG9QYYSGQAGX5H20AEULJ3GDWX3KXS8U9F4MCAKDKWUAKASAMM9562FFYR9EN8YG20LG0YGNR9ZPWP68524KMDA0T5XP2WYTEX35PU8HAPYJAJXQPSQL29R"
+ let parsed = parse_mentions(content: invstr, tags: [])
+
+ XCTAssertNotNil(parsed)
+ XCTAssertEqual(parsed.count, 1)
+ XCTAssertNotNil(parsed[0].is_invoice)
+ }
+
func testParseInvoice() throws {
let invstr = "lnbc100n1p357sl0sp5t9n56wdztun39lgdqlr30xqwksg3k69q4q2rkr52aplujw0esn0qpp5mrqgljk62z20q4nvgr6lzcyn6fhylzccwdvu4k77apg3zmrkujjqdpzw35xjueqd9ejqcfqv3jhxcmjd9c8g6t0dcxqyjw5qcqpjrzjqt56h4gvp5yx36u2uzqa6qwcsk3e2duunfxppzj9vhypc3wfe2wswz607uqq3xqqqsqqqqqqqqqqqlqqyg9qyysgqagx5h20aeulj3gdwx3kxs8u9f4mcakdkwuakasamm9562ffyr9en8yg20lg0ygnr9zpwp68524kmda0t5xp2wytex35pu8hapyjajxqpsql29r"
let parsed = parse_mentions(content: invstr, tags: [])