Skip to content

Commit 7ae0d3e

Browse files
committed
invoice amt fixes
1 parent b6a4c4b commit 7ae0d3e

File tree

3 files changed

+41
-81
lines changed

3 files changed

+41
-81
lines changed

Cargo.toml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,6 @@ lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightnin
1919
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "f9b8d630c579d76ec85e283bdd0fd0c9408a7474" }
2020
lightning-dns-resolver = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "f9b8d630c579d76ec85e283bdd0fd0c9408a7474" }
2121

22-
23-
24-
# lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
25-
# lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
26-
# lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
27-
# lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
28-
# lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["futures"] }
29-
# lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
30-
# lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["rpc-client", "tokio"] }
31-
# lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
32-
# lightning-dns-resolver = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
33-
34-
# lightning = { version = "0.1.0", features = ["dnssec"] }
35-
# lightning-block-sync = { version = "0.1.0", features = [ "rpc-client", "tokio" ] }
36-
# lightning-dns-resolver = { version = "0.2.0" }
37-
# lightning-invoice = { version = "0.33.0" }
38-
# lightning-net-tokio = { version = "0.1.0" }
39-
# lightning-persister = { version = "0.1.0" }
40-
# lightning-background-processor = { version = "0.1.0", features = [ "futures" ] }
41-
# lightning-rapid-gossip-sync = { version = "0.1.0" }
42-
4322
base64 = "0.13.0"
4423
bitcoin = "0.32"
4524
bitcoin-bech32 = "0.12"

src/cli.rs

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use bitcoin::hashes::Hash;
99
use bitcoin::network::Network;
1010
use bitcoin::secp256k1::PublicKey;
1111
use lightning::chain::channelmonitor::Balance;
12-
// use lightning::ln::bolt11_payment::payment_parameters_from_invoice;
13-
// use lightning::ln::bolt11_payment::payment_parameters_from_variable_amount_invoice;
1412
use lightning::ln::channelmanager::{
1513
Bolt11InvoiceParameters, PaymentId, RecipientOnionFields, Retry,
1614
};
@@ -829,36 +827,27 @@ fn send_payment(
829827
) {
830828
let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array());
831829
let payment_secret = Some(*invoice.payment_secret());
832-
// let zero_amt_invoice =
833-
// invoice.amount_milli_satoshis().is_none() || invoice.amount_milli_satoshis() == Some(0);
834-
// let pay_params_opt = if zero_amt_invoice {
835-
// if let Some(amt_msat) = required_amount_msat {
836-
// payment_parameters_from_variable_amount_invoice(invoice, amt_msat)
837-
// } else {
838-
// println!("Need an amount for the given 0-value invoice");
839-
// print!("> ");
840-
// return;
841-
// }
842-
// } else {
843-
// if required_amount_msat.is_some() && invoice.amount_milli_satoshis() != required_amount_msat
844-
// {
845-
// println!(
846-
// "Amount didn't match invoice value of {}msat",
847-
// invoice.amount_milli_satoshis().unwrap_or(0)
848-
// );
849-
// print!("> ");
850-
// return;
851-
// }
852-
// payment_parameters_from_invoice(invoice)
853-
// };
854-
// let (payment_hash, recipient_onion, route_params) = match pay_params_opt {
855-
// Ok(res) => res,
856-
// Err(e) => {
857-
// println!("Failed to parse invoice: {:?}", e);
858-
// print!("> ");
859-
// return;
860-
// },
861-
// };
830+
let zero_amt_invoice =
831+
invoice.amount_milli_satoshis().is_none() || invoice.amount_milli_satoshis() == Some(0);
832+
let amount_msats = if zero_amt_invoice {
833+
if required_amount_msat.is_none() {
834+
println!("Need an amount for the given 0-value invoice");
835+
print!("> ");
836+
return;
837+
}
838+
required_amount_msat
839+
} else {
840+
if required_amount_msat.is_some() && invoice.amount_milli_satoshis() != required_amount_msat
841+
{
842+
println!(
843+
"Amount didn't match invoice value of {}msat",
844+
invoice.amount_milli_satoshis().unwrap_or(0)
845+
);
846+
print!("> ");
847+
return;
848+
}
849+
None
850+
};
862851
outbound_payments.payments.insert(
863852
payment_id,
864853
PaymentInfo {
@@ -870,34 +859,27 @@ fn send_payment(
870859
);
871860
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
872861

873-
// TODO: fix this so the amounts match
874-
let amount_msats = invoice.amount_milli_satoshis().or(required_amount_msat);
875862
let route_params_config = RouteParametersConfig::default();
876-
channel_manager.pay_for_bolt11_invoice(
877-
invoice, payment_id, amount_msats, route_params_config,
878-
Retry::Timeout(Duration::from_secs(10))
879-
).unwrap();
880-
881-
// match channel_manager.send_payment(
882-
// payment_hash,
883-
// recipient_onion,
884-
// payment_id,
885-
// route_params,
886-
// Retry::Timeout(Duration::from_secs(10)),
887-
// ) {
888-
// Ok(_) => {
889-
// let payee_pubkey = invoice.recover_payee_pub_key();
890-
// let amt_msat = invoice.amount_milli_satoshis().unwrap();
891-
// println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
892-
// print!("> ");
893-
// },
894-
// Err(e) => {
895-
// println!("ERROR: failed to send payment: {:?}", e);
896-
// print!("> ");
897-
// outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
898-
// fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
899-
// },
900-
// };
863+
match channel_manager.pay_for_bolt11_invoice(
864+
invoice,
865+
payment_id,
866+
amount_msats,
867+
route_params_config,
868+
Retry::Timeout(Duration::from_secs(10)),
869+
) {
870+
Ok(_) => {
871+
let payee_pubkey = invoice.recover_payee_pub_key();
872+
let amt_msat = invoice.amount_milli_satoshis().unwrap();
873+
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
874+
print!("> ");
875+
},
876+
Err(e) => {
877+
println!("ERROR: failed to send payment: {:?}", e);
878+
print!("> ");
879+
outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
880+
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
881+
},
882+
};
901883
}
902884

903885
fn keysend<E: EntropySource>(

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ async fn start_ldk() {
831831
// Step 14: Give ChannelMonitors to ChainMonitor
832832
for item in chain_listener_channel_monitors.drain(..) {
833833
let channel_monitor = item.1 .0;
834-
// let funding_outpoint = item.2;
835834
let channel_id = channel_monitor.channel_id();
836835
assert_eq!(
837836
chain_monitor.watch_channel(channel_id, channel_monitor),

0 commit comments

Comments
 (0)