From 531057438201c8c4f5ae860753aefeb298d8db59 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sat, 25 Feb 2017 22:08:50 +0100 Subject: [PATCH] Wallet API: Add support for daemon rpc login --- src/wallet/api/wallet.cpp | 6 ++++-- src/wallet/api/wallet.h | 3 ++- src/wallet/wallet2_api.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index c798d4d3..99645189 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -656,9 +656,11 @@ string WalletImpl::keysFilename() const return m_wallet->get_keys_file(); } -bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) +bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password) { clearStatus(); + if(daemon_username != "") + m_daemon_login.emplace(daemon_username, daemon_password); return doInit(daemon_address, upper_transaction_size_limit); } @@ -1365,7 +1367,7 @@ bool WalletImpl::isNewWallet() const bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit) { - if (!m_wallet->init(daemon_address, boost::none, upper_transaction_size_limit)) + if (!m_wallet->init(daemon_address, m_daemon_login, upper_transaction_size_limit)) return false; // in case new wallet, this will force fast-refresh (pulling hashes instead of blocks) diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 3501fa0a..45611090 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -78,7 +78,7 @@ public: bool store(const std::string &path); std::string filename() const; std::string keysFilename() const; - bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0); + bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = ""); bool connectToDaemon(); ConnectionStatus connected() const; void setTrustedDaemon(bool arg); @@ -170,6 +170,7 @@ private: std::atomic m_rebuildWalletCache; // cache connection status to avoid unnecessary RPC calls mutable std::atomic m_is_connected; + boost::optional m_daemon_login{}; }; diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index eec4f8b8..e32d23d9 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -340,7 +340,7 @@ struct Wallet * \param upper_transaction_size_limit * \return - true on success */ - virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0; + virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username = "", const std::string &daemon_password = "") = 0; /*! * \brief createWatchOnly - Creates a watch only wallet