Skip to content

Commit

Permalink
add support for lnurl comments
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed May 2, 2024
1 parent c88748f commit 0db70b1
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target/
.env
.fedimint-test-dir
.test
.idea

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down
1 change: 1 addition & 0 deletions migrations/2024-05-02-213721_add_lnurlp_comments/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "invoice" DROP COLUMN "lnurlp_comment";
1 change: 1 addition & 0 deletions migrations/2024-05-02-213721_add_lnurlp_comments/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "invoice" ADD COLUMN "lnurlp_comment" VARCHAR(100);
1 change: 1 addition & 0 deletions src/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ async fn notify_user(
"bolt11": invoice.bolt11,
"preimage": invoice.preimage,
"zap_request": zap.as_ref().map(|z| z.request.clone()),
"lnurlp_comment": invoice.lnurlp_comment
})
.to_string(),
None,
Expand Down
4 changes: 3 additions & 1 deletion src/lnurlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub async fn well_known_lnurlp(
max_sendable: Amount { msats: MAX_AMOUNT },
min_sendable: Amount { msats: MIN_AMOUNT },
metadata: calc_metadata(&name, &state.domain_no_http()),
comment_allowed: None,
comment_allowed: Some(MAX_COMMENT_LEN),
tag: LnurlType::PayRequest,
status: LnurlStatus::Ok,
nostr_pubkey: Some(state.nostr_sk.public_key()),
Expand All @@ -49,6 +49,7 @@ pub async fn well_known_lnurlp(

const MAX_AMOUNT: u64 = 100_000_000 * 1_000; // 1 BTC
const MIN_AMOUNT: u64 = 5_000; // 5 sats
const MAX_COMMENT_LEN: i32 = 100;

pub async fn lnurl_callback(
state: &State,
Expand Down Expand Up @@ -134,6 +135,7 @@ pub async fn lnurl_callback(
bolt11: pr.to_string(),
amount: amount_msats as i64,
state: InvoiceState::Pending as i32,
lnurlp_comment: params.comment
};

let created_invoice = state.db.insert_new_invoice(new_invoice)?;
Expand Down
2 changes: 2 additions & 0 deletions src/models/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Invoice {
pub bolt11: String,
pub amount: i64,
pub state: i32,
pub lnurlp_comment: Option<String>
}

impl Invoice {
Expand Down Expand Up @@ -74,6 +75,7 @@ pub struct NewInvoice {
pub bolt11: String,
pub amount: i64,
pub state: i32,
pub lnurlp_comment: Option<String>
}

impl NewInvoice {
Expand Down
2 changes: 2 additions & 0 deletions src/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ diesel::table! {
bolt11 -> Varchar,
amount -> Int8,
state -> Int4,
#[max_length = 100]
lnurlp_comment -> Nullable<Varchar>,
}
}

Expand Down

0 comments on commit 0db70b1

Please sign in to comment.