diff options
Diffstat (limited to 'src/primitives/transaction.h')
-rw-r--r-- | src/primitives/transaction.h | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 89deb9de4d..ad190f7d7f 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -24,14 +24,6 @@ #include <utility> #include <vector> -/** - * A flag that is ORed into the protocol version to designate that a transaction - * should be (un)serialized without witness data. - * Make sure that this does not collide with any of the values in `version.h` - * or with `ADDRV2_FORMAT`. - */ -static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000; - /** An outpoint - a combination of a transaction hash and an index n into its vout */ class COutPoint { @@ -197,6 +189,13 @@ public: struct CMutableTransaction; +struct TransactionSerParams { + const bool allow_witness; + SER_PARAMS_OPFUNC +}; +static constexpr TransactionSerParams TX_WITH_WITNESS{.allow_witness = true}; +static constexpr TransactionSerParams TX_NO_WITNESS{.allow_witness = false}; + /** * Basic transaction serialization format: * - int32_t nVersion @@ -215,8 +214,9 @@ struct CMutableTransaction; * - uint32_t nLockTime */ template<typename Stream, typename TxType> -inline void UnserializeTransaction(TxType& tx, Stream& s) { - const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS); +void UnserializeTransaction(TxType& tx, Stream& s, const TransactionSerParams& params) +{ + const bool fAllowWitness = params.allow_witness; s >> tx.nVersion; unsigned char flags = 0; @@ -254,8 +254,9 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { } template<typename Stream, typename TxType> -inline void SerializeTransaction(const TxType& tx, Stream& s) { - const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS); +void SerializeTransaction(const TxType& tx, Stream& s, const TransactionSerParams& params) +{ + const bool fAllowWitness = params.allow_witness; s << tx.nVersion; unsigned char flags = 0; @@ -323,13 +324,15 @@ public: template <typename Stream> inline void Serialize(Stream& s) const { - SerializeTransaction(*this, s); + SerializeTransaction(*this, s, s.GetParams()); } /** This deserializing constructor is provided instead of an Unserialize method. * Unserialize is not possible, since it would require overwriting const fields. */ template <typename Stream> - CTransaction(deserialize_type, Stream& s) : CTransaction(CMutableTransaction(deserialize, s)) {} + CTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) : CTransaction(CMutableTransaction(deserialize, params, s)) {} + template <typename Stream> + CTransaction(deserialize_type, ParamsStream<TransactionSerParams,Stream>& s) : CTransaction(CMutableTransaction(deserialize, s)) {} bool IsNull() const { return vin.empty() && vout.empty(); @@ -389,17 +392,21 @@ struct CMutableTransaction template <typename Stream> inline void Serialize(Stream& s) const { - SerializeTransaction(*this, s); + SerializeTransaction(*this, s, s.GetParams()); } - template <typename Stream> inline void Unserialize(Stream& s) { - UnserializeTransaction(*this, s); + UnserializeTransaction(*this, s, s.GetParams()); + } + + template <typename Stream> + CMutableTransaction(deserialize_type, const TransactionSerParams& params, Stream& s) { + UnserializeTransaction(*this, s, params); } template <typename Stream> - CMutableTransaction(deserialize_type, Stream& s) { + CMutableTransaction(deserialize_type, ParamsStream<TransactionSerParams,Stream>& s) { Unserialize(s); } |