Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | |||||
/** Legacy class used for deserializing vtxPrev for backwards compatibility. | /** Legacy class used for deserializing vtxPrev for backwards compatibility. | ||||
* vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3, | * vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3, | ||||
* but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs. | * but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs. | ||||
* These need to get deserialized for field alignment when deserializing | * These need to get deserialized for field alignment when deserializing | ||||
* a CWalletTx, but the deserialized values are discarded.**/ | * a CWalletTx, but the deserialized values are discarded.**/ | ||||
class CMerkleTx { | class CMerkleTx { | ||||
public: | public: | ||||
CTransactionRef tx; | |||||
BlockHash hashBlock; | |||||
/** | |||||
* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest | |||||
* block in the chain we know this or any in-wallet dependency conflicts | |||||
* with. Older clients interpret nIndex == -1 as unconfirmed for backward | |||||
* compatibility. | |||||
*/ | |||||
int nIndex; | |||||
CMerkleTx() { | |||||
SetTx(MakeTransactionRef()); | |||||
Init(); | |||||
} | |||||
explicit CMerkleTx(CTransactionRef arg) { | |||||
SetTx(std::move(arg)); | |||||
Init(); | |||||
} | |||||
void Init() { | |||||
hashBlock = BlockHash(); | |||||
nIndex = -1; | |||||
} | |||||
void SetTx(CTransactionRef arg) { tx = std::move(arg); } | |||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
CTransactionRef tx; | |||||
BlockHash hashBlock; | |||||
int nIndex = 0; | |||||
// 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); | ||||
} | } | ||||
}; | }; | ||||
// Get the marginal bytes of spending the specified output | // Get the marginal bytes of spending the specified output | ||||
int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet, | int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet, | ||||
bool use_max_sig = false); | bool use_max_sig = false); | ||||
/** | /** | ||||
* 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 { | ||||
private: | private: | ||||
const CWallet *pwallet; | const CWallet *pwallet; | ||||
/** Constant used in hashBlock to indicate tx has been abandoned */ | /** Constant used in hashBlock to indicate tx has been abandoned */ | ||||
static const BlockHash ABANDON_HASH; | static const BlockHash ABANDON_HASH; | ||||
public: | public: | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public: | ||||
Amount GetCachableAmount(AmountType type, const isminefilter &filter, | Amount GetCachableAmount(AmountType type, const isminefilter &filter, | ||||
bool recalculate = false) const; | bool recalculate = false) const; | ||||
mutable CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]; | mutable CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]; | ||||
mutable bool fChangeCached; | mutable bool fChangeCached; | ||||
mutable bool fInMempool; | mutable bool fInMempool; | ||||
mutable Amount nChangeCached; | mutable Amount nChangeCached; | ||||
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg) | CWalletTx(const CWallet *pwalletIn, CTransactionRef arg) | ||||
: CMerkleTx(std::move(arg)) { | : tx(std::move(arg)), hashBlock(BlockHash()), nIndex(-1) { | ||||
Init(pwalletIn); | Init(pwalletIn); | ||||
} | } | ||||
void Init(const CWallet *pwalletIn) { | void Init(const CWallet *pwalletIn) { | ||||
pwallet = pwalletIn; | pwallet = pwalletIn; | ||||
mapValue.clear(); | mapValue.clear(); | ||||
vOrderForm.clear(); | vOrderForm.clear(); | ||||
fTimeReceivedIsTxTime = false; | fTimeReceivedIsTxTime = false; | ||||
nTimeReceived = 0; | nTimeReceived = 0; | ||||
nTimeSmart = 0; | nTimeSmart = 0; | ||||
fFromMe = false; | fFromMe = false; | ||||
fChangeCached = false; | fChangeCached = false; | ||||
fInMempool = false; | fInMempool = false; | ||||
nChangeCached = Amount::zero(); | nChangeCached = Amount::zero(); | ||||
nOrderPos = -1; | nOrderPos = -1; | ||||
} | } | ||||
CTransactionRef tx; | |||||
BlockHash hashBlock; | |||||
/** | |||||
* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest | |||||
* block in the chain we know this or any in-wallet dependency conflicts | |||||
* with. Older clients interpret nIndex == -1 as unconfirmed for backward | |||||
* compatibility. | |||||
*/ | |||||
int nIndex; | |||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
char fSpent = false; | char fSpent = false; | ||||
mapValue_t mapValueCopy = mapValue; | mapValue_t mapValueCopy = mapValue; | ||||
mapValueCopy["fromaccount"] = ""; | mapValueCopy["fromaccount"] = ""; | ||||
WriteOrderPos(nOrderPos, mapValueCopy); | WriteOrderPos(nOrderPos, mapValueCopy); | ||||
if (nTimeSmart) { | if (nTimeSmart) { | ||||
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); | mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart); | ||||
} | } | ||||
s << static_cast<const CMerkleTx &>(*this); | //! Used to be vMerkleBranch | ||||
std::vector<uint256> dummy_vector; | |||||
s << tx << hashBlock << dummy_vector << nIndex; | |||||
//! Used to be vtxPrev | //! Used to be vtxPrev | ||||
std::vector<CMerkleTx> vUnused; | std::vector<CMerkleTx> vUnused; | ||||
s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime | s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime | ||||
<< nTimeReceived << fFromMe << fSpent; | << nTimeReceived << fFromMe << fSpent; | ||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
Init(nullptr); | Init(nullptr); | ||||
char fSpent; | char fSpent; | ||||
s >> static_cast<CMerkleTx &>(*this); | //! Used to be vMerkleBranch | ||||
std::vector<uint256> dummy_vector; | |||||
s >> tx >> hashBlock >> dummy_vector >> nIndex; | |||||
//! Used to be vtxPrev | //! Used to be vtxPrev | ||||
std::vector<CMerkleTx> vUnused; | std::vector<CMerkleTx> vUnused; | ||||
s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> | s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> | ||||
nTimeReceived >> fFromMe >> fSpent; | nTimeReceived >> fFromMe >> fSpent; | ||||
ReadOrderPos(nOrderPos, mapValue); | ReadOrderPos(nOrderPos, mapValue); | ||||
nTimeSmart = mapValue.count("timesmart") | nTimeSmart = mapValue.count("timesmart") | ||||
? (unsigned int)atoi64(mapValue["timesmart"]) | ? (unsigned int)atoi64(mapValue["timesmart"]) | ||||
: 0; | : 0; | ||||
mapValue.erase("fromaccount"); | mapValue.erase("fromaccount"); | ||||
mapValue.erase("spent"); | mapValue.erase("spent"); | ||||
mapValue.erase("n"); | mapValue.erase("n"); | ||||
mapValue.erase("timesmart"); | mapValue.erase("timesmart"); | ||||
} | } | ||||
void SetTx(CTransactionRef arg) { tx = std::move(arg); } | |||||
//! make sure balances are recalculated | //! make sure balances are recalculated | ||||
void MarkDirty() { | void MarkDirty() { | ||||
m_amounts[DEBIT].Reset(); | m_amounts[DEBIT].Reset(); | ||||
m_amounts[CREDIT].Reset(); | m_amounts[CREDIT].Reset(); | ||||
m_amounts[IMMATURE_CREDIT].Reset(); | m_amounts[IMMATURE_CREDIT].Reset(); | ||||
m_amounts[AVAILABLE_CREDIT].Reset(); | m_amounts[AVAILABLE_CREDIT].Reset(); | ||||
fChangeCached = false; | fChangeCached = false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,127 Lines • Show Last 20 Lines |