diff options
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/crypter.h | 4 | ||||
-rw-r--r-- | src/wallet/db.h | 1 | ||||
-rw-r--r-- | src/wallet/init.cpp | 40 | ||||
-rw-r--r-- | src/wallet/init.h | 48 | ||||
-rw-r--r-- | src/wallet/rpcdump.cpp | 2 | ||||
-rw-r--r-- | src/wallet/test/wallet_crypto_tests.cpp (renamed from src/wallet/test/crypto_tests.cpp) | 2 | ||||
-rw-r--r-- | src/wallet/test/wallet_test_fixture.h | 2 | ||||
-rw-r--r-- | src/wallet/test/wallet_tests.cpp | 1 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 5 | ||||
-rw-r--r-- | src/wallet/wallet.h | 50 |
10 files changed, 64 insertions, 91 deletions
diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h index fdeb4cfee0..4c0c8ff5ec 100644 --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -67,7 +67,7 @@ public: typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial; -namespace crypto_tests +namespace wallet_crypto_tests { class TestCrypter; } @@ -75,7 +75,7 @@ namespace crypto_tests /** Encryption/decryption context with key information */ class CCrypter { -friend class crypto_tests::TestCrypter; // for test access to chKey/chIV +friend class wallet_crypto_tests::TestCrypter; // for test access to chKey/chIV private: std::vector<unsigned char, secure_allocator<unsigned char>> vchKey; std::vector<unsigned char, secure_allocator<unsigned char>> vchIV; diff --git a/src/wallet/db.h b/src/wallet/db.h index 65bb8cc253..49a9f3f082 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -16,6 +16,7 @@ #include <atomic> #include <map> +#include <memory> #include <string> #include <vector> diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 3d7bb674f0..c860eede05 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -3,17 +3,53 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include <wallet/init.h> - #include <chainparams.h> +#include <init.h> #include <net.h> #include <util.h> #include <utilmoneystr.h> #include <validation.h> +#include <walletinitinterface.h> #include <wallet/rpcwallet.h> #include <wallet/wallet.h> #include <wallet/walletutil.h> +class WalletInit : public WalletInitInterface { +public: + + //! Return the wallets help message. + std::string GetHelpString(bool showDebug) override; + + //! Wallets parameter interaction + bool ParameterInteraction() override; + + //! Register wallet RPCs. + void RegisterRPC(CRPCTable &tableRPC) override; + + //! Responsible for reading and validating the -wallet arguments and verifying the wallet database. + // This function will perform salvage on the wallet if requested, as long as only one wallet is + // being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). + bool Verify() override; + + //! Load wallet databases. + bool Open() override; + + //! Complete startup of wallets. + void Start(CScheduler& scheduler) override; + + //! Flush all wallets in preparation for shutdown. + void Flush() override; + + //! Stop all wallets. Wallets will be flushed first. + void Stop() override; + + //! Close all wallets. + void Close() override; +}; + +static WalletInit g_wallet_init; +WalletInitInterface* const g_wallet_init_interface = &g_wallet_init; + std::string WalletInit::GetHelpString(bool showDebug) { std::string strUsage = HelpMessageGroup(_("Wallet options:")); diff --git a/src/wallet/init.h b/src/wallet/init.h deleted file mode 100644 index f8be90d3e3..0000000000 --- a/src/wallet/init.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2017 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_WALLET_INIT_H -#define BITCOIN_WALLET_INIT_H - -#include <walletinitinterface.h> -#include <string> - -class CRPCTable; -class CScheduler; - -class WalletInit : public WalletInitInterface { -public: - - //! Return the wallets help message. - std::string GetHelpString(bool showDebug) override; - - //! Wallets parameter interaction - bool ParameterInteraction() override; - - //! Register wallet RPCs. - void RegisterRPC(CRPCTable &tableRPC) override; - - //! Responsible for reading and validating the -wallet arguments and verifying the wallet database. - // This function will perform salvage on the wallet if requested, as long as only one wallet is - // being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). - bool Verify() override; - - //! Load wallet databases. - bool Open() override; - - //! Complete startup of wallets. - void Start(CScheduler& scheduler) override; - - //! Flush all wallets in preparation for shutdown. - void Flush() override; - - //! Stop all wallets. Wallets will be flushed first. - void Stop() override; - - //! Close all wallets. - void Close() override; -}; - -#endif // BITCOIN_WALLET_INIT_H diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 28b6153ce1..a3594aa692 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -6,7 +6,6 @@ #include <key_io.h> #include <rpc/safemode.h> #include <rpc/server.h> -#include <wallet/init.h> #include <validation.h> #include <script/script.h> #include <script/standard.h> @@ -100,6 +99,7 @@ UniValue importprivkey(const JSONRPCRequest& request) throw std::runtime_error( "importprivkey \"privkey\" ( \"label\" ) ( rescan )\n" "\nAdds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n" + "Hint: use importmulti to import more than one private key.\n" "\nArguments:\n" "1. \"privkey\" (string, required) The private key (see dumpprivkey)\n" "2. \"label\" (string, optional, default=\"\") An optional label\n" diff --git a/src/wallet/test/crypto_tests.cpp b/src/wallet/test/wallet_crypto_tests.cpp index d8c0cdf0f9..e04c0af1dd 100644 --- a/src/wallet/test/crypto_tests.cpp +++ b/src/wallet/test/wallet_crypto_tests.cpp @@ -10,7 +10,7 @@ #include <boost/test/unit_test.hpp> -BOOST_FIXTURE_TEST_SUITE(crypto_tests, BasicTestingSetup) +BOOST_FIXTURE_TEST_SUITE(wallet_crypto_tests, BasicTestingSetup) class TestCrypter { diff --git a/src/wallet/test/wallet_test_fixture.h b/src/wallet/test/wallet_test_fixture.h index 23575391c4..b328b3543b 100644 --- a/src/wallet/test/wallet_test_fixture.h +++ b/src/wallet/test/wallet_test_fixture.h @@ -9,6 +9,8 @@ #include <wallet/wallet.h> +#include <memory> + /** Testing setup and teardown for wallet. */ struct WalletTestingSetup: public TestingSetup { diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 808f8b8838..e93e0f1966 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -4,6 +4,7 @@ #include <wallet/wallet.h> +#include <memory> #include <set> #include <stdint.h> #include <utility> diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c9843599d6..894dfb035c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -12,7 +12,6 @@ #include <consensus/consensus.h> #include <consensus/validation.h> #include <fs.h> -#include <wallet/init.h> #include <key.h> #include <key_io.h> #include <keystore.h> @@ -878,7 +877,7 @@ bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash) bool success = true; if (!walletdb.WriteTx(wtx)) { - LogPrintf("%s: Updating walletdb tx %s failed", __func__, wtx.GetHash().ToString()); + LogPrintf("%s: Updating walletdb tx %s failed\n", __func__, wtx.GetHash().ToString()); success = false; } @@ -3076,7 +3075,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve wtxNew.fTimeReceivedIsTxTime = true; wtxNew.fFromMe = true; - LogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString()); + LogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString()); /* Continued */ { // Take key pair from key pool so it won't be used again reservekey.KeepKey(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 3ef5bfbb65..22a0ac2924 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -24,6 +24,7 @@ #include <algorithm> #include <atomic> #include <map> +#include <memory> #include <set> #include <stdexcept> #include <stdint.h> @@ -660,22 +661,22 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface { private: static std::atomic<bool> fFlushScheduled; - std::atomic<bool> fAbortRescan; - std::atomic<bool> fScanningWallet; //controlled by WalletRescanReserver + std::atomic<bool> fAbortRescan{false}; + std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver std::mutex mutexScanning; friend class WalletRescanReserver; - CWalletDB *pwalletdbEncryption; + CWalletDB *pwalletdbEncryption = nullptr; //! the current wallet version: clients below this version are not able to load the wallet - int nWalletVersion; + int nWalletVersion = FEATURE_BASE; //! the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded - int nWalletMaxVersion; + int nWalletMaxVersion = FEATURE_BASE; - int64_t nNextResend; - int64_t nLastResend; - bool fBroadcastTransactions; + int64_t nNextResend = 0; + int64_t nLastResend = 0; + bool fBroadcastTransactions = false; /** * Used to keep track of spent outpoints, and @@ -704,10 +705,10 @@ private: std::set<int64_t> setInternalKeyPool; std::set<int64_t> setExternalKeyPool; - int64_t m_max_keypool_index; + int64_t m_max_keypool_index = 0; std::map<CKeyID, int64_t> m_pool_key_to_index; - int64_t nTimeFirstKey; + int64_t nTimeFirstKey = 0; /** * Private version of AddWatchOnly method which does not accept a @@ -740,7 +741,7 @@ private: * * Protected by cs_main (see BlockUntilSyncedToCurrentChain) */ - const CBlockIndex* m_last_block_processed; + const CBlockIndex* m_last_block_processed = nullptr; public: /* @@ -779,12 +780,11 @@ public: typedef std::map<unsigned int, CMasterKey> MasterKeyMap; MasterKeyMap mapMasterKeys; - unsigned int nMasterKeyMaxID; + unsigned int nMasterKeyMaxID = 0; /** Construct wallet with specified name and database implementation. */ CWallet(std::string name, std::unique_ptr<CWalletDBWrapper> dbw) : m_name(std::move(name)), dbw(std::move(dbw)) { - SetNull(); } ~CWallet() @@ -793,24 +793,6 @@ public: pwalletdbEncryption = nullptr; } - void SetNull() - { - nWalletVersion = FEATURE_BASE; - nWalletMaxVersion = FEATURE_BASE; - nMasterKeyMaxID = 0; - pwalletdbEncryption = nullptr; - nOrderPosNext = 0; - nAccountingEntryNumber = 0; - nNextResend = 0; - nLastResend = 0; - m_max_keypool_index = 0; - nTimeFirstKey = 0; - fBroadcastTransactions = false; - nRelockTime = 0; - fAbortRescan = false; - fScanningWallet = false; - } - std::map<uint256, CWalletTx> mapWallet; std::list<CAccountingEntry> laccentries; @@ -818,8 +800,8 @@ public: typedef std::multimap<int64_t, TxPair > TxItems; TxItems wtxOrdered; - int64_t nOrderPosNext; - uint64_t nAccountingEntryNumber; + int64_t nOrderPosNext = 0; + uint64_t nAccountingEntryNumber = 0; std::map<uint256, int> mapRequestCount; std::map<CTxDestination, CAddressBookData> mapAddressBook; @@ -912,7 +894,7 @@ public: bool LoadWatchOnly(const CScript &dest); //! Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock(). - int64_t nRelockTime; + int64_t nRelockTime = 0; bool Unlock(const SecureString& strWalletPassphrase); bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); |