]> Untitled Git - bdk/commitdiff
fix(chain)!: remove Debug usage and implement Display for CalculateFeeError
authorDmenec <Domenec.Madrid@uab.cat>
Thu, 11 Dec 2025 11:01:34 +0000 (12:01 +0100)
committerDmenec <Domenec.Madrid@uab.cat>
Thu, 5 Feb 2026 12:30:18 +0000 (13:30 +0100)
Limited to 3 max shown items and added a suffix when there are additional entries.

crates/chain/src/tx_graph.rs

index 97d4ecc024e798cabaa57193a3959670f5a99b25..701de335d6005c9c8d51503678ae5c417e6e137c 100644 (file)
@@ -256,15 +256,33 @@ pub enum CalculateFeeError {
 impl fmt::Display for CalculateFeeError {
     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
         match self {
-            CalculateFeeError::MissingTxOut(outpoints) => write!(
-                f,
-                "missing `TxOut` for one or more of the inputs of the tx: {outpoints:?}",
-            ),
-            CalculateFeeError::NegativeFee(fee) => write!(
-                f,
-                "transaction is invalid according to the graph and has negative fee: {}",
-                fee.display_dynamic()
-            ),
+            CalculateFeeError::MissingTxOut(outpoints) => {
+                let max_show = 3;
+                let shown: Vec<_> = outpoints.iter().take(max_show).collect();
+                let remaining = outpoints.len().saturating_sub(max_show);
+
+                write!(f, "cannot calculate fee, missing previous output(s): ")?;
+                if outpoints.is_empty() {
+                    write!(f, "<none>")
+                } else {
+                    write!(f, "{}", shown[0])?;
+                    for op in &shown[1..] {
+                        write!(f, ", {}", op)?;
+                    }
+                    if remaining > 0 {
+                        write!(f, " (+{} more)", remaining)?;
+                    }
+                    Ok(())
+                }
+            }
+            CalculateFeeError::NegativeFee(fee) => {
+                write!(
+                    f,
+                    "invalid transaction: negative fee {}",
+                    fee.display_dynamic()
+                )?;
+                Ok(())
+            }
         }
     }
 }