aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2020-02-16 11:38:49 +0000
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2020-02-16 11:38:49 +0000
commit0933a37078e1ce3a3d70983c3e7f4b3ac6c3fa37 (patch)
treefad17411a6dac54f3146787aac39b07eb32c45de /src/interfaces
parent2a2631fb0dc781504df0f3fe8b42f21cbdb6f20d (diff)
gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/wallet.cpp5
-rw-r--r--src/interfaces/wallet.h7
2 files changed, 8 insertions, 4 deletions
diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp
index baea71d0bb..eeaf3d075d 100644
--- a/src/interfaces/wallet.cpp
+++ b/src/interfaces/wallet.cpp
@@ -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; }
diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h
index d4280e8091..caca2683d0 100644
--- a/src/interfaces/wallet.h
+++ b/src/interfaces/wallet.h
@@ -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;