Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider only L-BTC when calculating wallet balance #630

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hydra-yse marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading