Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 666 Lines • ▼ Show 20 Lines | |||||
private: | private: | ||||
static std::atomic<bool> fFlushScheduled; | static std::atomic<bool> fFlushScheduled; | ||||
std::atomic<bool> fAbortRescan{false}; | std::atomic<bool> fAbortRescan{false}; | ||||
// controlled by WalletRescanReserver | // controlled by WalletRescanReserver | ||||
std::atomic<bool> fScanningWallet{false}; | std::atomic<bool> fScanningWallet{false}; | ||||
std::mutex mutexScanning; | std::mutex mutexScanning; | ||||
friend class WalletRescanReserver; | friend class WalletRescanReserver; | ||||
CWalletDB *pwalletdbEncryption = nullptr; | WalletBatch *encrypted_batch = nullptr; | ||||
//! the current wallet version: clients below this version are not able to | //! the current wallet version: clients below this version are not able to | ||||
//! load the wallet | //! load the wallet | ||||
int nWalletVersion = FEATURE_BASE; | int nWalletVersion = FEATURE_BASE; | ||||
//! the maximum wallet format version: memory-only variable that specifies | //! the maximum wallet format version: memory-only variable that specifies | ||||
//! to what version this wallet may be upgraded | //! to what version this wallet may be upgraded | ||||
int nWalletMaxVersion = FEATURE_BASE; | int nWalletMaxVersion = FEATURE_BASE; | ||||
Show All 27 Lines | private: | ||||
void SyncTransaction(const CTransactionRef &tx, | void SyncTransaction(const CTransactionRef &tx, | ||||
const CBlockIndex *pindex = nullptr, | const CBlockIndex *pindex = nullptr, | ||||
int posInBlock = 0); | int posInBlock = 0); | ||||
/* the HD chain data model (external chain counters) */ | /* the HD chain data model (external chain counters) */ | ||||
CHDChain hdChain; | CHDChain hdChain; | ||||
/* HD derive new child key (on internal or external chain) */ | /* HD derive new child key (on internal or external chain) */ | ||||
void DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata &metadata, | void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, | ||||
CKey &secret, bool internal = false); | CKey &secret, bool internal = false); | ||||
std::set<int64_t> setInternalKeyPool; | std::set<int64_t> setInternalKeyPool; | ||||
std::set<int64_t> setExternalKeyPool; | std::set<int64_t> setExternalKeyPool; | ||||
int64_t m_max_keypool_index = 0; | int64_t m_max_keypool_index = 0; | ||||
std::map<CKeyID, int64_t> m_pool_key_to_index; | std::map<CKeyID, int64_t> m_pool_key_to_index; | ||||
int64_t nTimeFirstKey = 0; | int64_t nTimeFirstKey = 0; | ||||
Show All 12 Lines | private: | ||||
/** | /** | ||||
* Wallet filename from wallet=<path> command line or config option. | * Wallet filename from wallet=<path> command line or config option. | ||||
* Used in debug logs and to send RPCs to the right wallet instance when | * Used in debug logs and to send RPCs to the right wallet instance when | ||||
* more than one wallet is loaded. | * more than one wallet is loaded. | ||||
*/ | */ | ||||
std::string m_name; | std::string m_name; | ||||
/** Internal database handle. */ | /** Internal database handle. */ | ||||
std::unique_ptr<CWalletDBWrapper> dbw; | std::unique_ptr<WalletDatabase> database; | ||||
/** | /** | ||||
* 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 | ||||
* live BlockConnected callbacks. | * live BlockConnected callbacks. | ||||
Show All 9 Lines | public: | ||||
* This lock protects all the fields added by CWallet. | * This lock protects all the fields added by CWallet. | ||||
*/ | */ | ||||
mutable CCriticalSection cs_wallet; | mutable CCriticalSection cs_wallet; | ||||
/** | /** | ||||
* 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; } | WalletDatabase &GetDBHandle() { return *database; } | ||||
/** | /** | ||||
* Select a set of coins such that nValueRet >= nTargetValue and at least | * Select a set of coins such that nValueRet >= nTargetValue and at least | ||||
* all coins from coinControl are selected; Never select unconfirmed coins | * all coins from coinControl are selected; Never select unconfirmed coins | ||||
* if they are not ours. | * if they are not ours. | ||||
*/ | */ | ||||
bool SelectCoins(const std::vector<COutput> &vAvailableCoins, | bool SelectCoins(const std::vector<COutput> &vAvailableCoins, | ||||
const Amount nTargetValue, | const Amount nTargetValue, | ||||
Show All 16 Lines | public: | ||||
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 = 0; | unsigned int nMasterKeyMaxID = 0; | ||||
/** Construct wallet with specified name and database implementation. */ | /** Construct wallet with specified name and database implementation. */ | ||||
CWallet(const CChainParams &chainParamsIn, std::string name, | CWallet(const CChainParams &chainParamsIn, std::string name, | ||||
std::unique_ptr<CWalletDBWrapper> dbwIn) | std::unique_ptr<WalletDatabase> databaseIn) | ||||
: m_name(std::move(name)), dbw(std::move(dbwIn)), | : m_name(std::move(name)), database(std::move(databaseIn)), | ||||
chainParams(chainParamsIn) {} | chainParams(chainParamsIn) {} | ||||
~CWallet() { | ~CWallet() { | ||||
delete pwalletdbEncryption; | delete encrypted_batch; | ||||
pwalletdbEncryption = nullptr; | encrypted_batch = nullptr; | ||||
} | } | ||||
std::map<TxId, CWalletTx> mapWallet; | std::map<TxId, CWalletTx> mapWallet; | ||||
std::list<CAccountingEntry> laccentries; | std::list<CAccountingEntry> laccentries; | ||||
typedef std::pair<CWalletTx *, CAccountingEntry *> TxPair; | typedef std::pair<CWalletTx *, CAccountingEntry *> TxPair; | ||||
typedef std::multimap<int64_t, TxPair> TxItems; | typedef std::multimap<int64_t, TxPair> TxItems; | ||||
TxItems wtxOrdered; | TxItems wtxOrdered; | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | public: | ||||
void AbortRescan() { fAbortRescan = true; } | void AbortRescan() { fAbortRescan = true; } | ||||
bool IsAbortingRescan() { return fAbortRescan; } | bool IsAbortingRescan() { return fAbortRescan; } | ||||
bool IsScanning() { return fScanningWallet; } | bool IsScanning() { return fScanningWallet; } | ||||
/** | /** | ||||
* keystore implementation | * keystore implementation | ||||
* Generate a new key | * Generate a new key | ||||
*/ | */ | ||||
CPubKey GenerateNewKey(CWalletDB &walletdb, bool internal = false); | CPubKey GenerateNewKey(WalletBatch &batch, bool internal = false); | ||||
//! Adds a key to the store, and saves it to disk. | //! Adds a key to the store, and saves it to disk. | ||||
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override; | bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override; | ||||
bool AddKeyPubKeyWithDB(CWalletDB &walletdb, const CKey &key, | bool AddKeyPubKeyWithDB(WalletBatch &batch, const CKey &key, | ||||
const CPubKey &pubkey); | const CPubKey &pubkey); | ||||
//! Adds a key to the store, without saving it to disk (used by LoadWallet) | //! Adds a key to the store, without saving it to disk (used by LoadWallet) | ||||
bool LoadKey(const CKey &key, const CPubKey &pubkey) { | bool LoadKey(const CKey &key, const CPubKey &pubkey) { | ||||
return CCryptoKeyStore::AddKeyPubKey(key, pubkey); | return CCryptoKeyStore::AddKeyPubKey(key, pubkey); | ||||
} | } | ||||
//! Load metadata (used by LoadWallet) | //! Load metadata (used by LoadWallet) | ||||
bool LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata); | bool LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata); | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public: | ||||
void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const; | void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const; | ||||
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const; | unsigned int ComputeTimeSmart(const CWalletTx &wtx) const; | ||||
/** | /** | ||||
* Increment the next transaction order id | * Increment the next transaction order id | ||||
* @return next transaction order id | * @return next transaction order id | ||||
*/ | */ | ||||
int64_t IncOrderPosNext(CWalletDB *pwalletdb = nullptr); | int64_t IncOrderPosNext(WalletBatch *batch = nullptr); | ||||
DBErrors ReorderTransactions(); | DBErrors ReorderTransactions(); | ||||
bool AccountMove(std::string strFrom, std::string strTo, | bool AccountMove(std::string strFrom, std::string strTo, | ||||
const Amount nAmount, std::string strComment = ""); | const Amount nAmount, std::string strComment = ""); | ||||
bool GetLabelDestination(CTxDestination &dest, const std::string &label, | bool GetLabelDestination(CTxDestination &dest, const std::string &label, | ||||
bool bForceNew = false); | bool bForceNew = false); | ||||
void MarkDirty(); | void MarkDirty(); | ||||
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose = true); | bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose = true); | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public: | ||||
* selected by SelectCoins(); Also create the change output, when needed | * selected by SelectCoins(); Also create the change output, when needed | ||||
* @note passing nChangePosInOut as -1 will result in setting a random | * @note passing nChangePosInOut as -1 will result in setting a random | ||||
* position | * position | ||||
*/ | */ | ||||
bool CreateTransaction(const std::vector<CRecipient> &vecSend, | bool CreateTransaction(const std::vector<CRecipient> &vecSend, | ||||
CTransactionRef &tx, CReserveKey &reservekey, | CTransactionRef &tx, CReserveKey &reservekey, | ||||
Amount &nFeeRet, int &nChangePosInOut, | Amount &nFeeRet, int &nChangePosInOut, | ||||
std::string &strFailReason, | std::string &strFailReason, | ||||
const CCoinControl &coinControl, bool sign = true); | const CCoinControl &coin_control, bool sign = true); | ||||
bool CommitTransaction( | bool CommitTransaction( | ||||
CTransactionRef tx, mapValue_t mapValue, | CTransactionRef tx, mapValue_t mapValue, | ||||
std::vector<std::pair<std::string, std::string>> orderForm, | std::vector<std::pair<std::string, std::string>> orderForm, | ||||
std::string fromAccount, CReserveKey &reservekey, CConnman *connman, | std::string fromAccount, CReserveKey &reservekey, CConnman *connman, | ||||
CValidationState &state); | CValidationState &state); | ||||
void ListAccountCreditDebit(const std::string &strAccount, | void ListAccountCreditDebit(const std::string &strAccount, | ||||
std::list<CAccountingEntry> &entries); | std::list<CAccountingEntry> &entries); | ||||
bool AddAccountingEntry(const CAccountingEntry &); | bool AddAccountingEntry(const CAccountingEntry &); | ||||
bool AddAccountingEntry(const CAccountingEntry &, CWalletDB *pwalletdb); | bool AddAccountingEntry(const CAccountingEntry &, WalletBatch *batch); | ||||
bool DummySignTx(CMutableTransaction &txNew, | bool DummySignTx(CMutableTransaction &txNew, | ||||
const std::set<CTxOut> &txouts) const { | const std::set<CTxOut> &txouts) const { | ||||
std::vector<CTxOut> v_txouts(txouts.size()); | std::vector<CTxOut> v_txouts(txouts.size()); | ||||
std::copy(txouts.begin(), txouts.end(), v_txouts.begin()); | std::copy(txouts.begin(), txouts.end(), v_txouts.begin()); | ||||
return DummySignTx(txNew, v_txouts); | return DummySignTx(txNew, v_txouts); | ||||
} | } | ||||
bool DummySignTx(CMutableTransaction &txNew, | bool DummySignTx(CMutableTransaction &txNew, | ||||
const std::vector<CTxOut> &txouts) const; | const std::vector<CTxOut> &txouts) const; | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | public: | ||||
unsigned int GetKeyPoolSize() { | unsigned int GetKeyPoolSize() { | ||||
// set{Ex,In}ternalKeyPool | // set{Ex,In}ternalKeyPool | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
return setInternalKeyPool.size() + setExternalKeyPool.size(); | return setInternalKeyPool.size() + setExternalKeyPool.size(); | ||||
} | } | ||||
//! signify that a particular wallet feature is now used. this may change | //! signify that a particular wallet feature is now used. this may change | ||||
//! nWalletVersion and nWalletMaxVersion if those are lower | //! nWalletVersion and nWalletMaxVersion if those are lower | ||||
bool SetMinVersion(enum WalletFeature, CWalletDB *pwalletdbIn = nullptr, | bool SetMinVersion(enum WalletFeature, WalletBatch *batch_in = nullptr, | ||||
bool fExplicit = false); | bool fExplicit = false); | ||||
//! change which version we're allowed to upgrade to (note that this does | //! change which version we're allowed to upgrade to (note that this does | ||||
//! not immediately imply upgrading to that format) | //! not immediately imply upgrading to that format) | ||||
bool SetMaxVersion(int nVersion); | bool SetMaxVersion(int nVersion); | ||||
//! get the current wallet format (the oldest client version guaranteed to | //! get the current wallet format (the oldest client version guaranteed to | ||||
//! understand this wallet) | //! understand this wallet) | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |