Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 634 Lines • ▼ Show 20 Lines | template <typename Stream> void Unserialize(Stream &s) { | ||||
mapValue.erase("n"); | mapValue.erase("n"); | ||||
} | } | ||||
private: | private: | ||||
std::vector<char> _ssExtra; | std::vector<char> _ssExtra; | ||||
}; | }; | ||||
// forward declarations for ScanForWalletTransactions/RescanFromTime | |||||
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, public CValidationInterface { | ||||
private: | private: | ||||
static std::atomic<bool> fFlushScheduled; | static std::atomic<bool> fFlushScheduled; | ||||
std::atomic<bool> fAbortRescan; | std::atomic<bool> fAbortRescan; | ||||
// controlled by WalletRescanReserver | |||||
std::atomic<bool> fScanningWallet; | std::atomic<bool> fScanningWallet; | ||||
std::mutex mutexScanning; | |||||
friend class WalletRescanReserver; | |||||
/** | /** | ||||
* 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 20 Lines • Show All 317 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; | ||||
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, | bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, | ||||
const CBlockIndex *pIndex, int posInBlock, | const CBlockIndex *pIndex, int posInBlock, | ||||
bool fUpdate); | bool fUpdate); | ||||
int64_t RescanFromTime(int64_t startTime, bool update); | int64_t RescanFromTime(int64_t startTime, | ||||
const WalletRescanReserver &reserver, bool update); | |||||
CBlockIndex *ScanForWalletTransactions(CBlockIndex *pindexStart, | CBlockIndex *ScanForWalletTransactions(CBlockIndex *pindexStart, | ||||
CBlockIndex *pindexStop, | CBlockIndex *pindexStop, | ||||
const WalletRescanReserver &reserver, | |||||
bool fUpdate = false); | 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; | ||||
// ResendWalletTransactionsBefore may only be called if | // ResendWalletTransactionsBefore may only be called if | ||||
// fBroadcastTransactions! | // fBroadcastTransactions! | ||||
std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, | std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, | ||||
▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | for (const auto &coin : coins) { | ||||
} | } | ||||
nIn++; | nIn++; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** RAII object to check and reserve a wallet rescan */ | |||||
class WalletRescanReserver { | |||||
private: | |||||
CWalletRef m_wallet; | |||||
bool m_could_reserve; | |||||
public: | |||||
explicit WalletRescanReserver(CWalletRef w) | |||||
: m_wallet(w), m_could_reserve(false) {} | |||||
bool reserve() { | |||||
assert(!m_could_reserve); | |||||
std::lock_guard<std::mutex> lock(m_wallet->mutexScanning); | |||||
if (m_wallet->fScanningWallet) { | |||||
return false; | |||||
} | |||||
m_wallet->fScanningWallet = true; | |||||
m_could_reserve = true; | |||||
return true; | |||||
} | |||||
bool isReserved() const { | |||||
return (m_could_reserve && m_wallet->fScanningWallet); | |||||
} | |||||
~WalletRescanReserver() { | |||||
std::lock_guard<std::mutex> lock(m_wallet->mutexScanning); | |||||
if (m_could_reserve) { | |||||
m_wallet->fScanningWallet = false; | |||||
} | |||||
} | |||||
}; | |||||
#endif // BITCOIN_WALLET_WALLET_H | #endif // BITCOIN_WALLET_WALLET_H |