Skip to content

Commit da60506

Browse files
committed
Add deserializing constructors to CTransaction and CMutableTransaction
1 parent 0e85204 commit da60506

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/primitives/transaction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion
7878
UpdateHash();
7979
}
8080

81+
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) {
82+
UpdateHash();
83+
}
84+
8185
CTransaction& CTransaction::operator=(const CTransaction &tx) {
8286
*const_cast<int*>(&nVersion) = tx.nVersion;
8387
*const_cast<std::vector<CTxIn>*>(&vin) = tx.vin;

src/primitives/transaction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ class CTransaction
379379

380380
/** Convert a CMutableTransaction into a CTransaction. */
381381
CTransaction(const CMutableTransaction &tx);
382+
CTransaction(CMutableTransaction &&tx);
382383

383384
CTransaction& operator=(const CTransaction& tx);
384385

@@ -392,6 +393,9 @@ class CTransaction
392393
}
393394
}
394395

396+
template <typename Stream>
397+
CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}
398+
395399
bool IsNull() const {
396400
return vin.empty() && vout.empty();
397401
}
@@ -460,6 +464,11 @@ struct CMutableTransaction
460464
SerializeTransaction(*this, s, ser_action);
461465
}
462466

467+
template <typename Stream>
468+
CMutableTransaction(deserialize_type, Stream& s) {
469+
Unserialize(s);
470+
}
471+
463472
/** Compute the hash of this CMutableTransaction. This is computed on the
464473
* fly, as opposed to GetHash() in CTransaction, which uses a cached result.
465474
*/

0 commit comments

Comments
 (0)