Skip to content

Commit f0eb724

Browse files
committed
Use payment_parameters_from_invoice rather than building by hand
1 parent 3bb8258 commit f0eb724

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

src/cli.rs

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use lightning::sign::{EntropySource, KeysManager};
1919
use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
2020
use lightning::util::persist::KVStore;
2121
use lightning::util::ser::{Writeable, Writer};
22+
use lightning_invoice::payment::payment_parameters_from_invoice;
2223
use lightning_invoice::{utils, Bolt11Invoice, Currency};
2324
use lightning_persister::fs_store::FilesystemStore;
2425
use std::env;
@@ -690,8 +691,16 @@ fn send_payment(
690691
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
691692
) {
692693
let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array());
693-
let payment_hash = PaymentHash((*invoice.payment_hash()).to_byte_array());
694694
let payment_secret = Some(*invoice.payment_secret());
695+
let (payment_hash, recipient_onion, route_params) =
696+
match payment_parameters_from_invoice(invoice) {
697+
Ok(res) => res,
698+
Err(e) => {
699+
println!("Failed to parse invoice");
700+
print!("> ");
701+
return;
702+
}
703+
};
695704
outbound_payments.payments.insert(
696705
payment_id,
697706
PaymentInfo {
@@ -703,42 +712,6 @@ fn send_payment(
703712
);
704713
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
705714

706-
let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());
707-
recipient_onion.payment_metadata = invoice.payment_metadata().map(|v| v.clone());
708-
let mut payment_params = match PaymentParameters::from_node_id(
709-
invoice.recover_payee_pub_key(),
710-
invoice.min_final_cltv_expiry_delta() as u32,
711-
)
712-
.with_expiry_time(
713-
invoice.duration_since_epoch().as_secs().saturating_add(invoice.expiry_time().as_secs()),
714-
)
715-
.with_route_hints(invoice.route_hints())
716-
{
717-
Err(e) => {
718-
println!("ERROR: Could not process invoice to prepare payment parameters, {:?}, invoice: {:?}", e, invoice);
719-
return;
720-
}
721-
Ok(p) => p,
722-
};
723-
if let Some(features) = invoice.features() {
724-
payment_params = match payment_params.with_bolt11_features(features.clone()) {
725-
Err(e) => {
726-
println!("ERROR: Could not build BOLT11 payment parameters! {:?}", e);
727-
return;
728-
}
729-
Ok(p) => p,
730-
};
731-
}
732-
let invoice_amount = match invoice.amount_milli_satoshis() {
733-
None => {
734-
println!("ERROR: An invoice with an amount is expected; {:?}", invoice);
735-
return;
736-
}
737-
Some(a) => a,
738-
};
739-
let route_params =
740-
RouteParameters::from_payment_params_and_value(payment_params, invoice_amount);
741-
742715
match channel_manager.send_payment(
743716
payment_hash,
744717
recipient_onion,

0 commit comments

Comments
 (0)