Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/transaction.h
Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | public: | ||||
// CURRENT_VERSION and MAX_STANDARD_VERSION will be equal. | // CURRENT_VERSION and MAX_STANDARD_VERSION will be equal. | ||||
static const int32_t MAX_STANDARD_VERSION = 2; | static const int32_t MAX_STANDARD_VERSION = 2; | ||||
// The local variables are made const to prevent unintended modification | // The local variables are made const to prevent unintended modification | ||||
// without updating the cached hash value. However, CTransaction is not | // without updating the cached hash value. However, CTransaction is not | ||||
// actually immutable; deserialization and assignment are implemented, | // actually immutable; deserialization and assignment are implemented, | ||||
// and bypass the constness. This is safe, as they update the entire | // and bypass the constness. This is safe, as they update the entire | ||||
// structure, including the hash. | // structure, including the hash. | ||||
const int32_t nVersion; | |||||
const std::vector<CTxIn> vin; | const std::vector<CTxIn> vin; | ||||
const std::vector<CTxOut> vout; | const std::vector<CTxOut> vout; | ||||
const int32_t nVersion; | |||||
const uint32_t nLockTime; | const uint32_t nLockTime; | ||||
private: | private: | ||||
/** Memory only. */ | /** Memory only. */ | ||||
const uint256 hash; | const uint256 hash; | ||||
uint256 ComputeHash() const; | uint256 ComputeHash() const; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
friend bool operator!=(const CTransaction &a, const CTransaction &b) { | friend bool operator!=(const CTransaction &a, const CTransaction &b) { | ||||
return a.hash != b.hash; | return a.hash != b.hash; | ||||
} | } | ||||
std::string ToString() const; | std::string ToString() const; | ||||
}; | }; | ||||
static_assert(sizeof(CTransaction) == 88); | |||||
/** | /** | ||||
* A mutable version of CTransaction. | * A mutable version of CTransaction. | ||||
*/ | */ | ||||
class CMutableTransaction { | class CMutableTransaction { | ||||
public: | public: | ||||
int32_t nVersion; | |||||
std::vector<CTxIn> vin; | std::vector<CTxIn> vin; | ||||
std::vector<CTxOut> vout; | std::vector<CTxOut> vout; | ||||
int32_t nVersion; | |||||
uint32_t nLockTime; | uint32_t nLockTime; | ||||
CMutableTransaction(); | CMutableTransaction(); | ||||
explicit CMutableTransaction(const CTransaction &tx); | explicit CMutableTransaction(const CTransaction &tx); | ||||
template <typename Stream> inline void Serialize(Stream &s) const { | template <typename Stream> inline void Serialize(Stream &s) const { | ||||
SerializeTransaction(*this, s); | SerializeTransaction(*this, s); | ||||
} | } | ||||
Show All 15 Lines | public: | ||||
TxId GetId() const; | TxId GetId() const; | ||||
TxHash GetHash() const; | TxHash GetHash() const; | ||||
friend bool operator==(const CMutableTransaction &a, | friend bool operator==(const CMutableTransaction &a, | ||||
const CMutableTransaction &b) { | const CMutableTransaction &b) { | ||||
return a.GetId() == b.GetId(); | return a.GetId() == b.GetId(); | ||||
} | } | ||||
}; | }; | ||||
static_assert(sizeof(CMutableTransaction) == 56); | |||||
typedef std::shared_ptr<const CTransaction> CTransactionRef; | typedef std::shared_ptr<const CTransaction> CTransactionRef; | ||||
static inline CTransactionRef MakeTransactionRef() { | static inline CTransactionRef MakeTransactionRef() { | ||||
return std::make_shared<const CTransaction>(); | return std::make_shared<const CTransaction>(); | ||||
} | } | ||||
template <typename Tx> | template <typename Tx> | ||||
static inline CTransactionRef MakeTransactionRef(Tx &&txIn) { | static inline CTransactionRef MakeTransactionRef(Tx &&txIn) { | ||||
return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); | return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); | ||||
Show All 17 Lines |