Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | public: | ||||
* Pass this transaction to the mempool. Fails if absolute fee exceeds | * Pass this transaction to the mempool. Fails if absolute fee exceeds | ||||
* absurd fee. | * absurd fee. | ||||
*/ | */ | ||||
bool AcceptToMemoryPool(const Amount nAbsurdFee, CValidationState &state); | bool AcceptToMemoryPool(const Amount nAbsurdFee, CValidationState &state); | ||||
std::set<TxId> GetConflicts() const; | std::set<TxId> GetConflicts() const; | ||||
}; | }; | ||||
class CInputCoin { | |||||
public: | |||||
CInputCoin(const CWalletTx *walletTx, unsigned int i) : wtx(walletTx) { | |||||
if (!walletTx) { | |||||
throw std::invalid_argument("walletTx should not be null"); | |||||
} | |||||
if (i >= walletTx->tx->vout.size()) { | |||||
throw std::out_of_range("The output index is out of range"); | |||||
} | |||||
outpoint = COutPoint(walletTx->GetId(), i); | |||||
txout = walletTx->tx->vout[i]; | |||||
} | |||||
COutPoint outpoint; | |||||
CTxOut txout; | |||||
const CWalletTx *wtx; | |||||
bool operator<(const CInputCoin &rhs) const { | |||||
return outpoint < rhs.outpoint; | |||||
} | |||||
bool operator!=(const CInputCoin &rhs) const { | |||||
return outpoint != rhs.outpoint; | |||||
} | |||||
bool operator==(const CInputCoin &rhs) const { | |||||
return outpoint == rhs.outpoint; | |||||
} | |||||
}; | |||||
class COutput { | class COutput { | ||||
public: | public: | ||||
const CWalletTx *tx; | const CWalletTx *tx; | ||||
int i; | int i; | ||||
int nDepth; | int nDepth; | ||||
/** Whether we have the private keys to spend this output */ | /** Whether we have the private keys to spend this output */ | ||||
bool fSpendable; | bool fSpendable; | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | private: | ||||
std::atomic<bool> fAbortRescan; | std::atomic<bool> fAbortRescan; | ||||
std::atomic<bool> fScanningWallet; | std::atomic<bool> fScanningWallet; | ||||
/** | /** | ||||
* 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( | bool SelectCoins(const std::vector<COutput> &vAvailableCoins, | ||||
const std::vector<COutput> &vAvailableCoins, const Amount nTargetValue, | const Amount nTargetValue, | ||||
std::set<std::pair<const CWalletTx *, unsigned int>> &setCoinsRet, | std::set<CInputCoin> &setCoinsRet, Amount &nValueRet, | ||||
Amount &nValueRet, const CCoinControl *coinControl = nullptr) const; | const CCoinControl *coinControl = nullptr) const; | ||||
CWalletDB *pwalletdbEncryption; | CWalletDB *pwalletdbEncryption; | ||||
//! 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; | int nWalletVersion; | ||||
//! the maximum wallet format version: memory-only variable that specifies | //! the maximum wallet format version: memory-only variable that specifies | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | void AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe = true, | ||||
const int &nMaxDepth = 9999999) const; | const int &nMaxDepth = 9999999) const; | ||||
/** | /** | ||||
* Shuffle and select coins until nTargetValue is reached while avoiding | * Shuffle and select coins until nTargetValue is reached while avoiding | ||||
* small change; This method is stochastic for some inputs and upon | * small change; This method is stochastic for some inputs and upon | ||||
* completion the coin set and corresponding actual target value is | * completion the coin set and corresponding actual target value is | ||||
* assembled. | * assembled. | ||||
*/ | */ | ||||
bool SelectCoinsMinConf( | bool SelectCoinsMinConf(const Amount nTargetValue, int nConfMine, | ||||
const Amount nTargetValue, int nConfMine, int nConfTheirs, | int nConfTheirs, uint64_t nMaxAncestors, | ||||
uint64_t nMaxAncestors, std::vector<COutput> vCoins, | std::vector<COutput> vCoins, | ||||
std::set<std::pair<const CWalletTx *, unsigned int>> &setCoinsRet, | std::set<CInputCoin> &setCoinsRet, | ||||
Amount &nValueRet) const; | Amount &nValueRet) const; | ||||
bool IsSpent(const TxId &txid, uint32_t n) const; | bool IsSpent(const TxId &txid, uint32_t n) const; | ||||
bool IsLockedCoin(const TxId &txid, uint32_t n) const; | bool IsLockedCoin(const TxId &txid, uint32_t n) const; | ||||
void LockCoin(const COutPoint &output); | void LockCoin(const COutPoint &output); | ||||
void UnlockCoin(const COutPoint &output); | void UnlockCoin(const COutPoint &output); | ||||
void UnlockAllCoins(); | void UnlockAllCoins(); | ||||
void ListLockedCoins(std::vector<COutPoint> &vOutpts); | void ListLockedCoins(std::vector<COutPoint> &vOutpts); | ||||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | |||||
// ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable so | // ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable so | ||||
// that each entry corresponds to each vIn, in order. | // that each entry corresponds to each vIn, in order. | ||||
template <typename ContainerType> | template <typename ContainerType> | ||||
bool CWallet::DummySignTx(CMutableTransaction &txNew, | bool CWallet::DummySignTx(CMutableTransaction &txNew, | ||||
const ContainerType &coins) { | const ContainerType &coins) { | ||||
// Fill in dummy signatures for fee calculation. | // Fill in dummy signatures for fee calculation. | ||||
int nIn = 0; | int nIn = 0; | ||||
for (const auto &coin : coins) { | for (const auto &coin : coins) { | ||||
const CScript &scriptPubKey = | const CScript &scriptPubKey = coin.txout.scriptPubKey; | ||||
coin.first->tx->vout[coin.second].scriptPubKey; | |||||
SignatureData sigdata; | SignatureData sigdata; | ||||
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, | if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, | ||||
sigdata)) { | sigdata)) { | ||||
return false; | return false; | ||||
} else { | } else { | ||||
UpdateTransaction(txNew, nIn, sigdata); | UpdateTransaction(txNew, nIn, sigdata); | ||||
} | } | ||||
nIn++; | nIn++; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
#endif // BITCOIN_WALLET_WALLET_H | #endif // BITCOIN_WALLET_WALLET_H |