Skip to content

Commit a38b180

Browse files
committed
Fix amount calculation for tracked onchain payments
We recently started tracking onchain payments in the store. It turns out the calculated amount was slightly off as in the outbound case it would include the paid fees. Here, we fix this minor bug.
1 parent 7e6f9c1 commit a38b180

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/wallet/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,21 @@ where
187187
// here to determine the `PaymentKind`, but that's not really satisfactory, so
188188
// we're punting on it until we can come up with a better solution.
189189
let kind = crate::payment::PaymentKind::Onchain { txid, status: confirmation_status };
190+
let fee = locked_wallet.calculate_fee(&wtx.tx_node.tx).unwrap_or(Amount::ZERO);
190191
let (sent, received) = locked_wallet.sent_and_received(&wtx.tx_node.tx);
191192
let (direction, amount_msat) = if sent > received {
192193
let direction = PaymentDirection::Outbound;
193-
let amount_msat = Some(sent.to_sat().saturating_sub(received.to_sat()) * 1000);
194+
let amount_msat = Some(
195+
sent.to_sat().saturating_sub(fee.to_sat()).saturating_sub(received.to_sat())
196+
* 1000,
197+
);
194198
(direction, amount_msat)
195199
} else {
196200
let direction = PaymentDirection::Inbound;
197-
let amount_msat = Some(received.to_sat().saturating_sub(sent.to_sat()) * 1000);
201+
let amount_msat = Some(
202+
received.to_sat().saturating_sub(sent.to_sat().saturating_sub(fee.to_sat()))
203+
* 1000,
204+
);
198205
(direction, amount_msat)
199206
};
200207

0 commit comments

Comments
 (0)