From: Dmenec Date: Thu, 11 Dec 2025 11:01:34 +0000 (+0100) Subject: fix(chain)!: remove Debug usage and implement Display for CalculateFeeError X-Git-Url: http://internal-gitweb-vhost/parse/src/example_cli/%22https:/struct.InsertBlockNotMatchingError.html?a=commitdiff_plain;h=5a85f6e25a9e14204cb66fec3f7381a59133f0be;p=bdk fix(chain)!: remove Debug usage and implement Display for CalculateFeeError Limited to 3 max shown items and added a suffix when there are additional entries. --- diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index 97d4ecc0..701de335 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -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, "") + } 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(()) + } } } }