From 56516757ad8874d8121dba468946546bb8fd7d4e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 29 May 2025 05:08:34 +0100 Subject: [PATCH] Add code comment to amount calculation Its not immediately obvious that x - y cannot overflow. Add a code comment to explain it. --- bitcoin/src/blockdata/transaction.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index fc88001b1..6182308f5 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -784,6 +784,8 @@ pub fn effective_value( let weight = input_weight_prediction.total_weight(); let fee = fee_rate.to_fee(weight); + // Cannot overflow because after conversion to signed Amount::MIN - Amount::MAX + // still fits in SignedAmount::MAX (0 - MAX = -MAX). (value.to_signed() - fee.to_signed()).expect("cannot overflow") }