From ac0de44a2f88e8fde3d78df80a4eb1556663935b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Wed, 18 Apr 2018 13:46:11 +0100 Subject: [PATCH] wallet: Add HasWallets --- src/rpc/misc.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- src/wallet/wallet.cpp | 5 +++++ src/wallet/wallet.h | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index ba3ea705577e8..6754407dbdb66 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -69,7 +69,7 @@ UniValue validateaddress(const JSONRPCRequest& request) { #ifdef ENABLE_WALLET - if (!GetWallets().empty() && IsDeprecatedRPCEnabled("validateaddress")) { + if (HasWallets() && IsDeprecatedRPCEnabled("validateaddress")) { ret.pushKVs(getaddressinfo(request)); } #endif diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9875a2697dde4..9b5fb0b062d1c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -66,7 +66,7 @@ bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException) { if (pwallet) return true; if (avoidException) return false; - if (GetWallets().empty()) { + if (!HasWallets()) { // Note: It isn't currently possible to trigger this error because // wallet RPC methods aren't registered unless a wallet is loaded. But // this error is being kept as a precaution, because it's possible in diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c04760f0bc622..1f86fb535b346 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -50,6 +50,11 @@ void RemoveWallet(CWallet* wallet) if (i != vpwallets.end()) vpwallets.erase(i); } +bool HasWallets() +{ + return !vpwallets.empty(); +} + std::vector GetWallets() { return vpwallets; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index efaf83d7555e6..23c75aa5a629b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -34,6 +34,7 @@ void AddWallet(CWallet* wallet); void RemoveWallet(CWallet* wallet); +bool HasWallets(); std::vector GetWallets(); CWallet* GetWallet(const std::string& name);