Merge #18241: wallet/refactor: refer to CWallet immutably when possible

79facb11e92f8b61063f301027dee7c7344eb1be wallet: use constant CWallets in rpcwallet.cpp (Karl-Johan Alm)
d9b0ebc1da8758645f6de24a4a557511ef9b5e36 wallet: make ReserveDestination pwallet ivar const (Karl-Johan Alm)
57c569e4d9779e2263848770e0ba7eab3054a1bf wallet: make BackupWallet() const (Karl-Johan Alm)
df3a818d2a9fe48e656a8ad2da18fab8a1bfd6e3 wallet: make getters const (Karl-Johan Alm)
227b9dd2d6e1914edfec108af6bec5f12d9f6f39 wallet/spkm: make GetOldestKeyPoolTime() const (Karl-Johan Alm)
22d329ad0ed3ed501bd811720be6a2876d1afe4d wallet: use constant CWallets in rpcdump.cpp (Karl-Johan Alm)
7b3587b29db9eaf11718fc09d48817a45a0a429a wallet/db: make IsDummy() const (Karl-Johan Alm)
d366795d180bc52ba750f71f201a6e5e0c40f1b6 wallet/db: make Backup() const (Karl-Johan Alm)
8cd0b86340870d8f359e4ae26880e03ea36818ab wallet: make CanGetAddresses() const (Karl-Johan Alm)
037fa770eb1ed5152b3ef2c5d3fb2a812d3ef944 wallet: make KeypoolCountExternalKeys() const (Karl-Johan Alm)
ddc93557ad0cf8e433df850d38710828ccd99c16 wallet: make CanGenerateKeys() const (Karl-Johan Alm)
dc2d0650fdb69d27fe1b0092555b7841d542a635 make BlockUntilSyncedToCurrentChain() const (Karl-Johan Alm)

Pull request description:

  A lot of places refer to `CWallet*`'s as `CWallet * const`, which translates to *"an immutable pointer to a mutable `CWallet` instance"*; this is

  1. often not what the author meant, especially as a lot of these places do not at all modify the wallet object, and
  2. confusing, as it tends to suggest that this is a proper way to refer to a constant `CWallet` instance.

  This PR changes references to wallets to `const CWallet* const` whenever immutability is expected. This should result in no behavioral changes at all, and improved compile-time error checking.

  Note from irc:

  > <sipa> sounds good to me; this is the sort of change that as long as it compiles, the behavior shouldn't change
  > <sipa> though in general it may lead to introducing automatic copying of objects sometimes (e.g. trying to std::move a const object will work, but generally result in a copy rather than an efficient move)
  > <sipa> CWallet objects aren't copied or moved though

ACKs for top commit:
  laanwj:
    ACK 79facb11e92f8b61063f301027dee7c7344eb1be
  Empact:
    ACK 79facb11e9
  promag:
    ACK 79facb11e92f8b61063f301027dee7c7344eb1be.
  fjahr:
    ACK 79facb11e92f8b61063f301027dee7c7344eb1be

Tree-SHA512: 80a80c1a52f0f788d0ccb268b53bc0f46c796643a3c5a22b55bbbde4ffa6c7e347784e5e53b1e488a3b4e14399e31d5be9417ad5b6319c74a462609e9b1a98e8
This commit is contained in:
fanquake 2020-03-07 07:05:38 +08:00
commit 4d80274b99
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
12 changed files with 68 additions and 68 deletions

View File

@ -270,7 +270,7 @@ void BaseIndex::ChainStateFlushed(const CBlockLocator& locator)
Commit(); Commit();
} }
bool BaseIndex::BlockUntilSyncedToCurrentChain() bool BaseIndex::BlockUntilSyncedToCurrentChain() const
{ {
AssertLockNotHeld(cs_main); AssertLockNotHeld(cs_main);

View File

@ -97,7 +97,7 @@ public:
/// sync once and only needs to process blocks in the ValidationInterface /// sync once and only needs to process blocks in the ValidationInterface
/// queue. If the index is catching up from far behind, this method does /// queue. If the index is catching up from far behind, this method does
/// not block and immediately returns false. /// not block and immediately returns false.
bool BlockUntilSyncedToCurrentChain(); bool BlockUntilSyncedToCurrentChain() const;
void Interrupt(); void Interrupt();

View File

@ -468,7 +468,7 @@ public:
} }
unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; } unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
bool hdEnabled() override { return m_wallet->IsHDEnabled(); } bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
bool canGetAddresses() override { return m_wallet->CanGetAddresses(); } bool canGetAddresses() const override { return m_wallet->CanGetAddresses(); }
bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); } bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); }
OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; } OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; } OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }

View File

@ -246,7 +246,7 @@ public:
virtual bool hdEnabled() = 0; virtual bool hdEnabled() = 0;
// Return whether the wallet is blank. // Return whether the wallet is blank.
virtual bool canGetAddresses() = 0; virtual bool canGetAddresses() const = 0;
// check if a certain wallet flag is set. // check if a certain wallet flag is set.
virtual bool IsWalletFlagSet(uint64_t flag) = 0; virtual bool IsWalletFlagSet(uint64_t flag) = 0;

View File

@ -850,7 +850,7 @@ bool BerkeleyDatabase::Rewrite(const char* pszSkip)
return BerkeleyBatch::Rewrite(*this, pszSkip); return BerkeleyBatch::Rewrite(*this, pszSkip);
} }
bool BerkeleyDatabase::Backup(const std::string& strDest) bool BerkeleyDatabase::Backup(const std::string& strDest) const
{ {
if (IsDummy()) { if (IsDummy()) {
return false; return false;

View File

@ -157,7 +157,7 @@ public:
/** Back up the entire database to a file. /** Back up the entire database to a file.
*/ */
bool Backup(const std::string& strDest); bool Backup(const std::string& strDest) const;
/** Make sure all changes are flushed to disk. /** Make sure all changes are flushed to disk.
*/ */
@ -193,7 +193,7 @@ private:
* Only to be used at a low level, application should ideally not care * Only to be used at a low level, application should ideally not care
* about this. * about this.
*/ */
bool IsDummy() { return env == nullptr; } bool IsDummy() const { return env == nullptr; }
}; };
/** RAII class that provides access to a Berkeley database */ /** RAII class that provides access to a Berkeley database */

View File

@ -54,7 +54,7 @@ static std::string DecodeDumpString(const std::string &str) {
return ret.str(); return ret.str();
} }
static bool GetWalletAddressesForKey(LegacyScriptPubKeyMan* spk_man, CWallet* const pwallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) static bool GetWalletAddressesForKey(LegacyScriptPubKeyMan* spk_man, const CWallet* const pwallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{ {
bool fLabelFound = false; bool fLabelFound = false;
CKey key; CKey key;
@ -65,7 +65,7 @@ static bool GetWalletAddressesForKey(LegacyScriptPubKeyMan* spk_man, CWallet* co
strAddr += ","; strAddr += ",";
} }
strAddr += EncodeDestination(dest); strAddr += EncodeDestination(dest);
strLabel = EncodeDumpString(pwallet->mapAddressBook[dest].name); strLabel = EncodeDumpString(pwallet->mapAddressBook.at(dest).name);
fLabelFound = true; fLabelFound = true;
} }
} }
@ -676,7 +676,7 @@ UniValue importwallet(const JSONRPCRequest& request)
UniValue dumpprivkey(const JSONRPCRequest& request) UniValue dumpprivkey(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
} }
@ -724,7 +724,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
UniValue dumpwallet(const JSONRPCRequest& request) UniValue dumpwallet(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
} }

View File

@ -40,7 +40,7 @@
static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; static const std::string WALLET_ENDPOINT_BASE = "/wallet/";
static inline bool GetAvoidReuseFlag(CWallet * const pwallet, const UniValue& param) { static inline bool GetAvoidReuseFlag(const CWallet* const pwallet, const UniValue& param) {
bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool();
@ -458,7 +458,7 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
static UniValue listaddressgroupings(const JSONRPCRequest& request) static UniValue listaddressgroupings(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -520,7 +520,7 @@ static UniValue listaddressgroupings(const JSONRPCRequest& request)
static UniValue signmessage(const JSONRPCRequest& request) static UniValue signmessage(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -590,7 +590,7 @@ static UniValue signmessage(const JSONRPCRequest& request)
static UniValue getreceivedbyaddress(const JSONRPCRequest& request) static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -660,7 +660,7 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
static UniValue getreceivedbylabel(const JSONRPCRequest& request) static UniValue getreceivedbylabel(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -728,7 +728,7 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
static UniValue getbalance(const JSONRPCRequest& request) static UniValue getbalance(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -786,7 +786,7 @@ static UniValue getbalance(const JSONRPCRequest& request)
static UniValue getunconfirmedbalance(const JSONRPCRequest &request) static UniValue getunconfirmedbalance(const JSONRPCRequest &request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -1041,7 +1041,7 @@ struct tallyitem
} }
}; };
static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, CWallet * const pwallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, const CWallet* const pwallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{ {
// Minimum confirmations // Minimum confirmations
int nMinDepth = 1; int nMinDepth = 1;
@ -1190,7 +1190,7 @@ static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, CWallet * co
static UniValue listreceivedbyaddress(const JSONRPCRequest& request) static UniValue listreceivedbyaddress(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -1242,7 +1242,7 @@ static UniValue listreceivedbyaddress(const JSONRPCRequest& request)
static UniValue listreceivedbylabel(const JSONRPCRequest& request) static UniValue listreceivedbylabel(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -1302,7 +1302,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
* @param filter_ismine The "is mine" filter flags. * @param filter_ismine The "is mine" filter flags.
* @param filter_label Optional label string to filter incoming transactions. * @param filter_label Optional label string to filter incoming transactions.
*/ */
static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWallet* const pwallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{ {
CAmount nFee; CAmount nFee;
std::list<COutputEntry> listReceived; std::list<COutputEntry> listReceived;
@ -1325,7 +1325,7 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* con
entry.pushKV("category", "send"); entry.pushKV("category", "send");
entry.pushKV("amount", ValueFromAmount(-s.amount)); entry.pushKV("amount", ValueFromAmount(-s.amount));
if (pwallet->mapAddressBook.count(s.destination)) { if (pwallet->mapAddressBook.count(s.destination)) {
entry.pushKV("label", pwallet->mapAddressBook[s.destination].name); entry.pushKV("label", pwallet->mapAddressBook.at(s.destination).name);
} }
entry.pushKV("vout", s.vout); entry.pushKV("vout", s.vout);
entry.pushKV("fee", ValueFromAmount(-nFee)); entry.pushKV("fee", ValueFromAmount(-nFee));
@ -1342,7 +1342,7 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, CWallet* con
{ {
std::string label; std::string label;
if (pwallet->mapAddressBook.count(r.destination)) { if (pwallet->mapAddressBook.count(r.destination)) {
label = pwallet->mapAddressBook[r.destination].name; label = pwallet->mapAddressBook.at(r.destination).name;
} }
if (filter_label && label != *filter_label) { if (filter_label && label != *filter_label) {
continue; continue;
@ -1402,7 +1402,7 @@ static const std::vector<RPCResult> TransactionDescriptionString()
UniValue listtransactions(const JSONRPCRequest& request) UniValue listtransactions(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -1516,7 +1516,7 @@ UniValue listtransactions(const JSONRPCRequest& request)
static UniValue listsinceblock(const JSONRPCRequest& request) static UniValue listsinceblock(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -1658,7 +1658,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
static UniValue gettransaction(const JSONRPCRequest& request) static UniValue gettransaction(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -1817,7 +1817,7 @@ static UniValue abandontransaction(const JSONRPCRequest& request)
static UniValue backupwallet(const JSONRPCRequest& request) static UniValue backupwallet(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -2266,7 +2266,7 @@ static UniValue lockunspent(const JSONRPCRequest& request)
static UniValue listlockunspent(const JSONRPCRequest& request) static UniValue listlockunspent(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -2432,7 +2432,7 @@ static UniValue getbalances(const JSONRPCRequest& request)
static UniValue getwalletinfo(const JSONRPCRequest& request) static UniValue getwalletinfo(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -2814,7 +2814,7 @@ static UniValue unloadwallet(const JSONRPCRequest& request)
static UniValue listunspent(const JSONRPCRequest& request) static UniValue listunspent(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -3248,7 +3248,7 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request)
UniValue signrawtransactionwithwallet(const JSONRPCRequest& request) UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -3728,7 +3728,7 @@ public:
UniValue operator()(const WitnessUnknown& id) const { return UniValue(UniValue::VOBJ); } UniValue operator()(const WitnessUnknown& id) const { return UniValue(UniValue::VOBJ); }
}; };
static UniValue DescribeWalletAddress(CWallet* pwallet, const CTxDestination& dest) static UniValue DescribeWalletAddress(const CWallet* const pwallet, const CTxDestination& dest)
{ {
UniValue ret(UniValue::VOBJ); UniValue ret(UniValue::VOBJ);
UniValue detail = DescribeAddress(dest); UniValue detail = DescribeAddress(dest);
@ -3756,7 +3756,7 @@ static UniValue AddressBookDataToJSON(const CAddressBookData& data, const bool v
UniValue getaddressinfo(const JSONRPCRequest& request) UniValue getaddressinfo(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -3858,7 +3858,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
// be associated with an address, so the label should be equivalent to the // be associated with an address, so the label should be equivalent to the
// value of the name key/value pair in the labels array below. // value of the name key/value pair in the labels array below.
if ((pwallet->chain().rpcEnableDeprecated("label")) && (pwallet->mapAddressBook.count(dest))) { if ((pwallet->chain().rpcEnableDeprecated("label")) && (pwallet->mapAddressBook.count(dest))) {
ret.pushKV("label", pwallet->mapAddressBook[dest].name); ret.pushKV("label", pwallet->mapAddressBook.at(dest).name);
} }
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey)); ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
@ -3881,7 +3881,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
// stable if we allow multiple labels to be associated with an address in // stable if we allow multiple labels to be associated with an address in
// the future. // the future.
UniValue labels(UniValue::VARR); UniValue labels(UniValue::VARR);
std::map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(dest); std::map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(dest);
if (mi != pwallet->mapAddressBook.end()) { if (mi != pwallet->mapAddressBook.end()) {
// DEPRECATED: The previous behavior of returning an array containing a // DEPRECATED: The previous behavior of returning an array containing a
// JSON object of `name` and `purpose` key/value pairs is deprecated. // JSON object of `name` and `purpose` key/value pairs is deprecated.
@ -3899,7 +3899,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
static UniValue getaddressesbylabel(const JSONRPCRequest& request) static UniValue getaddressesbylabel(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -3958,7 +3958,7 @@ static UniValue getaddressesbylabel(const JSONRPCRequest& request)
static UniValue listlabels(const JSONRPCRequest& request) static UniValue listlabels(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;
@ -4091,7 +4091,7 @@ UniValue sethdseed(const JSONRPCRequest& request)
UniValue walletprocesspsbt(const JSONRPCRequest& request) UniValue walletprocesspsbt(const JSONRPCRequest& request)
{ {
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get(); const CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue; return NullUniValue;

View File

@ -358,7 +358,7 @@ bool LegacyScriptPubKeyMan::IsHDEnabled() const
return !hdChain.seed_id.IsNull(); return !hdChain.seed_id.IsNull();
} }
bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) const
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
// Check if the keypool has keys // Check if the keypool has keys
@ -441,7 +441,7 @@ static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, Walle
return keypool.nTime; return keypool.nTime;
} }
int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime() int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime() const
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
@ -459,7 +459,7 @@ int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime()
return oldestKey; return oldestKey;
} }
size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys() size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys() const
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
return setExternalKeyPool.size() + set_pre_split_keypool.size(); return setExternalKeyPool.size() + set_pre_split_keypool.size();
@ -973,7 +973,7 @@ void LegacyScriptPubKeyMan::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime); mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
} }
bool LegacyScriptPubKeyMan::CanGenerateKeys() bool LegacyScriptPubKeyMan::CanGenerateKeys() const
{ {
// A wallet can generate keys if it has an HD seed (IsHDEnabled) or it is a non-HD wallet (pre FEATURE_HD) // A wallet can generate keys if it has an HD seed (IsHDEnabled) or it is a non-HD wallet (pre FEATURE_HD)
LOCK(cs_KeyStore); LOCK(cs_KeyStore);

View File

@ -184,7 +184,7 @@ public:
virtual bool IsHDEnabled() const { return false; } virtual bool IsHDEnabled() const { return false; }
/* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */ /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
virtual bool CanGetAddresses(bool internal = false) { return false; } virtual bool CanGetAddresses(bool internal = false) const { return false; }
/** Upgrades the wallet to the specified version */ /** Upgrades the wallet to the specified version */
virtual bool Upgrade(int prev_version, std::string& error) { return false; } virtual bool Upgrade(int prev_version, std::string& error) { return false; }
@ -194,9 +194,9 @@ public:
//! The action to do when the DB needs rewrite //! The action to do when the DB needs rewrite
virtual void RewriteDB() {} virtual void RewriteDB() {}
virtual int64_t GetOldestKeyPoolTime() { return GetTime(); } virtual int64_t GetOldestKeyPoolTime() const { return GetTime(); }
virtual size_t KeypoolCountExternalKeys() { return 0; } virtual size_t KeypoolCountExternalKeys() const { return 0; }
virtual unsigned int GetKeyPoolSize() const { return 0; } virtual unsigned int GetKeyPoolSize() const { return 0; }
virtual int64_t GetTimeFirstKey() const { return 0; } virtual int64_t GetTimeFirstKey() const { return 0; }
@ -336,15 +336,15 @@ public:
void RewriteDB() override; void RewriteDB() override;
int64_t GetOldestKeyPoolTime() override; int64_t GetOldestKeyPoolTime() const override;
size_t KeypoolCountExternalKeys() override; size_t KeypoolCountExternalKeys() const override;
unsigned int GetKeyPoolSize() const override; unsigned int GetKeyPoolSize() const override;
int64_t GetTimeFirstKey() const override; int64_t GetTimeFirstKey() const override;
const CKeyMetadata* GetMetadata(const CTxDestination& dest) const override; const CKeyMetadata* GetMetadata(const CTxDestination& dest) const override;
bool CanGetAddresses(bool internal = false) override; bool CanGetAddresses(bool internal = false) const override;
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const override; std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const override;
@ -410,7 +410,7 @@ public:
bool ImportScriptPubKeys(const std::set<CScript>& script_pub_keys, const bool have_solving_data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); bool ImportScriptPubKeys(const std::set<CScript>& script_pub_keys, const bool have_solving_data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
/* Returns true if the wallet can generate new keys */ /* Returns true if the wallet can generate new keys */
bool CanGenerateKeys(); bool CanGenerateKeys() const;
/* Generates a new HD seed (will not be activated) */ /* Generates a new HD seed (will not be activated) */
CPubKey GenerateNewSeed(); CPubKey GenerateNewSeed();

View File

@ -1150,7 +1150,7 @@ void CWallet::UpdatedBlockTip()
} }
void CWallet::BlockUntilSyncedToCurrentChain() { void CWallet::BlockUntilSyncedToCurrentChain() const {
AssertLockNotHeld(cs_wallet); AssertLockNotHeld(cs_wallet);
// Skip the queue-draining stuff if we know we're caught up with // Skip the queue-draining stuff if we know we're caught up with
// ::ChainActive().Tip(), otherwise put a callback in the validation interface queue and wait // ::ChainActive().Tip(), otherwise put a callback in the validation interface queue and wait
@ -1333,7 +1333,7 @@ bool CWallet::IsHDEnabled() const
return result; return result;
} }
bool CWallet::CanGetAddresses(bool internal) bool CWallet::CanGetAddresses(bool internal) const
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
if (m_spk_managers.empty()) return false; if (m_spk_managers.empty()) return false;
@ -3112,7 +3112,7 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
return WalletBatch(*database).EraseName(EncodeDestination(address)); return WalletBatch(*database).EraseName(EncodeDestination(address));
} }
size_t CWallet::KeypoolCountExternalKeys() size_t CWallet::KeypoolCountExternalKeys() const
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
@ -3177,7 +3177,7 @@ bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& des
return true; return true;
} }
int64_t CWallet::GetOldestKeyPoolTime() int64_t CWallet::GetOldestKeyPoolTime() const
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
int64_t oldestKey = std::numeric_limits<int64_t>::max(); int64_t oldestKey = std::numeric_limits<int64_t>::max();
@ -3201,7 +3201,7 @@ void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations
} }
} }
std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain::Lock& locked_chain) std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain::Lock& locked_chain) const
{ {
std::map<CTxDestination, CAmount> balances; std::map<CTxDestination, CAmount> balances;
@ -3242,7 +3242,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain:
return balances; return balances;
} }
std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings() std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings() const
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
std::set< std::set<CTxDestination> > groupings; std::set< std::set<CTxDestination> > groupings;
@ -4004,7 +4004,7 @@ void CWallet::postInitProcess()
chain().requestMempoolTransactions(*this); chain().requestMempoolTransactions(*this);
} }
bool CWallet::BackupWallet(const std::string& strDest) bool CWallet::BackupWallet(const std::string& strDest) const
{ {
return database->Backup(strDest); return database->Backup(strDest);
} }

View File

@ -141,7 +141,7 @@ class ReserveDestination
{ {
protected: protected:
//! The wallet to reserve from //! The wallet to reserve from
CWallet* const pwallet; const CWallet* const pwallet;
//! The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called //! The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called
ScriptPubKeyMan* m_spk_man{nullptr}; ScriptPubKeyMan* m_spk_man{nullptr};
OutputType const type; OutputType const type;
@ -832,8 +832,8 @@ public:
* Rescan abort properties * Rescan abort properties
*/ */
void AbortRescan() { fAbortRescan = true; } void AbortRescan() { fAbortRescan = true; }
bool IsAbortingRescan() { return fAbortRescan; } bool IsAbortingRescan() const { return fAbortRescan; }
bool IsScanning() { return fScanningWallet; } bool IsScanning() const { return fScanningWallet; }
int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; } int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; }
double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; } double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
@ -968,13 +968,13 @@ public:
/** Absolute maximum transaction fee (in satoshis) used by default for the wallet */ /** Absolute maximum transaction fee (in satoshis) used by default for the wallet */
CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE}; CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE};
size_t KeypoolCountExternalKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool TopUpKeyPool(unsigned int kpSize = 0); bool TopUpKeyPool(unsigned int kpSize = 0);
int64_t GetOldestKeyPoolTime(); int64_t GetOldestKeyPoolTime() const;
std::set<std::set<CTxDestination>> GetAddressGroupings() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::set<std::set<CTxDestination>> GetAddressGroupings() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
std::map<CTxDestination, CAmount> GetAddressBalances(interfaces::Chain::Lock& locked_chain); std::map<CTxDestination, CAmount> GetAddressBalances(interfaces::Chain::Lock& locked_chain) const;
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const; std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
@ -1027,7 +1027,7 @@ public:
bool SetMaxVersion(int nVersion); bool SetMaxVersion(int nVersion);
//! get the current wallet format (the oldest client version guaranteed to understand this wallet) //! get the current wallet format (the oldest client version guaranteed to understand this wallet)
int GetVersion() { LOCK(cs_wallet); return nWalletVersion; } int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
//! Get wallet transactions that conflict with given transaction (spend same outputs) //! Get wallet transactions that conflict with given transaction (spend same outputs)
std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@ -1098,13 +1098,13 @@ public:
*/ */
void postInitProcess(); void postInitProcess();
bool BackupWallet(const std::string& strDest); bool BackupWallet(const std::string& strDest) const;
/* Returns true if HD is enabled */ /* Returns true if HD is enabled */
bool IsHDEnabled() const; bool IsHDEnabled() const;
/* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */ /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
bool CanGetAddresses(bool internal = false); bool CanGetAddresses(bool internal = false) const;
/** /**
* Blocks until the wallet state is up-to-date to /at least/ the current * Blocks until the wallet state is up-to-date to /at least/ the current
@ -1112,7 +1112,7 @@ public:
* Obviously holding cs_main/cs_wallet when going into this call may cause * Obviously holding cs_main/cs_wallet when going into this call may cause
* deadlock * deadlock
*/ */
void BlockUntilSyncedToCurrentChain() LOCKS_EXCLUDED(cs_main, cs_wallet); void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(cs_main, cs_wallet);
/** set a single wallet flag */ /** set a single wallet flag */
void SetWalletFlag(uint64_t flags); void SetWalletFlag(uint64_t flags);