Skip to content

Commit

Permalink
fix: consider only L-BTC when calculating wallet balance (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse authored Dec 30, 2024
1 parent 6782e8b commit d3a3b2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i64>();
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::<i64>();
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()
Expand Down
12 changes: 11 additions & 1 deletion lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i64>())
.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::<i64>()
})
.sum::<i64>();
debug!("Onchain wallet balance: {wallet_amount_sat} sats");

Expand Down

0 comments on commit d3a3b2b

Please sign in to comment.