Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 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;
Comment thread
benthecarman marked this conversation as resolved.

pub async fn lnurl_callback(
state: &State,
Expand Down Expand Up @@ -86,6 +87,12 @@ pub async fn lnurl_callback(
return Err(anyhow::anyhow!("Invalid nostr event"));
}

if let Some(comment) = params.comment.as_ref() {
if comment.len() > MAX_COMMENT_LEN as usize {
return Err(anyhow::anyhow!("Comment too long"))
}
}

let federation_id = FederationId::from_str(&user.federation_id)
.map_err(|e| anyhow::anyhow!("Internal error: Invalid federation_id: {e}"))?;

Expand Down Expand Up @@ -134,6 +141,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