Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | public: | ||||
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); } | bool isAbandoned() const { return (hashBlock == ABANDON_HASH); } | ||||
void setAbandoned() { hashBlock = ABANDON_HASH; } | void setAbandoned() { hashBlock = ABANDON_HASH; } | ||||
TxId GetId() const { return tx->GetId(); } | TxId GetId() const { return tx->GetId(); } | ||||
bool IsCoinBase() const { return tx->IsCoinBase(); } | bool IsCoinBase() const { return tx->IsCoinBase(); } | ||||
bool IsImmatureCoinBase() const; | bool IsImmatureCoinBase() const; | ||||
}; | }; | ||||
// Get the marginal bytes of spending the specified output | |||||
int CalculateMaximumSignedInputSize(const CTxOut &txout, | |||||
const CWallet *pwallet); | |||||
/** | /** | ||||
* A transaction with a bunch of additional info that only the owner cares | * A transaction with a bunch of additional info that only the owner cares | ||||
* about. It includes any unrecorded transactions needed to link it back to the | * about. It includes any unrecorded transactions needed to link it back to the | ||||
* block chain. | * block chain. | ||||
*/ | */ | ||||
class CWalletTx : public CMerkleTx { | class CWalletTx : public CMerkleTx { | ||||
private: | private: | ||||
const CWallet *pwallet; | const CWallet *pwallet; | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | public: | ||||
Amount GetDebit(const isminefilter &filter) const; | Amount GetDebit(const isminefilter &filter) const; | ||||
Amount GetCredit(const isminefilter &filter) const; | Amount GetCredit(const isminefilter &filter) const; | ||||
Amount GetImmatureCredit(bool fUseCache = true) const; | Amount GetImmatureCredit(bool fUseCache = true) const; | ||||
Amount GetAvailableCredit(bool fUseCache = true) const; | Amount GetAvailableCredit(bool fUseCache = true) const; | ||||
Amount GetImmatureWatchOnlyCredit(const bool fUseCache = true) const; | Amount GetImmatureWatchOnlyCredit(const bool fUseCache = true) const; | ||||
Amount GetAvailableWatchOnlyCredit(const bool fUseCache = true) const; | Amount GetAvailableWatchOnlyCredit(const bool fUseCache = true) const; | ||||
Amount GetChange() const; | Amount GetChange() const; | ||||
// Get the marginal bytes if spending the specified output from this | |||||
// transaction | |||||
int GetSpendSize(unsigned int out) const { | |||||
return CalculateMaximumSignedInputSize(tx->vout[out], pwallet); | |||||
} | |||||
void GetAmounts(std::list<COutputEntry> &listReceived, | void GetAmounts(std::list<COutputEntry> &listReceived, | ||||
std::list<COutputEntry> &listSent, Amount &nFee, | std::list<COutputEntry> &listSent, Amount &nFee, | ||||
std::string &strSentAccount, | std::string &strSentAccount, | ||||
const isminefilter &filter) const; | const isminefilter &filter) const; | ||||
bool IsFromMe(const isminefilter &filter) const { | bool IsFromMe(const isminefilter &filter) const { | ||||
return GetDebit(filter) > Amount::zero(); | return GetDebit(filter) > Amount::zero(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
class COutput { | class COutput { | ||||
public: | public: | ||||
const CWalletTx *tx; | const CWalletTx *tx; | ||||
int i; | int i; | ||||
int nDepth; | int nDepth; | ||||
/** | |||||
* Pre-computed estimated size of this output as a fully-signed input in a | |||||
* transaction. Can be -1 if it could not be calculated. | |||||
*/ | |||||
int nInputBytes; | |||||
/** Whether we have the private keys to spend this output */ | /** Whether we have the private keys to spend this output */ | ||||
bool fSpendable; | bool fSpendable; | ||||
/** Whether we know how to spend this output, ignoring the lack of keys */ | /** Whether we know how to spend this output, ignoring the lack of keys */ | ||||
bool fSolvable; | bool fSolvable; | ||||
/** | /** | ||||
* Whether this output is considered safe to spend. Unconfirmed transactions | * Whether this output is considered safe to spend. Unconfirmed transactions | ||||
* from outside keys are considered unsafe and will not be used to fund new | * from outside keys are considered unsafe and will not be used to fund new | ||||
* spending transactions. | * spending transactions. | ||||
*/ | */ | ||||
bool fSafe; | bool fSafe; | ||||
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, | COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, | ||||
bool fSolvableIn, bool fSafeIn) { | bool fSolvableIn, bool fSafeIn) { | ||||
tx = txIn; | tx = txIn; | ||||
i = iIn; | i = iIn; | ||||
nDepth = nDepthIn; | nDepth = nDepthIn; | ||||
fSpendable = fSpendableIn; | fSpendable = fSpendableIn; | ||||
fSolvable = fSolvableIn; | fSolvable = fSolvableIn; | ||||
fSafe = fSafeIn; | fSafe = fSafeIn; | ||||
nInputBytes = -1; | |||||
// If known and signable by the given wallet, compute nInputBytes | |||||
// Failure will keep this value -1 | |||||
if (fSpendable && tx) { | |||||
nInputBytes = tx->GetSpendSize(i); | |||||
} | |||||
} | } | ||||
std::string ToString() const; | std::string ToString() const; | ||||
}; | }; | ||||
/** Private key that includes an expiration date in case it never gets used. */ | /** Private key that includes an expiration date in case it never gets used. */ | ||||
class CWalletKey { | class CWalletKey { | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | bool CommitTransaction( | ||||
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 &, CWalletDB *pwalletdb); | ||||
template <typename ContainerType> | |||||
bool DummySignTx(CMutableTransaction &txNew, | bool DummySignTx(CMutableTransaction &txNew, | ||||
const ContainerType &coins) const; | const std::set<CTxOut> &txouts) const { | ||||
std::vector<CTxOut> v_txouts(txouts.size()); | |||||
std::copy(txouts.begin(), txouts.end(), v_txouts.begin()); | |||||
return DummySignTx(txNew, v_txouts); | |||||
} | |||||
bool DummySignTx(CMutableTransaction &txNew, | |||||
const std::vector<CTxOut> &txouts) const; | |||||
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout) const; | |||||
static CFeeRate fallbackFee; | static CFeeRate fallbackFee; | ||||
bool NewKeyPool(); | bool NewKeyPool(); | ||||
size_t KeypoolCountExternalKeys(); | size_t KeypoolCountExternalKeys(); | ||||
bool TopUpKeyPool(unsigned int kpSize = 0); | bool TopUpKeyPool(unsigned int kpSize = 0); | ||||
void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, | void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, | ||||
bool fRequestedInternal); | bool fRequestedInternal); | ||||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
if (!(s.GetType() & SER_GETHASH)) { | if (!(s.GetType() & SER_GETHASH)) { | ||||
READWRITE(nVersion); | READWRITE(nVersion); | ||||
} | } | ||||
READWRITE(vchPubKey); | READWRITE(vchPubKey); | ||||
} | } | ||||
}; | }; | ||||
// Helper for producing a bunch of max-sized low-S signatures (eg 72 bytes) | |||||
// ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable so | |||||
// that each entry corresponds to each vIn, in order. | |||||
template <typename ContainerType> | |||||
bool CWallet::DummySignTx(CMutableTransaction &txNew, | |||||
const ContainerType &coins) const { | |||||
// Fill in dummy signatures for fee calculation. | |||||
int nIn = 0; | |||||
for (const auto &coin : coins) { | |||||
const CScript &scriptPubKey = coin.txout.scriptPubKey; | |||||
SignatureData sigdata; | |||||
if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, | |||||
sigdata)) { | |||||
return false; | |||||
} else { | |||||
UpdateTransaction(txNew, nIn, sigdata); | |||||
} | |||||
nIn++; | |||||
} | |||||
return true; | |||||
} | |||||
OutputType ParseOutputType(const std::string &str, | OutputType ParseOutputType(const std::string &str, | ||||
OutputType default_type = OutputType::DEFAULT); | OutputType default_type = OutputType::DEFAULT); | ||||
const std::string &FormatOutputType(OutputType type); | const std::string &FormatOutputType(OutputType type); | ||||
/** | /** | ||||
* Get a destination of the requested type (if possible) to the specified key. | * Get a destination of the requested type (if possible) to the specified key. | ||||
* The caller must make sure LearnRelatedScripts has been called beforehand. | * The caller must make sure LearnRelatedScripts has been called beforehand. | ||||
*/ | */ | ||||
Show All 32 Lines | public: | ||||
~WalletRescanReserver() { | ~WalletRescanReserver() { | ||||
std::lock_guard<std::mutex> lock(m_wallet->mutexScanning); | std::lock_guard<std::mutex> lock(m_wallet->mutexScanning); | ||||
if (m_could_reserve) { | if (m_could_reserve) { | ||||
m_wallet->fScanningWallet = false; | m_wallet->fScanningWallet = false; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
// Calculate the size of the transaction assuming all signatures are max size | |||||
// Use DummySignatureCreator, which inserts 72 byte signatures everywhere. | |||||
// NOTE: this requires that all inputs must be in mapWallet (eg the tx should | |||||
// be IsAllFromMe). | |||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, | |||||
const CWallet *wallet); | |||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, | |||||
const CWallet *wallet, | |||||
const std::vector<CTxOut> &txouts); | |||||
#endif // BITCOIN_WALLET_WALLET_H | #endif // BITCOIN_WALLET_WALLET_H |