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-2020 The Bitcoin developers | // Copyright (c) 2018-2020 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 <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <interfaces/handler.h> | |||||
#include <outputtype.h> | #include <outputtype.h> | ||||
#include <primitives/blockhash.h> | #include <primitives/blockhash.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/strencodings.h> | #include <util/strencodings.h> | ||||
▲ Show 20 Lines • Show All 649 Lines • ▼ Show 20 Lines | |||||
// forward declarations for ScanForWalletTransactions/RescanFromTime | // forward declarations for ScanForWalletTransactions/RescanFromTime | ||||
class WalletRescanReserver; | class WalletRescanReserver; | ||||
/** | /** | ||||
* A CWallet is an extension of a keystore, which also maintains a set of | * A CWallet is an extension of a keystore, which also maintains a set of | ||||
* transactions and balances, and provides the ability to create new | * transactions and balances, and provides the ability to create new | ||||
* transactions. | * transactions. | ||||
*/ | */ | ||||
class CWallet final : public CCryptoKeyStore, public CValidationInterface { | class CWallet final : public CCryptoKeyStore, | ||||
private interfaces::Chain::Notifications { | |||||
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; | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | public: | ||||
int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0; | int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0; | ||||
uint64_t nAccountingEntryNumber = 0; | uint64_t nAccountingEntryNumber = 0; | ||||
std::map<CTxDestination, CAddressBookData> mapAddressBook; | std::map<CTxDestination, CAddressBookData> mapAddressBook; | ||||
std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet); | std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet); | ||||
/** Registered interfaces::Chain::Notifications handler. */ | |||||
std::unique_ptr<interfaces::Handler> m_chain_notifications_handler; | |||||
/** Interface for accessing chain state. */ | /** Interface for accessing chain state. */ | ||||
interfaces::Chain &chain() const { return m_chain; } | interfaces::Chain &chain() const { return m_chain; } | ||||
const CWalletTx *GetWalletTx(const TxId &txid) const; | const CWalletTx *GetWalletTx(const TxId &txid) const; | ||||
//! check whether we are allowed to upgrade (or already support) to the | //! check whether we are allowed to upgrade (or already support) to the | ||||
//! named feature | //! named feature | ||||
bool CanSupportFeature(enum WalletFeature wf) const | bool CanSupportFeature(enum WalletFeature wf) const | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | public: | ||||
DBErrors ReorderTransactions(); | DBErrors ReorderTransactions(); | ||||
void MarkDirty(); | void MarkDirty(); | ||||
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose = true); | bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose = true); | ||||
void LoadToWallet(const CWalletTx &wtxIn) | void LoadToWallet(const CWalletTx &wtxIn) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
void TransactionAddedToMempool(const CTransactionRef &tx) override; | void TransactionAddedToMempool(const CTransactionRef &tx) override; | ||||
void | void | ||||
BlockConnected(const std::shared_ptr<const CBlock> &pblock, | BlockConnected(const CBlock &block, | ||||
const CBlockIndex *pindex, | |||||
const std::vector<CTransactionRef> &vtxConflicted) override; | const std::vector<CTransactionRef> &vtxConflicted) override; | ||||
void | void BlockDisconnected(const CBlock &block) override; | ||||
BlockDisconnected(const std::shared_ptr<const CBlock> &pblock) override; | |||||
int64_t RescanFromTime(int64_t startTime, | int64_t RescanFromTime(int64_t startTime, | ||||
const WalletRescanReserver &reserver, bool update); | const WalletRescanReserver &reserver, bool update); | ||||
struct ScanResult { | struct ScanResult { | ||||
enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS; | enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS; | ||||
//! Hash and height of most recent block that was successfully scanned. | //! Hash and height of most recent block that was successfully scanned. | ||||
//! Unset if no blocks were scanned due to read errors or the chain | //! Unset if no blocks were scanned due to read errors or the chain | ||||
//! being empty. | //! being empty. | ||||
BlockHash stop_block; | BlockHash stop_block; | ||||
Optional<int> stop_height; | Optional<int> stop_height; | ||||
//! Hash of the most recent block that could not be scanned due to | //! Hash of the most recent block that could not be scanned due to | ||||
//! read errors or pruning. Will be set if status is FAILURE, unset if | //! read errors or pruning. Will be set if status is FAILURE, unset if | ||||
//! status is SUCCESS, and may or may not be set if status is | //! status is SUCCESS, and may or may not be set if status is | ||||
//! USER_ABORT. | //! USER_ABORT. | ||||
BlockHash failed_block; | BlockHash failed_block; | ||||
}; | }; | ||||
ScanResult ScanForWalletTransactions(const BlockHash &first_block, | ScanResult ScanForWalletTransactions(const BlockHash &first_block, | ||||
const BlockHash &last_block, | const BlockHash &last_block, | ||||
const WalletRescanReserver &reserver, | const WalletRescanReserver &reserver, | ||||
bool fUpdate); | bool fUpdate); | ||||
void TransactionRemovedFromMempool(const CTransactionRef &ptx) override; | void TransactionRemovedFromMempool(const CTransactionRef &ptx) override; | ||||
void ReacceptWalletTransactions(); | void ReacceptWalletTransactions(); | ||||
void ResendWalletTransactions(int64_t nBestBlockTime, | void ResendWalletTransactions(interfaces::Chain::Lock &locked_chain, | ||||
CConnman *connman) override | int64_t nBestBlockTime) override; | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | |||||
// ResendWalletTransactionsBefore may only be called if | // ResendWalletTransactionsBefore may only be called if | ||||
// fBroadcastTransactions! | // fBroadcastTransactions! | ||||
std::vector<uint256> | std::vector<uint256> | ||||
ResendWalletTransactionsBefore(interfaces::Chain::Lock &locked_chain, | ResendWalletTransactionsBefore(interfaces::Chain::Lock &locked_chain, | ||||
int64_t nTime); | int64_t nTime); | ||||
Amount GetBalance(const isminefilter &filter = ISMINE_SPENDABLE, | Amount GetBalance(const isminefilter &filter = ISMINE_SPENDABLE, | ||||
const int min_depth = 0) const; | const int min_depth = 0) const; | ||||
Amount GetUnconfirmedBalance() const; | Amount GetUnconfirmedBalance() const; | ||||
▲ Show 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | void WalletLogPrintfToBeContinued(std::string fmt, | ||||
LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(), | LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(), | ||||
parameters...); | parameters...); | ||||
}; | }; | ||||
/** | /** | ||||
* Implement lookup of key origin information through wallet key metadata. | * Implement lookup of key origin information through wallet key metadata. | ||||
*/ | */ | ||||
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override; | bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override; | ||||
friend struct WalletTestingSetup; | |||||
}; | }; | ||||
/** A key allocated from the key pool. */ | /** A key allocated from the key pool. */ | ||||
class CReserveKey final : public CReserveScript { | class CReserveKey final : public CReserveScript { | ||||
protected: | protected: | ||||
CWallet *pwallet; | CWallet *pwallet; | ||||
int64_t nIndex{-1}; | int64_t nIndex{-1}; | ||||
CPubKey vchPubKey; | CPubKey vchPubKey; | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |