mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 03:33:27 -03:00
gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged
This commit is contained in:
parent
2a2631fb0d
commit
0933a37078
3 changed files with 15 additions and 14 deletions
|
@ -380,16 +380,17 @@ public:
|
||||||
}
|
}
|
||||||
return result;
|
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 */);
|
auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
|
||||||
if (!locked_chain) return false;
|
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);
|
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
|
||||||
if (!locked_wallet) {
|
if (!locked_wallet) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
balances = getBalances();
|
balances = getBalances();
|
||||||
num_blocks = locked_chain->getHeight().get_value_or(-1);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
|
CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
|
||||||
|
|
|
@ -201,8 +201,11 @@ public:
|
||||||
//! Get balances.
|
//! Get balances.
|
||||||
virtual WalletBalances getBalances() = 0;
|
virtual WalletBalances getBalances() = 0;
|
||||||
|
|
||||||
//! Get balances if possible without blocking.
|
//! Get balances if possible without waiting for chain and wallet locks.
|
||||||
virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;
|
virtual bool tryGetBalances(WalletBalances& balances,
|
||||||
|
int& num_blocks,
|
||||||
|
bool force,
|
||||||
|
int cached_num_blocks) = 0;
|
||||||
|
|
||||||
//! Get balance.
|
//! Get balance.
|
||||||
virtual CAmount getBalance() = 0;
|
virtual CAmount getBalance() = 0;
|
||||||
|
|
|
@ -78,12 +78,10 @@ void WalletModel::pollBalanceChanged()
|
||||||
// rescan.
|
// rescan.
|
||||||
interfaces::WalletBalances new_balances;
|
interfaces::WalletBalances new_balances;
|
||||||
int numBlocks = -1;
|
int numBlocks = -1;
|
||||||
if (!m_wallet->tryGetBalances(new_balances, numBlocks)) {
|
if (!m_wallet->tryGetBalances(new_balances, numBlocks, fForceCheckBalanceChanged, cachedNumBlocks)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
|
|
||||||
{
|
|
||||||
fForceCheckBalanceChanged = false;
|
fForceCheckBalanceChanged = false;
|
||||||
|
|
||||||
// Balance and number of transactions might have changed
|
// Balance and number of transactions might have changed
|
||||||
|
@ -93,7 +91,6 @@ void WalletModel::pollBalanceChanged()
|
||||||
if(transactionTableModel)
|
if(transactionTableModel)
|
||||||
transactionTableModel->updateConfirmations();
|
transactionTableModel->updateConfirmations();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances)
|
void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue