refactor: add coin_is_owned method

This commit is contained in:
Michael Mallan 2024-12-20 14:58:53 +00:00
parent 3a4df7aeec
commit 1b33e74a7a
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB
2 changed files with 9 additions and 2 deletions

View File

@ -29,7 +29,7 @@ use super::{
pub const HISTORY_EVENT_PAGE_SIZE: u64 = 20;
use crate::daemon::model::LabelsLoader;
use crate::daemon::model::{coin_is_owned, LabelsLoader};
use crate::daemon::{
model::{remaining_sequence, Coin, HistoryTransaction, Payment},
Daemon,
@ -94,7 +94,7 @@ fn coins_summary(
for coin in coins {
if coin.spend_info.is_none() {
// Include unconfirmed coins from self in confirmed balance.
if coin.block_height.is_some() || coin.is_from_self {
if coin_is_owned(coin) {
balance += coin.amount;
// Only consider confirmed coins for remaining seq
// (they would not be considered as expiring so we can also skip that part)

View File

@ -29,6 +29,13 @@ pub fn remaining_sequence(coin: &Coin, blockheight: u32, timelock: u16) -> u32 {
}
}
/// Whether the coin is owned by this wallet.
/// This comprises all confirmed coins together with those
/// unconfirmed coins from self.
pub fn coin_is_owned(coin: &Coin) -> bool {
coin.block_height.is_some() || coin.is_from_self
}
#[derive(Debug, Clone)]
pub struct SpendTx {
pub network: Network,