mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-14 04:16:33 +02:00
Wallet: Cache connection status query
This commit is contained in:
parent
36a6b89b54
commit
3f8e05d7a4
@ -15,6 +15,7 @@
|
||||
namespace {
|
||||
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10;
|
||||
static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 60;
|
||||
static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5;
|
||||
}
|
||||
|
||||
class WalletListenerImpl : public Bitmonero::WalletListener
|
||||
@ -90,12 +91,19 @@ Wallet::Status Wallet::status() const
|
||||
Wallet::ConnectionStatus Wallet::connected()
|
||||
{
|
||||
qDebug("Checking wallet connection status");
|
||||
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
||||
if(newStatus != m_connectionStatus) {
|
||||
m_connectionStatus = newStatus;
|
||||
emit connectionStatusChanged();
|
||||
|
||||
// cache connection status
|
||||
if(m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl){
|
||||
qDebug("connectionStatus query");
|
||||
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
||||
if(newStatus != m_connectionStatus) {
|
||||
m_connectionStatus = newStatus;
|
||||
emit connectionStatusChanged();
|
||||
}
|
||||
m_connectionStatusTime.restart();
|
||||
}
|
||||
return newStatus;
|
||||
|
||||
return m_connectionStatus;
|
||||
}
|
||||
|
||||
bool Wallet::synchronized() const
|
||||
@ -425,10 +433,15 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
|
||||
, m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS)
|
||||
, m_daemonBlockChainTargetHeight(0)
|
||||
, m_daemonBlockChainTargetHeightTtl(DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS)
|
||||
, m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS)
|
||||
{
|
||||
m_history = new TransactionHistory(m_walletImpl->history(), this);
|
||||
m_walletImpl->setListener(new WalletListenerImpl(this));
|
||||
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
|
||||
// start cache timers
|
||||
m_connectionStatusTime.restart();
|
||||
m_daemonBlockChainHeightTime.restart();
|
||||
m_daemonBlockChainTargetHeightTime.restart();
|
||||
}
|
||||
|
||||
Wallet::~Wallet()
|
||||
|
@ -220,6 +220,8 @@ private:
|
||||
mutable quint64 m_daemonBlockChainTargetHeight;
|
||||
int m_daemonBlockChainTargetHeightTtl;
|
||||
ConnectionStatus m_connectionStatus;
|
||||
int m_connectionStatusTtl;
|
||||
mutable QTime m_connectionStatusTime;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user