diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2016-11-10 15:53:43 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-11-19 17:50:40 -0800 |
commit | da60506fc80f6a78f1b271a9a53b956b49b37234 (patch) | |
tree | 89b7747f91e62b50cada241342694a6430b0051f | |
parent | 0e85204a1001397f11bad94f1c9c2cb11f8fb4af (diff) |
Add deserializing constructors to CTransaction and CMutableTransaction
-rw-r--r-- | src/primitives/transaction.cpp | 4 | ||||
-rw-r--r-- | src/primitives/transaction.h | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 7acdac17f2..91f4d29488 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<int*>(&nVersion) = tx.nVersion; *const_cast<std::vector<CTxIn>*>(&vin) = tx.vin; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 1d176e5d8c..015a89ff10 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 <typename Stream> + 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 <typename Stream> + 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. */ |