diff --git a/modules/fedimint-lnv2-client/src/cli.rs b/modules/fedimint-lnv2-client/src/cli.rs index 19f7678b123..24d658365c5 100644 --- a/modules/fedimint-lnv2-client/src/cli.rs +++ b/modules/fedimint-lnv2-client/src/cli.rs @@ -9,7 +9,7 @@ use serde::Serialize; use serde_json::Value; use crate::api::LnFederationApi; -use crate::LightningClientModule; +use crate::{Bolt11InvoiceDescription, LightningClientModule}; #[derive(Parser, Serialize)] enum Opts { @@ -62,9 +62,21 @@ pub(crate) async fn handle_cli_command( let opts = Opts::parse_from(iter::once(&ffi::OsString::from("lnv2")).chain(args.iter())); let value = match opts { - Opts::Send { gateway, invoice } => json(lightning.send(invoice, gateway).await?), + Opts::Send { gateway, invoice } => { + json(lightning.send(invoice, gateway, Value::Null).await?) + } Opts::AwaitSend { operation_id } => json(lightning.await_send(operation_id).await?), - Opts::Receive { gateway, amount } => json(lightning.receive(amount, gateway).await?), + Opts::Receive { amount, gateway } => json( + lightning + .receive( + amount, + 3600, + Bolt11InvoiceDescription::Direct(String::new()), + gateway, + Value::Null, + ) + .await?, + ), Opts::AwaitReceive { operation_id } => json(lightning.await_receive(operation_id).await?), Opts::Gateway(gateway_opts) => match gateway_opts { GatewayOpts::Select { invoice } => json(lightning.select_gateway(invoice).await?.0), diff --git a/modules/fedimint-lnv2-client/src/lib.rs b/modules/fedimint-lnv2-client/src/lib.rs index e2c367fa9d6..9cbacf7ce08 100644 --- a/modules/fedimint-lnv2-client/src/lib.rs +++ b/modules/fedimint-lnv2-client/src/lib.rs @@ -115,9 +115,6 @@ pub const EXPIRATION_DELTA_LIMIT_DEFAULT: u64 = 1008; /// A two hour buffer in case either the client or gateway go offline pub const CONTRACT_CONFIRMATION_BUFFER: u64 = 12; -/// Default expiration time for lightning invoices -pub const INVOICE_EXPIRATION_SECONDS_DEFAULT: u32 = 24 * 60 * 60; - #[cfg_attr(doc, aquamarine::aquamarine)] /// The high-level state of sending a payment over lightning. /// @@ -520,25 +517,6 @@ impl LightningClientModule { &self, invoice: Bolt11Invoice, gateway: Option, - ) -> Result { - self.send_custom( - invoice, - PaymentFee::SEND_FEE_LIMIT_DEFAULT, - EXPIRATION_DELTA_LIMIT_DEFAULT, - gateway, - Value::Null, - ) - .await - } - - /// Pay an invoice. For testing you can optionally specify a gateway to - /// route with, otherwise a gateway will be selected automatically. - pub async fn send_custom( - &self, - invoice: Bolt11Invoice, - payment_fee_limit: PaymentFee, - expiration_delta_limit: u64, - gateway: Option, custom_meta: Value, ) -> Result { let amount = invoice @@ -580,11 +558,11 @@ impl LightningClientModule { let (send_fee, expiration_delta) = routing_info.send_parameters(&invoice); - if !send_fee.le(&payment_fee_limit) { + if !send_fee.le(&PaymentFee::SEND_FEE_LIMIT_DEFAULT) { return Err(SendPaymentError::PaymentFeeExceedsLimit(send_fee)); } - if expiration_delta_limit < expiration_delta { + if EXPIRATION_DELTA_LIMIT_DEFAULT < expiration_delta { return Err(SendPaymentError::ExpirationDeltaExceedsLimit( expiration_delta, )); @@ -768,27 +746,11 @@ impl LightningClientModule { /// Request an invoice. For testing you can optionally specify a gateway to /// generate the invoice, otherwise a gateway will be selected /// automatically. - pub async fn receive(&self, amount: Amount, gateway: Option) -> ReceiveResult { - self.receive_custom( - amount, - INVOICE_EXPIRATION_SECONDS_DEFAULT, - Bolt11InvoiceDescription::Direct(String::new()), - PaymentFee::RECEIVE_FEE_LIMIT_DEFAULT, - gateway, - Value::Null, - ) - .await - } - - /// Request an invoice. For testing you can optionally specify a gateway to - /// generate the invoice, otherwise a gateway will be selected - /// automatically. - pub async fn receive_custom( + pub async fn receive( &self, amount: Amount, expiry_secs: u32, description: Bolt11InvoiceDescription, - payment_fee_limit: PaymentFee, gateway: Option, custom_meta: Value, ) -> Result<(Bolt11Invoice, OperationId), ReceiveError> { @@ -798,7 +760,6 @@ impl LightningClientModule { amount, expiry_secs, description, - payment_fee_limit, gateway, ) .await?; @@ -820,7 +781,6 @@ impl LightningClientModule { amount: Amount, expiry_secs: u32, description: Bolt11InvoiceDescription, - payment_fee_limit: PaymentFee, gateway: Option, ) -> Result<(SafeUrl, IncomingContract, Bolt11Invoice), ReceiveError> { let (ephemeral_tweak, ephemeral_pk) = generate_ephemeral_tweak(recipient_static_pk); @@ -847,7 +807,10 @@ impl LightningClientModule { .map_err(ReceiveError::FailedToSelectGateway)?, }; - if !routing_info.receive_fee.le(&payment_fee_limit) { + if !routing_info + .receive_fee + .le(&PaymentFee::RECEIVE_FEE_LIMIT_DEFAULT) + { return Err(ReceiveError::PaymentFeeExceedsLimit( routing_info.receive_fee, )); diff --git a/modules/fedimint-lnv2-tests/tests/tests.rs b/modules/fedimint-lnv2-tests/tests/tests.rs index 1aded8854a4..85e08a07f92 100644 --- a/modules/fedimint-lnv2-tests/tests/tests.rs +++ b/modules/fedimint-lnv2-tests/tests/tests.rs @@ -11,8 +11,8 @@ use fedimint_dummy_common::config::DummyGenParams; use fedimint_dummy_server::DummyInit; use fedimint_lnv2_client::{ Bolt11InvoiceDescription, LightningClientInit, LightningClientModule, - LightningClientStateMachines, LightningOperationMeta, PaymentFee, ReceiveState, - SendPaymentError, SendState, CONTRACT_CONFIRMATION_BUFFER, EXPIRATION_DELTA_LIMIT_DEFAULT, + LightningClientStateMachines, LightningOperationMeta, ReceiveState, SendPaymentError, + SendState, CONTRACT_CONFIRMATION_BUFFER, EXPIRATION_DELTA_LIMIT_DEFAULT, }; use fedimint_lnv2_common::config::LightningGenParams; use fedimint_lnv2_common::{LightningInput, LightningInputV0, OutgoingWitness}; @@ -55,13 +55,13 @@ async fn can_pay_external_invoice_exactly_once() -> anyhow::Result<()> { let operation_id = client .get_first_module::()? - .send(invoice.clone(), Some(gateway_api.clone())) + .send(invoice.clone(), Some(gateway_api.clone()), Value::Null) .await?; assert_eq!( client .get_first_module::()? - .send(invoice.clone(), Some(gateway_api.clone())) + .send(invoice.clone(), Some(gateway_api.clone()), Value::Null) .await, Err(SendPaymentError::PendingPreviousPayment(operation_id)), ); @@ -79,7 +79,7 @@ async fn can_pay_external_invoice_exactly_once() -> anyhow::Result<()> { assert_eq!( client .get_first_module::()? - .send(invoice, Some(gateway_api)) + .send(invoice, Some(gateway_api), Value::Null) .await, Err(SendPaymentError::SuccessfulPreviousPayment(operation_id)), ); @@ -103,7 +103,11 @@ async fn refund_failed_payment() -> anyhow::Result<()> { let op = client .get_first_module::()? - .send(mock::unpayable_invoice(), Some(mock::gateway())) + .send( + mock::unpayable_invoice(), + Some(mock::gateway()), + Value::Null, + ) .await?; let mut sub = client @@ -136,7 +140,7 @@ async fn unilateral_refund_of_outgoing_contracts() -> anyhow::Result<()> { let op = client .get_first_module::()? - .send(mock::crash_invoice(), Some(mock::gateway())) + .send(mock::crash_invoice(), Some(mock::gateway()), Value::Null) .await?; let mut sub = client @@ -175,7 +179,7 @@ async fn claiming_outgoing_contract_triggers_success() -> anyhow::Result<()> { let op = client .get_first_module::()? - .send(mock::crash_invoice(), Some(mock::gateway())) + .send(mock::crash_invoice(), Some(mock::gateway()), Value::Null) .await?; let mut sub = client @@ -236,11 +240,10 @@ async fn receive_operation_expires() -> anyhow::Result<()> { let op = client .get_first_module::()? - .receive_custom( + .receive( Amount::from_sats(1000), 5, // receive operation expires in 5 seconds Bolt11InvoiceDescription::Direct(String::new()), - PaymentFee::RECEIVE_FEE_LIMIT_DEFAULT, Some(mock::gateway()), Value::Null, ) @@ -268,7 +271,11 @@ async fn rejects_wrong_network_invoice() -> anyhow::Result<()> { assert_eq!( client .get_first_module::()? - .send(mock::signet_bolt_11_invoice(), Some(mock::gateway())) + .send( + mock::signet_bolt_11_invoice(), + Some(mock::gateway()), + Value::Null + ) .await .expect_err("send did not fail due to incorrect Currency"), SendPaymentError::WrongCurrency {