Refactor GetTxid() into UpdateTxid() to match coding style of hash member variable.
UpdateTxid() is called alongside UpdateHash() when a CTransaction is deserialized or constructed. GetTxid() now returns a const reference.
This commit is contained in:
parent
29306269f4
commit
07e6d5b025
|
@ -132,6 +132,7 @@ CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion
|
||||||
joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig)
|
joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig)
|
||||||
{
|
{
|
||||||
UpdateHash();
|
UpdateHash();
|
||||||
|
UpdateTxid();
|
||||||
}
|
}
|
||||||
|
|
||||||
CTransaction& CTransaction::operator=(const CTransaction &tx) {
|
CTransaction& CTransaction::operator=(const CTransaction &tx) {
|
||||||
|
@ -143,6 +144,7 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
|
||||||
*const_cast<uint256*>(&joinSplitPubKey) = tx.joinSplitPubKey;
|
*const_cast<uint256*>(&joinSplitPubKey) = tx.joinSplitPubKey;
|
||||||
*const_cast<joinsplit_sig_t*>(&joinSplitSig) = tx.joinSplitSig;
|
*const_cast<joinsplit_sig_t*>(&joinSplitSig) = tx.joinSplitSig;
|
||||||
*const_cast<uint256*>(&hash) = tx.hash;
|
*const_cast<uint256*>(&hash) = tx.hash;
|
||||||
|
*const_cast<uint256*>(&txid) = tx.txid;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +229,7 @@ std::string CTransaction::ToString() const
|
||||||
|
|
||||||
// Return a txid which is non-malleable.
|
// Return a txid which is non-malleable.
|
||||||
// Signature data is cleared before the transaction is serialized and hashed.
|
// Signature data is cleared before the transaction is serialized and hashed.
|
||||||
uint256 CTransaction::GetTxid() const
|
void CTransaction::UpdateTxid() const
|
||||||
{
|
{
|
||||||
// Create a deep copy of this transaction
|
// Create a deep copy of this transaction
|
||||||
CMutableTransaction tx(*this);
|
CMutableTransaction tx(*this);
|
||||||
|
@ -241,10 +243,9 @@ uint256 CTransaction::GetTxid() const
|
||||||
tx.joinSplitSig.assign(0);
|
tx.joinSplitSig.assign(0);
|
||||||
|
|
||||||
// Return double SHA256 hash
|
// Return double SHA256 hash
|
||||||
return tx.GetSerializeHash();
|
*const_cast<uint256*>(&txid) = tx.GetSerializeHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a txid which is non-malleable.
|
// Return a txid which is non-malleable.
|
||||||
uint256 CMutableTransaction::GetTxid() const
|
uint256 CMutableTransaction::GetTxid() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -288,6 +288,8 @@ private:
|
||||||
/** Memory only. */
|
/** Memory only. */
|
||||||
const uint256 hash;
|
const uint256 hash;
|
||||||
void UpdateHash() const;
|
void UpdateHash() const;
|
||||||
|
uint256 txid;
|
||||||
|
void UpdateTxid() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef boost::array<unsigned char, 64> joinsplit_sig_t;
|
typedef boost::array<unsigned char, 64> joinsplit_sig_t;
|
||||||
|
@ -331,8 +333,10 @@ public:
|
||||||
READWRITE(*const_cast<joinsplit_sig_t*>(&joinSplitSig));
|
READWRITE(*const_cast<joinsplit_sig_t*>(&joinSplitSig));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ser_action.ForRead())
|
if (ser_action.ForRead()) {
|
||||||
UpdateHash();
|
UpdateHash();
|
||||||
|
UpdateTxid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNull() const {
|
bool IsNull() const {
|
||||||
|
@ -374,9 +378,10 @@ public:
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
||||||
// Return the txid which is the double SHA256 hash of the transaction.
|
// Return the txid, which is the double SHA256 hash over portions of the transaction.
|
||||||
uint256 GetTxid() const;
|
const uint256& GetTxid() const {
|
||||||
|
return txid;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A mutable version of CTransaction. */
|
/** A mutable version of CTransaction. */
|
||||||
|
|
Loading…
Reference in New Issue