From 6cdf13d2c8e21258c45fe5e21a07eb3ab5107bc6 Mon Sep 17 00:00:00 2001 From: VanshulB Date: Wed, 5 Mar 2025 07:25:47 +0530 Subject: [PATCH] fix: error while displaying expired fidelity bonds --- src/maker/rpc/messages.rs | 2 +- src/wallet/fidelity.rs | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/maker/rpc/messages.rs b/src/maker/rpc/messages.rs index 2dd8854b..1c67f9a2 100644 --- a/src/maker/rpc/messages.rs +++ b/src/maker/rpc/messages.rs @@ -134,7 +134,7 @@ impl Display for RpcMsgResp { Self::Shutdown => write!(f, "Shutdown Initiated"), Self::FidelitySpend(txid) => write!(f, "{}", txid), Self::ServerError(e) => write!(f, "{}", e), - Self::ListBonds(v) => write!(f, "{:#?}", v), + Self::ListBonds(v) => write!(f, "{}", v), } } } diff --git a/src/wallet/fidelity.rs b/src/wallet/fidelity.rs index 55220fca..d4d9375f 100644 --- a/src/wallet/fidelity.rs +++ b/src/wallet/fidelity.rs @@ -179,17 +179,34 @@ impl Wallet { .store .fidelity_bond .iter() - .map(|(index, (bond, _, _))| { + .map(|(index, (bond, _, is_spent))| { // assuming that lock_time is always in height and never in seconds. - self.calculate_bond_value(*index).map(|bond_value| { - serde_json::json!({ + match self.calculate_bond_value(*index) { + Ok(bond_value) => Ok(serde_json::json!({ "index": index, "outpoint": bond.outpoint.to_string(), "amount": bond.amount.to_sat(), "bond-value": bond_value, "expires-in": bond.lock_time.to_consensus_u32() - current_block, - }) - }) + })), + Err(err) => { + if matches!( + err, + WalletError::Fidelity(FidelityError::BondLocktimeExpired) + | WalletError::Fidelity(FidelityError::BondAlreadySpent) + ) { + Ok(serde_json::json!({ + "index": index, + "outpoint": bond.outpoint.to_string(), + "amount": bond.amount.to_sat(), + "is_expired": true, + "is_spent": *is_spent, + })) + } else { + Err(err) + } + } + } }) .collect::, WalletError>>()?;