@@ -290,6 +290,8 @@ struct CMutableTransaction;
290
290
*/
291
291
template <typename Stream, typename Operation, typename TxType>
292
292
inline void SerializeTransaction (TxType& tx, Stream& s, Operation ser_action, int nType, int nVersion) {
293
+ const bool fAllowWitness = !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS);
294
+
293
295
READWRITE (*const_cast <int32_t *>(&tx.nVersion ));
294
296
unsigned char flags = 0 ;
295
297
if (ser_action.ForRead ()) {
@@ -298,7 +300,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
298
300
const_cast <CTxWitness*>(&tx.wit )->SetNull ();
299
301
/* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
300
302
READWRITE (*const_cast <std::vector<CTxIn>*>(&tx.vin ));
301
- if (tx.vin .size () == 0 && !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS) ) {
303
+ if (tx.vin .size () == 0 && fAllowWitness ) {
302
304
/* We read a dummy or an empty vin. */
303
305
READWRITE (flags);
304
306
if (flags != 0 ) {
@@ -309,7 +311,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
309
311
/* We read a non-empty vin. Assume a normal vout follows. */
310
312
READWRITE (*const_cast <std::vector<CTxOut>*>(&tx.vout ));
311
313
}
312
- if ((flags & 1 ) && !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS) ) {
314
+ if ((flags & 1 ) && fAllowWitness ) {
313
315
/* The witness flag is present, and we support witnesses. */
314
316
flags ^= 1 ;
315
317
const_cast <CTxWitness*>(&tx.wit )->vtxinwit .resize (tx.vin .size ());
@@ -322,7 +324,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
322
324
} else {
323
325
// Consistency check
324
326
assert (tx.wit .vtxinwit .size () <= tx.vin .size ());
325
- if (!(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS) ) {
327
+ if (fAllowWitness ) {
326
328
/* Check whether witnesses need to be serialized. */
327
329
if (!tx.wit .IsNull ()) {
328
330
flags |= 1 ;
0 commit comments