Skip to content

Commit 1be2068

Browse files
committed
Fix outbound payment amount tracking
1 parent e923f41 commit 1be2068

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/cli.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ async fn send_payment(
845845
) {
846846
let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array());
847847
let payment_secret = Some(*invoice.payment_secret());
848-
match (invoice.amount_milli_satoshis(), required_amount_msat) {
848+
let amt_msat = match (invoice.amount_milli_satoshis(), required_amount_msat) {
849849
// pay_for_bolt11_invoice only validates that the amount we pay is >= the invoice's
850850
// required amount, not that its equal (to allow for overpayment). As that is somewhat
851851
// surprising, here we check and reject all disagreements in amount.
@@ -857,8 +857,14 @@ async fn send_payment(
857857
print!("> ");
858858
return;
859859
},
860-
_ => {},
861-
}
860+
(Some(inv_amt), _) => inv_amt,
861+
(_, Some(req_amt)) => req_amt,
862+
(None, None) => {
863+
println!("Need an amount to pay an amountless invoice");
864+
print!("> ");
865+
return;
866+
},
867+
};
862868
let write_future = {
863869
let mut outbound_payments = outbound_payments.lock().unwrap();
864870
outbound_payments.payments.insert(
@@ -867,7 +873,7 @@ async fn send_payment(
867873
preimage: None,
868874
secret: payment_secret,
869875
status: HTLCStatus::Pending,
870-
amt_msat: MillisatAmount(invoice.amount_milli_satoshis()),
876+
amt_msat: MillisatAmount(Some(amt_msat)),
871877
},
872878
);
873879
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, outbound_payments.encode())
@@ -883,7 +889,6 @@ async fn send_payment(
883889
) {
884890
Ok(_) => {
885891
let payee_pubkey = invoice.recover_payee_pub_key();
886-
let amt_msat = invoice.amount_milli_satoshis().unwrap();
887892
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
888893
print!("> ");
889894
},

0 commit comments

Comments
 (0)