Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2018 The Bitcoin developers | // Copyright (c) 2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_WALLET_WALLET_H | #ifndef BITCOIN_WALLET_WALLET_H | ||||
#define BITCOIN_WALLET_WALLET_H | #define BITCOIN_WALLET_WALLET_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <script/ismine.h> | #include <script/ismine.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util.h> | |||||
#include <utilstrencodings.h> | #include <utilstrencodings.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <wallet/crypter.h> | #include <wallet/crypter.h> | ||||
#include <wallet/rpcwallet.h> | #include <wallet/rpcwallet.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <atomic> | #include <atomic> | ||||
▲ Show 20 Lines • Show All 700 Lines • ▼ Show 20 Lines | private: | ||||
* key did not previously have a timestamp associated with it. Because this | * key did not previously have a timestamp associated with it. Because this | ||||
* is an inherited virtual method, it is accessible despite being marked | * is an inherited virtual method, it is accessible despite being marked | ||||
* private, but it is marked private anyway to encourage use of the other | * private, but it is marked private anyway to encourage use of the other | ||||
* AddWatchOnly which accepts a timestamp and sets nTimeFirstKey more | * AddWatchOnly which accepts a timestamp and sets nTimeFirstKey more | ||||
* intelligently for more efficient rescans. | * intelligently for more efficient rescans. | ||||
*/ | */ | ||||
bool AddWatchOnly(const CScript &dest) override; | bool AddWatchOnly(const CScript &dest) override; | ||||
/** | |||||
* Wallet filename from wallet=<path> command line or config option. | |||||
* Used in debug logs and to send RPCs to the right wallet instance when | |||||
* more than one wallet is loaded. | |||||
*/ | |||||
std::string m_name; | |||||
/** Internal database handle. */ | |||||
std::unique_ptr<CWalletDBWrapper> dbw; | std::unique_ptr<CWalletDBWrapper> dbw; | ||||
/** | /** | ||||
* The following is used to keep track of how far behind the wallet is | * The following is used to keep track of how far behind the wallet is | ||||
* from the chain sync, and to allow clients to block on us being caught up. | * from the chain sync, and to allow clients to block on us being caught up. | ||||
* | * | ||||
* Note that this is *not* how far we've processed, we may need some rescan | * Note that this is *not* how far we've processed, we may need some rescan | ||||
* to have seen all transactions in the chain, but is only used to track | * to have seen all transactions in the chain, but is only used to track | ||||
Show All 15 Lines | public: | ||||
* Get database handle used by this wallet. Ideally this function would not | * Get database handle used by this wallet. Ideally this function would not | ||||
* be necessary. | * be necessary. | ||||
*/ | */ | ||||
CWalletDBWrapper &GetDBHandle() { return *dbw; } | CWalletDBWrapper &GetDBHandle() { return *dbw; } | ||||
/** | /** | ||||
* Get a name for this wallet for logging/debugging purposes. | * Get a name for this wallet for logging/debugging purposes. | ||||
*/ | */ | ||||
std::string GetName() const { | std::string GetName() const { return m_name; } | ||||
if (dbw) { | |||||
return dbw->GetName(); | |||||
} else { | |||||
return "dummy"; | |||||
} | |||||
} | |||||
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool); | void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool); | ||||
// Map from Key ID to key metadata. | // Map from Key ID to key metadata. | ||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata; | std::map<CKeyID, CKeyMetadata> mapKeyMetadata; | ||||
// Map from Script ID to key metadata (for watch-only keys). | // Map from Script ID to key metadata (for watch-only keys). | ||||
std::map<CScriptID, CKeyMetadata> m_script_metadata; | std::map<CScriptID, CKeyMetadata> m_script_metadata; | ||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | ||||
MasterKeyMap mapMasterKeys; | MasterKeyMap mapMasterKeys; | ||||
unsigned int nMasterKeyMaxID; | unsigned int nMasterKeyMaxID; | ||||
// Create wallet with dummy database handle | /** Construct wallet with specified name and database implementation. */ | ||||
explicit CWallet(const CChainParams &chainParamsIn) | CWallet(const CChainParams &chainParamsIn, std::string name, | ||||
: dbw(new CWalletDBWrapper()), chainParams(chainParamsIn) { | |||||
SetNull(); | |||||
} | |||||
// Create wallet with passed-in database handle | |||||
CWallet(const CChainParams &chainParamsIn, | |||||
std::unique_ptr<CWalletDBWrapper> dbw_in) | std::unique_ptr<CWalletDBWrapper> dbw_in) | ||||
: dbw(std::move(dbw_in)), chainParams(chainParamsIn) { | : m_name(std::move(name)), dbw(std::move(dbw_in)), | ||||
chainParams(chainParamsIn) { | |||||
SetNull(); | SetNull(); | ||||
} | } | ||||
~CWallet() { | ~CWallet() { | ||||
delete pwalletdbEncryption; | delete pwalletdbEncryption; | ||||
pwalletdbEncryption = nullptr; | pwalletdbEncryption = nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
bool AbandonTransaction(const TxId &txid); | bool AbandonTransaction(const TxId &txid); | ||||
/** | /** | ||||
* Initializes the wallet, returns a new CWallet instance or a null pointer | * Initializes the wallet, returns a new CWallet instance or a null pointer | ||||
* in case of an error. | * in case of an error. | ||||
*/ | */ | ||||
static CWallet *CreateWalletFromFile(const CChainParams &chainParams, | static CWallet *CreateWalletFromFile(const CChainParams &chainParams, | ||||
const std::string walletFile); | const std::string &name, | ||||
const fs::path &path); | |||||
/** | /** | ||||
* Wallet post-init setup | * Wallet post-init setup | ||||
* Gives the wallet a chance to register repetitive tasks and complete | * Gives the wallet a chance to register repetitive tasks and complete | ||||
* post-init tasks | * post-init tasks | ||||
*/ | */ | ||||
void postInitProcess(CScheduler &scheduler); | void postInitProcess(CScheduler &scheduler); | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |