Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; | static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; | ||||
//! Default for -walletrejectlongchains | //! Default for -walletrejectlongchains | ||||
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false; | static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false; | ||||
//! Default for -avoidpartialspends | //! Default for -avoidpartialspends | ||||
static const bool DEFAULT_AVOIDPARTIALSPENDS = false; | static const bool DEFAULT_AVOIDPARTIALSPENDS = false; | ||||
static const bool DEFAULT_WALLETBROADCAST = true; | static const bool DEFAULT_WALLETBROADCAST = true; | ||||
static const bool DEFAULT_DISABLE_WALLET = false; | static const bool DEFAULT_DISABLE_WALLET = false; | ||||
class CBlockIndex; | |||||
class CChainParams; | class CChainParams; | ||||
class CCoinControl; | class CCoinControl; | ||||
class COutput; | class COutput; | ||||
class CReserveKey; | class CReserveKey; | ||||
class CScript; | class CScript; | ||||
class CTxMemPool; | class CTxMemPool; | ||||
class CWalletTx; | class CWalletTx; | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
// For compatibility with older versions. | // For compatibility with older versions. | ||||
std::vector<uint256> vMerkleBranch; | std::vector<uint256> vMerkleBranch; | ||||
READWRITE(tx); | READWRITE(tx); | ||||
READWRITE(hashBlock); | READWRITE(hashBlock); | ||||
READWRITE(vMerkleBranch); | READWRITE(vMerkleBranch); | ||||
READWRITE(nIndex); | READWRITE(nIndex); | ||||
} | } | ||||
void SetMerkleBranch(const CBlockIndex *pIndex, int posInBlock); | void SetMerkleBranch(const BlockHash &block_hash, int posInBlock); | ||||
/** | /** | ||||
* Return depth of transaction in blockchain: | * Return depth of transaction in blockchain: | ||||
* <0 : conflicts with a transaction this deep in the blockchain | * <0 : conflicts with a transaction this deep in the blockchain | ||||
* 0 : in memory pool, waiting to be included in a block | * 0 : in memory pool, waiting to be included in a block | ||||
* >=1 : this many blocks deep in the main chain | * >=1 : this many blocks deep in the main chain | ||||
*/ | */ | ||||
int GetDepthInMainChain(interfaces::Chain::Lock &locked_chain) const; | int GetDepthInMainChain(interfaces::Chain::Lock &locked_chain) const; | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | private: | ||||
* TODO: One exception to this is that the abandoned state is cleared under | * TODO: One exception to this is that the abandoned state is cleared under | ||||
* the assumption that any further notification of a transaction that was | * the assumption that any further notification of a transaction that was | ||||
* considered abandoned is an indication that it is not safe to be | * considered abandoned is an indication that it is not safe to be | ||||
* considered abandoned. Abandoned state should probably be more carefully | * considered abandoned. Abandoned state should probably be more carefully | ||||
* tracked via different posInBlock signals or by checking mempool presence | * tracked via different posInBlock signals or by checking mempool presence | ||||
* when necessary. | * when necessary. | ||||
*/ | */ | ||||
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, | bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, | ||||
const CBlockIndex *pIndex, int posInBlock, | const BlockHash &block_hash, int posInBlock, | ||||
bool fUpdate) | bool fUpdate) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
/** | /** | ||||
* Mark a transaction (and its in-wallet descendants) as conflicting with a | * Mark a transaction (and its in-wallet descendants) as conflicting with a | ||||
* particular block. | * particular block. | ||||
*/ | */ | ||||
void MarkConflicted(const BlockHash &hashBlock, const TxId &txid); | void MarkConflicted(const BlockHash &hashBlock, const TxId &txid); | ||||
/** | /** | ||||
* Mark a transaction's inputs dirty, thus forcing the outputs to be | * Mark a transaction's inputs dirty, thus forcing the outputs to be | ||||
* recomputed | * recomputed | ||||
*/ | */ | ||||
void MarkInputsDirty(const CTransactionRef &tx) | void MarkInputsDirty(const CTransactionRef &tx) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) | void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
/** | /** | ||||
* Used by | * Used by | ||||
* TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions. | * TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions. | ||||
* Should be called with pindexBlock and posInBlock if this is for a | * Should be called with non-zero block_hash and posInBlock if this is for a | ||||
* transaction that is included in a block. | * transaction that is included in a block. | ||||
*/ | */ | ||||
void SyncTransaction(const CTransactionRef &tx, | void SyncTransaction(const CTransactionRef &tx, const BlockHash &block_hash, | ||||
const CBlockIndex *pindex = nullptr, | |||||
int posInBlock = 0, bool update_tx = true) | int posInBlock = 0, bool update_tx = true) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
/* 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(WalletBatch &batch, CKeyMetadata &metadata, | void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, | ||||
Show All 34 Lines | private: | ||||
/** | /** | ||||
* 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. | ||||
* | |||||
* Protected by cs_main (see BlockUntilSyncedToCurrentChain) | |||||
*/ | */ | ||||
const CBlockIndex *m_last_block_processed = nullptr; | BlockHash m_last_block_processed; | ||||
public: | public: | ||||
const CChainParams &chainParams; | const CChainParams &chainParams; | ||||
/* | /* | ||||
* Main wallet lock. | * Main wallet lock. | ||||
* 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; | ||||
▲ Show 20 Lines • Show All 240 Lines • ▼ Show 20 Lines | public: | ||||
BlockConnected(const std::shared_ptr<const CBlock> &pblock, | BlockConnected(const std::shared_ptr<const CBlock> &pblock, | ||||
const CBlockIndex *pindex, | const CBlockIndex *pindex, | ||||
const std::vector<CTransactionRef> &vtxConflicted) override; | const std::vector<CTransactionRef> &vtxConflicted) override; | ||||
void | void | ||||
BlockDisconnected(const std::shared_ptr<const CBlock> &pblock) 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); | ||||
enum class ScanResult { SUCCESS, FAILURE, USER_ABORT }; | struct ScanResult { | ||||
ScanResult ScanForWalletTransactions(const CBlockIndex *const pindexStart, | enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS; | ||||
const CBlockIndex *const pindexStop, | |||||
//! Hash and height of most recent block that was successfully scanned. | |||||
//! Unset if no blocks were scanned due to read errors or the chain | |||||
//! being empty. | |||||
BlockHash stop_block; | |||||
Optional<int> stop_height; | |||||
//! 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 | |||||
//! status is SUCCESS, and may or may not be set if status is | |||||
//! USER_ABORT. | |||||
BlockHash failed_block; | |||||
}; | |||||
ScanResult ScanForWalletTransactions(const BlockHash &first_block, | |||||
const BlockHash &last_block, | |||||
const WalletRescanReserver &reserver, | const WalletRescanReserver &reserver, | ||||
const CBlockIndex *&failed_block, | bool fUpdate); | ||||
const CBlockIndex *&stop_block, | |||||
bool fUpdate = false); | |||||
void TransactionRemovedFromMempool(const CTransactionRef &ptx) override; | void TransactionRemovedFromMempool(const CTransactionRef &ptx) override; | ||||
void ReacceptWalletTransactions(); | void ReacceptWalletTransactions(); | ||||
void ResendWalletTransactions(int64_t nBestBlockTime, | void ResendWalletTransactions(int64_t nBestBlockTime, | ||||
CConnman *connman) override | CConnman *connman) override | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | 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> | ||||
▲ Show 20 Lines • Show All 427 Lines • Show Last 20 Lines |