mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-17 00:07:51 +00:00
Wallet: Cache connection status query
This commit is contained in:
parent
36a6b89b54
commit
3f8e05d7a4
2 changed files with 20 additions and 5 deletions
|
@ -15,6 +15,7 @@
|
||||||
namespace {
|
namespace {
|
||||||
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10;
|
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10;
|
||||||
static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 60;
|
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
|
class WalletListenerImpl : public Bitmonero::WalletListener
|
||||||
|
@ -90,12 +91,19 @@ Wallet::Status Wallet::status() const
|
||||||
Wallet::ConnectionStatus Wallet::connected()
|
Wallet::ConnectionStatus Wallet::connected()
|
||||||
{
|
{
|
||||||
qDebug("Checking wallet connection status");
|
qDebug("Checking wallet connection status");
|
||||||
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
|
||||||
if(newStatus != m_connectionStatus) {
|
// cache connection status
|
||||||
m_connectionStatus = newStatus;
|
if(m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl){
|
||||||
emit connectionStatusChanged();
|
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
|
bool Wallet::synchronized() const
|
||||||
|
@ -425,10 +433,15 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
|
||||||
, m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS)
|
, m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS)
|
||||||
, m_daemonBlockChainTargetHeight(0)
|
, m_daemonBlockChainTargetHeight(0)
|
||||||
, m_daemonBlockChainTargetHeightTtl(DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS)
|
, 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_history = new TransactionHistory(m_walletImpl->history(), this);
|
||||||
m_walletImpl->setListener(new WalletListenerImpl(this));
|
m_walletImpl->setListener(new WalletListenerImpl(this));
|
||||||
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
|
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
|
||||||
|
// start cache timers
|
||||||
|
m_connectionStatusTime.restart();
|
||||||
|
m_daemonBlockChainHeightTime.restart();
|
||||||
|
m_daemonBlockChainTargetHeightTime.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet::~Wallet()
|
Wallet::~Wallet()
|
||||||
|
|
|
@ -220,6 +220,8 @@ private:
|
||||||
mutable quint64 m_daemonBlockChainTargetHeight;
|
mutable quint64 m_daemonBlockChainTargetHeight;
|
||||||
int m_daemonBlockChainTargetHeightTtl;
|
int m_daemonBlockChainTargetHeightTtl;
|
||||||
ConnectionStatus m_connectionStatus;
|
ConnectionStatus m_connectionStatus;
|
||||||
|
int m_connectionStatusTtl;
|
||||||
|
mutable QTime m_connectionStatusTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue