mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged
This commit is contained in:
@@ -380,16 +380,17 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
|
||||
bool tryGetBalances(WalletBalances& balances, int& num_blocks, bool force, int cached_num_blocks) override
|
||||
{
|
||||
auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
|
||||
if (!locked_chain) return false;
|
||||
num_blocks = locked_chain->getHeight().get_value_or(-1);
|
||||
if (!force && num_blocks == cached_num_blocks) return false;
|
||||
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
|
||||
if (!locked_wallet) {
|
||||
return false;
|
||||
}
|
||||
balances = getBalances();
|
||||
num_blocks = locked_chain->getHeight().get_value_or(-1);
|
||||
return true;
|
||||
}
|
||||
CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
|
||||
|
||||
@@ -201,8 +201,11 @@ public:
|
||||
//! Get balances.
|
||||
virtual WalletBalances getBalances() = 0;
|
||||
|
||||
//! Get balances if possible without blocking.
|
||||
virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;
|
||||
//! Get balances if possible without waiting for chain and wallet locks.
|
||||
virtual bool tryGetBalances(WalletBalances& balances,
|
||||
int& num_blocks,
|
||||
bool force,
|
||||
int cached_num_blocks) = 0;
|
||||
|
||||
//! Get balance.
|
||||
virtual CAmount getBalance() = 0;
|
||||
|
||||
Reference in New Issue
Block a user