From 3b6e5e8eb0184a6d4d709ab24d694f075faaac38 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 18 Jul 2019 10:41:48 -0400 Subject: [PATCH] implement getIsConnected() --- src/wallet/MoneroWallet.cpp | 29 +++++++++++++++++++++++++++++ src/wallet/MoneroWallet.h | 10 ++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 82975df..f3c6f5c 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -70,6 +70,10 @@ using namespace tools; */ namespace monero { + // ------------------------- INITIALIZE CONSTANTS --------------------------- + + static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 30; + // ----------------------- INTERNAL PRIVATE HELPERS ----------------------- bool boolEquals(bool val, const boost::optional& optVal) { @@ -859,6 +863,31 @@ namespace monero { return connection; } + // TODO: could return Wallet::ConnectionStatus_Disconnected, Wallet::ConnectionStatus_WrongVersion, Wallet::ConnectionStatus_Connected like wallet.cpp::connected() + bool MoneroWallet::getIsConnected() { + uint32_t version = 0; + bool isConnected = wallet2->check_connection(&version, NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS); + if (!isConnected) return false; + if (!wallet2->light_wallet() && (version >> 16) != CORE_RPC_VERSION_MAJOR) return false; + return true; + } + + long MoneroWallet::getDaemonHeight() { + throw runtime_error("getDaemonHeight() not implemented"); + } + + long MoneroWallet::getDaemonTargetHeight() { + throw runtime_error("getDaemonTargetHeight() not implemented"); + } + + bool MoneroWallet::getIsDaemonSynced() { + throw runtime_error("getIsDaemonSynced() not implemented"); + } + + bool MoneroWallet::getIsSynced() { + throw runtime_error("getIsSynced() not implemented"); + } + string MoneroWallet::getPath() const { return wallet2->path(); } diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 5bf496f..f67b72f 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -225,6 +225,16 @@ namespace monero { */ shared_ptr getDaemonConnection() const; + bool getIsConnected(); + + long getDaemonHeight(); + + long getDaemonTargetHeight(); + + bool getIsDaemonSynced(); + + bool getIsSynced(); + /** * TODO */