Skip to content

Commit 75f2238

Browse files
committed
f LDK: Account for new ChannelManager::create_bolt11_invoice
1 parent 0abcf92 commit 75f2238

File tree

2 files changed

+15
-46
lines changed

2 files changed

+15
-46
lines changed

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ impl Node {
824824
Arc::clone(&self.runtime),
825825
Arc::clone(&self.channel_manager),
826826
Arc::clone(&self.connection_manager),
827-
Arc::clone(&self.keys_manager),
828827
self.liquidity_source.clone(),
829828
Arc::clone(&self.payment_store),
830829
Arc::clone(&self.peer_store),
@@ -842,7 +841,6 @@ impl Node {
842841
Arc::clone(&self.runtime),
843842
Arc::clone(&self.channel_manager),
844843
Arc::clone(&self.connection_manager),
845-
Arc::clone(&self.keys_manager),
846844
self.liquidity_source.clone(),
847845
Arc::clone(&self.payment_store),
848846
Arc::clone(&self.peer_store),

src/payment/bolt11.rs

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ use crate::payment::store::{
2020
};
2121
use crate::payment::SendingParameters;
2222
use crate::peer_store::{PeerInfo, PeerStore};
23-
use crate::types::{ChannelManager, KeysManager};
23+
use crate::types::ChannelManager;
2424

2525
use lightning::ln::bolt11_payment;
26-
use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry, RetryableSendFailure};
27-
use lightning::ln::invoice_utils::{
28-
create_invoice_from_channelmanager_and_duration_since_epoch,
29-
create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash,
26+
use lightning::ln::channelmanager::{
27+
Bolt11InvoiceParameters, PaymentId, RecipientOnionFields, Retry, RetryableSendFailure,
3028
};
3129
use lightning::routing::router::{PaymentParameters, RouteParameters};
3230

3331
use lightning_types::payment::{PaymentHash, PaymentPreimage};
3432

35-
use lightning_invoice::{Bolt11Invoice, Currency};
33+
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};
3634

3735
use bitcoin::hashes::sha256::Hash as Sha256;
3836
use bitcoin::hashes::Hash;
3937

4038
use std::sync::{Arc, RwLock};
41-
use std::time::SystemTime;
4239

4340
/// A payment handler allowing to create and pay [BOLT 11] invoices.
4441
///
@@ -50,7 +47,6 @@ pub struct Bolt11Payment {
5047
runtime: Arc<RwLock<Option<Arc<tokio::runtime::Runtime>>>>,
5148
channel_manager: Arc<ChannelManager>,
5249
connection_manager: Arc<ConnectionManager<Arc<FilesystemLogger>>>,
53-
keys_manager: Arc<KeysManager>,
5450
liquidity_source: Option<Arc<LiquiditySource<Arc<FilesystemLogger>>>>,
5551
payment_store: Arc<PaymentStore<Arc<FilesystemLogger>>>,
5652
peer_store: Arc<PeerStore<Arc<FilesystemLogger>>>,
@@ -63,7 +59,6 @@ impl Bolt11Payment {
6359
runtime: Arc<RwLock<Option<Arc<tokio::runtime::Runtime>>>>,
6460
channel_manager: Arc<ChannelManager>,
6561
connection_manager: Arc<ConnectionManager<Arc<FilesystemLogger>>>,
66-
keys_manager: Arc<KeysManager>,
6762
liquidity_source: Option<Arc<LiquiditySource<Arc<FilesystemLogger>>>>,
6863
payment_store: Arc<PaymentStore<Arc<FilesystemLogger>>>,
6964
peer_store: Arc<PeerStore<Arc<FilesystemLogger>>>, config: Arc<Config>,
@@ -73,7 +68,6 @@ impl Bolt11Payment {
7368
runtime,
7469
channel_manager,
7570
connection_manager,
76-
keys_manager,
7771
liquidity_source,
7872
payment_store,
7973
peer_store,
@@ -469,41 +463,18 @@ impl Bolt11Payment {
469463
&self, amount_msat: Option<u64>, description: &str, expiry_secs: u32,
470464
manual_claim_payment_hash: Option<PaymentHash>,
471465
) -> Result<Bolt11Invoice, Error> {
472-
let currency = Currency::from(self.config.network);
473-
let keys_manager = Arc::clone(&self.keys_manager);
474-
let duration = SystemTime::now()
475-
.duration_since(SystemTime::UNIX_EPOCH)
476-
.expect("for the foreseeable future this shouldn't happen");
466+
let invoice_description = Bolt11InvoiceDescription::Direct(
467+
Description::new(description.to_string()).map_err(|_| Error::InvoiceCreationFailed)?,
468+
);
477469

478470
let invoice = {
479-
let invoice_res = if let Some(payment_hash) = manual_claim_payment_hash {
480-
create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
481-
&self.channel_manager,
482-
keys_manager,
483-
Arc::clone(&self.logger),
484-
currency,
485-
amount_msat,
486-
description.to_string(),
487-
duration,
488-
expiry_secs,
489-
payment_hash,
490-
None,
491-
)
492-
} else {
493-
create_invoice_from_channelmanager_and_duration_since_epoch(
494-
&self.channel_manager,
495-
keys_manager,
496-
Arc::clone(&self.logger),
497-
currency,
498-
amount_msat,
499-
description.to_string(),
500-
duration,
501-
expiry_secs,
502-
None,
503-
)
504-
};
505-
506-
match invoice_res {
471+
let mut invoice_params = Bolt11InvoiceParameters::default();
472+
invoice_params.amount_msats = amount_msat;
473+
invoice_params.description = invoice_description;
474+
invoice_params.invoice_expiry_delta_secs = Some(expiry_secs);
475+
invoice_params.payment_hash = manual_claim_payment_hash;
476+
477+
match self.channel_manager.create_bolt11_invoice(invoice_params) {
507478
Ok(inv) => {
508479
log_info!(self.logger, "Invoice created: {}", inv);
509480
inv
@@ -749,7 +720,7 @@ impl Bolt11Payment {
749720
Error::InvalidInvoice
750721
})?
751722
} else {
752-
bolt11_payment::payment_parameters_from_zero_amount_invoice(&invoice, amount_msat).map_err(|_| {
723+
bolt11_payment::payment_parameters_from_variable_amount_invoice(&invoice, amount_msat).map_err(|_| {
753724
log_error!(self.logger, "Failed to send probes due to the given invoice unexpectedly being not \"zero-amount\".");
754725
Error::InvalidInvoice
755726
})?

0 commit comments

Comments
 (0)