Skip to content

Commit

Permalink
Add deserializing constructors to CTransaction and CMutableTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Nov 20, 2016
1 parent 0e85204 commit da60506
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/primitives/transaction.cpp
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/primitives/transaction.h
Expand Up @@ -379,6 +379,7 @@ class CTransaction

/** Convert a CMutableTransaction into a CTransaction. */
CTransaction(const CMutableTransaction &tx);
CTransaction(CMutableTransaction &&tx);

CTransaction& operator=(const CTransaction& tx);

Expand All @@ -392,6 +393,9 @@ class CTransaction
}
}

template <typename Stream>
CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {}

bool IsNull() const {
return vin.empty() && vout.empty();
}
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit da60506

Please sign in to comment.