diff --git a/lib/core/src/persist/mod.rs b/lib/core/src/persist/mod.rs index 30e88df42..afef0f117 100644 --- a/lib/core/src/persist/mod.rs +++ b/lib/core/src/persist/mod.rs @@ -104,7 +104,20 @@ impl Persister { pub(crate) fn insert_or_update_payment_with_wallet_tx(&self, tx: &WalletTx) -> Result<()> { let tx_id = tx.txid.to_string(); let is_tx_confirmed = tx.height.is_some(); - let amount_sat = tx.balance.values().sum::(); + let amount_sat = tx + .balance + .iter() + .filter_map(|(asset_id, balance)| { + if *asset_id == lwk_wollet::elements::AssetId::LIQUID_BTC { + return Some(balance); + } + None + }) + .sum::(); + if amount_sat == 0 { + log::warn!("Attempted to persist a payment with no output amount: tx_id {tx_id}"); + return Ok(()); + } let maybe_script_pubkey = tx .outputs .iter() diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index 2ebe663cf..a717c0c5b 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -2469,7 +2469,17 @@ impl LiquidSdk { let transactions = self.onchain_wallet.transactions().await?; let wallet_amount_sat = transactions .into_iter() - .map(|tx| tx.balance.values().sum::()) + .map(|tx| { + tx.balance + .into_iter() + .filter_map(|(asset_id, balance)| { + if asset_id == lwk_wollet::elements::AssetId::LIQUID_BTC { + return Some(balance); + } + None + }) + .sum::() + }) .sum::(); debug!("Onchain wallet balance: {wallet_amount_sat} sats");