Skip to content

Commit 24467de

Browse files
committed
Fix outbound payment amount tracking
1 parent 3a0fffe commit 24467de

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
@@ -844,7 +844,7 @@ async fn send_payment(
844844
) {
845845
let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array());
846846
let payment_secret = Some(*invoice.payment_secret());
847-
match (invoice.amount_milli_satoshis(), required_amount_msat) {
847+
let amt_msat = match (invoice.amount_milli_satoshis(), required_amount_msat) {
848848
// pay_for_bolt11_invoice only validates that the amount we pay is >= the invoice's
849849
// required amount, not that its equal (to allow for overpayment). As that is somewhat
850850
// surprising, here we check and reject all disagreements in amount.
@@ -856,8 +856,14 @@ async fn send_payment(
856856
print!("> ");
857857
return;
858858
},
859-
_ => {},
860-
}
859+
(Some(inv_amt), _) => inv_amt,
860+
(_, Some(req_amt)) => req_amt,
861+
(None, None) => {
862+
println!("Need an amount to pay an amountless invoice");
863+
print!("> ");
864+
return;
865+
},
866+
};
861867
let write_future = {
862868
let mut outbound_payments = outbound_payments.lock().unwrap();
863869
outbound_payments.payments.insert(
@@ -866,7 +872,7 @@ async fn send_payment(
866872
preimage: None,
867873
secret: payment_secret,
868874
status: HTLCStatus::Pending,
869-
amt_msat: MillisatAmount(invoice.amount_milli_satoshis()),
875+
amt_msat: MillisatAmount(Some(amt_msat)),
870876
},
871877
);
872878
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, outbound_payments.encode())
@@ -882,7 +888,6 @@ async fn send_payment(
882888
) {
883889
Ok(_) => {
884890
let payee_pubkey = invoice.recover_payee_pub_key();
885-
let amt_msat = invoice.amount_milli_satoshis().unwrap();
886891
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
887892
print!("> ");
888893
},

0 commit comments

Comments
 (0)