Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Create invoice from lightning node if amt is high
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Jan 30, 2024
1 parent 323446f commit 7b86c0f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ use crate::utils::parse_profile_metadata;
use mockall::{automock, predicate::*};

const DEFAULT_PAYMENT_TIMEOUT: u64 = 30;
const MAX_FEDERATION_INVOICE_AMT: u64 = 200_000;

#[cfg_attr(test, automock)]
pub trait InvoiceHandler {
Expand Down Expand Up @@ -1126,18 +1127,16 @@ impl<S: MutinyStorage> MutinyWallet<S> {
amount: Option<u64>,
labels: Vec<String>,
) -> Result<MutinyInvoice, MutinyError> {
let federation_ids = self.list_federation_ids().await?;
let amt = amount.map_or(Err(MutinyError::InvalidArgumentsError), Ok)?;

// Attempt to create federation invoice
if !federation_ids.is_empty() {
// Attempt to create federation invoice if available and below max amount
let federation_ids = self.list_federation_ids().await?;
if !federation_ids.is_empty() && amt <= MAX_FEDERATION_INVOICE_AMT {
let federation_id = &federation_ids[0];
let fedimint_client = self.federations.read().await.get(federation_id).cloned();

if let Some(client) = fedimint_client {
if let Ok(inv) = client
.get_invoice(amount.unwrap_or_default(), labels.clone())
.await
{
if let Ok(inv) = client.get_invoice(amt, labels.clone()).await {
self.storage
.set_invoice_labels(inv.bolt11.clone().expect("just created"), labels)?;
return Ok(inv);
Expand All @@ -1146,10 +1145,9 @@ impl<S: MutinyStorage> MutinyWallet<S> {
}

// Fallback to node_manager invoice creation if no federation invoice created
let inv = self.node_manager.create_invoice(amount).await?;
let inv = self.node_manager.create_invoice(Some(amt)).await?;
self.storage
.set_invoice_labels(inv.bolt11.clone().expect("just created"), labels)?;

Ok(inv)
}

Expand Down

0 comments on commit 7b86c0f

Please sign in to comment.