@@ -235,7 +235,8 @@ struct PSBTInput
235235 // Write the utxo
236236 if (non_witness_utxo) {
237237 SerializeToVector (s, PSBT_IN_NON_WITNESS_UTXO);
238- SerializeToVector (s, non_witness_utxo);
238+ OverrideStream<Stream> os (&s, s.GetType (), s.GetVersion ());
239+ SerializeToVector (os, non_witness_utxo);
239240 }
240241
241242 if (final_script_sig.empty ()) {
@@ -295,13 +296,17 @@ struct PSBTInput
295296 // Do stuff based on type
296297 switch (type) {
297298 case PSBT_IN_NON_WITNESS_UTXO:
299+ {
298300 if (non_witness_utxo) {
299301 throw std::ios_base::failure (" Duplicate Key, input non-witness utxo already provided" );
300302 } else if (key.size () != 1 ) {
301303 throw std::ios_base::failure (" Non-witness utxo key is more than one byte type" );
302304 }
303- UnserializeFromVector (s, non_witness_utxo);
305+ // Set the stream to unserialize with witness since this is always a valid network transaction
306+ OverrideStream<Stream> os (&s, s.GetType (), s.GetVersion ());
307+ UnserializeFromVector (os, non_witness_utxo);
304308 break ;
309+ }
305310 case PSBT_IN_PARTIAL_SIG:
306311 {
307312 // Make sure that the key is the size of pubkey + 1
@@ -511,7 +516,8 @@ struct PartiallySignedTransaction
511516 SerializeToVector (s, PSBT_GLOBAL_UNSIGNED_TX);
512517
513518 // Write serialized tx to a stream
514- SerializeToVector (s, *tx);
519+ OverrideStream<Stream> os (&s, s.GetType (), s.GetVersion ());
520+ SerializeToVector (os, *tx);
515521
516522 // Write the unknown things
517523 for (auto & entry : unknown) {
@@ -565,7 +571,9 @@ struct PartiallySignedTransaction
565571 throw std::ios_base::failure (" Global unsigned tx key is more than one byte type" );
566572 }
567573 CMutableTransaction mtx;
568- UnserializeFromVector (s, mtx);
574+ // Set the stream to serialize with non-witness since this should always be non-witness
575+ OverrideStream<Stream> os (&s, s.GetType (), s.GetVersion ());
576+ UnserializeFromVector (os, mtx);
569577 tx = std::move (mtx);
570578 // Make sure that all scriptSigs are empty
571579 for (const CTxIn& txin : tx->vin ) {
0 commit comments