diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 7acdac17f..91f4d2948 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -78,6 +78,10 @@ CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion UpdateHash(); } +CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), wit(std::move(tx.wit)), nLockTime(tx.nLockTime) { + UpdateHash(); +} + CTransaction& CTransaction::operator=(const CTransaction &tx) { *const_cast(&nVersion) = tx.nVersion; *const_cast*>(&vin) = tx.vin; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 1d176e5d8..015a89ff1 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -379,6 +379,7 @@ public: /** Convert a CMutableTransaction into a CTransaction. */ CTransaction(const CMutableTransaction &tx); + CTransaction(CMutableTransaction &&tx); CTransaction& operator=(const CTransaction& tx); @@ -392,6 +393,9 @@ public: } } + template + CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {} + bool IsNull() const { return vin.empty() && vout.empty(); } @@ -460,6 +464,11 @@ struct CMutableTransaction SerializeTransaction(*this, s, ser_action); } + template + CMutableTransaction(deserialize_type, Stream& s) { + Unserialize(s); + } + /** Compute the hash of this CMutableTransaction. This is computed on the * fly, as opposed to GetHash() in CTransaction, which uses a cached result. */