@@ -615,45 +615,31 @@ class CTxWitness
615615struct CMutableTransaction ;
616616
617617/* *
618- * Basic transaction serialization format:
618+ * Elements transaction serialization format:
619619 * - int32_t nVersion
620+ * - unsigned char flags
621+ * - bit 1: witness data
620622 * - std::vector<CTxIn> vin
621623 * - std::vector<CTxOut> vout
622624 * - uint32_t nLockTime
623- *
624- * Extended transaction serialization format:
625- * - int32_t nVersion
626- * - unsigned char dummy = 0x00
627- * - unsigned char flags (!= 0)
628- * - std::vector<CTxIn> vin
629- * - std::vector<CTxOut> vout
630625 * - if (flags & 1):
631626 * - CTxWitness wit;
632- * - uint32_t nLockTime
633627 */
634628template <typename Stream, typename TxType>
635629inline void UnserializeTransaction (TxType& tx, Stream& s) {
636- const bool fAllowWitness = !(s.GetVersion () & SERIALIZE_TRANSACTION_NO_WITNESS);
637630 s >> tx.nVersion ;
638631 unsigned char flags = 0 ;
639632 tx.vin .clear ();
640633 tx.vout .clear ();
641634 tx.wit .SetNull ();
642- /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
635+
636+ s >> flags;
643637 s >> tx.vin ;
644- if (tx.vin .size () == 0 && fAllowWitness ) {
645- /* We read a dummy or an empty vin. */
646- s >> flags;
647- if (flags != 0 ) {
648- s >> tx.vin ;
649- s >> tx.vout ;
650- }
651- } else {
652- /* We read a non-empty vin. Assume a normal vout follows. */
653- s >> tx.vout ;
654- }
655- if ((flags & 1 ) && fAllowWitness ) {
656- /* The witness flag is present, and we support witnesses. */
638+ s >> tx.vout ;
639+ s >> tx.nLockTime ;
640+
641+ if (flags & 1 ) {
642+ /* The witness flag is present. */
657643 flags ^= 1 ;
658644 const_cast <CTxWitness*>(&tx.wit )->vtxinwit .resize (tx.vin .size ());
659645 const_cast <CTxWitness*>(&tx.wit )->vtxoutwit .resize (tx.vout .size ());
@@ -663,43 +649,35 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) {
663649 /* Unknown flag in the serialization */
664650 throw std::ios_base::failure (" Unknown transaction optional data" );
665651 }
666- s >> tx.nLockTime ;
667652}
668653
669654template <typename Stream, typename TxType>
670655inline void SerializeTransaction (const TxType& tx, Stream& s) {
671- const bool fAllowWitness = !(s.GetVersion () & SERIALIZE_TRANSACTION_NO_WITNESS);
672-
656+ const bool fAllowWitness = !(s.GetVersion () & SERIALIZE_TRANSACTION_NO_WITNESS);
673657 s << tx.nVersion ;
674-
675658 unsigned char flags = 0 ;
676659 // Consistency check
677660 assert (tx.wit .vtxoutwit .size () <= tx.vout .size ());
678- if (fAllowWitness ) {
679- /* Check whether witnesses need to be serialized. */
680- if (tx.HasWitness ()) {
681- flags |= 1 ;
682- }
683- }
684- if (flags) {
685- /* Use extended format in case witnesses are to be serialized. */
686- std::vector<CTxIn> vinDummy;
687- s << vinDummy;
688- s << flags;
661+
662+ /* Check whether witnesses need to be serialized. */
663+ if (fAllowWitness && tx.HasWitness ()) {
664+ flags |= 1 ;
689665 }
666+
667+ s << flags;
690668 s << tx.vin ;
691669 s << tx.vout ;
670+ s << tx.nLockTime ;
671+
692672 if (flags & 1 ) {
693673 const_cast <CTxWitness*>(&tx.wit )->vtxinwit .resize (tx.vin .size ());
694674 const_cast <CTxWitness*>(&tx.wit )->vtxoutwit .resize (tx.vout .size ());
695675 s << tx.wit ;
696676 }
697- s << tx.nLockTime ;
698677}
699678
700-
701679/* * The basic transaction that is broadcasted on the network and contained in
702- * blocks. A transaction can contain multiple inputs and outputs.
680+ * blocks. A transaction can contain multiple inputs and outputs.
703681 */
704682class CTransaction
705683{
0 commit comments