Skip to content

Commit

Permalink
Fix creating orders with LN address (#365)
Browse files Browse the repository at this point in the history
* Fix creating orders with LN address

* Add comment
  • Loading branch information
grunch authored Oct 10, 2024
1 parent 9d4d5f1 commit 9e51caf
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/app/order.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::cli::settings::Settings;
use crate::lightning::invoice::decode_invoice;
use crate::lightning::invoice::is_valid_invoice;
use crate::util::{get_bitcoin_price, publish_order, send_cant_do_msg, send_new_order_msg};

use anyhow::Result;
use mostro_core::message::{Action, Message};
use nostr::nips::nip59::UnwrappedGift;
Expand All @@ -19,16 +18,22 @@ pub async fn order_action(
if let Some(order) = msg.get_inner_message_kind().get_order() {
let mostro_settings = Settings::get_mostro();

// Reject all new invoices in a neworder with amount != 0
// Allows lightning address or invoice
// If user add a bolt11 invoice with a wrong amount the payment will fail later
if let Some(invoice) = msg.get_inner_message_kind().get_payment_request() {
let invoice = decode_invoice(&invoice)?;
if invoice
.amount_milli_satoshis()
.map(|sats| sats / 1000)
.is_some()
{
send_new_order_msg(None, Action::IncorrectInvoiceAmount, None, &event.sender).await;
return Ok(());
// Verify if LN address is valid
match is_valid_invoice(invoice.clone(), None, None).await {
Ok(_) => (),
Err(_) => {
send_new_order_msg(
order.id,
Action::IncorrectInvoiceAmount,
None,
&event.sender,
)
.await;
return Ok(());
}
}
}

Expand Down

0 comments on commit 9e51caf

Please sign in to comment.