@@ -487,37 +487,41 @@ PSBTError SignPSBTInput(const SigningProvider& provider, PartiallySignedTransact
487
487
return sig_complete ? PSBTError::OK : PSBTError::INCOMPLETE;
488
488
}
489
489
490
- void RemoveUnnecessaryTransactions (PartiallySignedTransaction& psbtx, std::optional< int > sighash_type )
490
+ void RemoveUnnecessaryTransactions (PartiallySignedTransaction& psbtx)
491
491
{
492
- if (!sighash_type) sighash_type = SIGHASH_DEFAULT;
493
- // Only drop non_witness_utxos if sighash_type != SIGHASH_ANYONECANPAY
494
- if ((*sighash_type & 0x80 ) != SIGHASH_ANYONECANPAY ) {
495
- // Figure out if any non_witness_utxos should be dropped
496
- std::vector< unsigned int > to_drop ;
497
- for ( unsigned int i = 0 ; i < psbtx. inputs . size (); ++i) {
498
- const auto & input = psbtx. inputs . at (i);
499
- int wit_ver;
500
- std::vector< unsigned char > wit_prog ;
501
- if (input. witness_utxo . IsNull () || !input. witness_utxo . scriptPubKey . IsWitnessProgram (wit_ver, wit_prog)) {
502
- // There's a non-segwit input or Segwit v0, so we cannot drop any witness_utxos
503
- to_drop. clear ();
504
- break ;
505
- }
506
- if (wit_ver == 0 ) {
507
- // Segwit v0, so we cannot drop any non_witness_utxos
508
- to_drop. clear ();
509
- break ;
510
- }
511
- if ( input.non_witness_utxo ) {
512
- to_drop.push_back (i );
513
- }
492
+ // Figure out if any non_witness_utxos should be dropped
493
+ std::vector< unsigned int > to_drop;
494
+ for ( unsigned int i = 0 ; i < psbtx. inputs . size (); ++i ) {
495
+ const auto & input = psbtx. inputs . at (i);
496
+ int wit_ver ;
497
+ std::vector< unsigned char > wit_prog;
498
+ if ( input. witness_utxo . IsNull () || !input. witness_utxo . scriptPubKey . IsWitnessProgram (wit_ver, wit_prog)) {
499
+ // There's a non-segwit input, so we cannot drop any non_witness_utxos
500
+ to_drop. clear () ;
501
+ break ;
502
+ }
503
+ if (wit_ver == 0 ) {
504
+ // Segwit v0, so we cannot drop any non_witness_utxos
505
+ to_drop. clear ();
506
+ break ;
507
+ }
508
+ // non_witness_utxos cannot be dropped if the sighash type includes SIGHASH_ANYONECANPAY
509
+ // Since callers should have called SignPSBTInput which updates the sighash type in the PSBT, we only
510
+ // need to look at that field. If it is not present, then we can assume SIGHASH_DEFAULT or SIGHASH_ALL.
511
+ if (input. sighash_type != std::nullopt && (* input.sighash_type & 0x80 ) == SIGHASH_ANYONECANPAY ) {
512
+ to_drop.clear ( );
513
+ break ;
514
514
}
515
515
516
- // Drop the non_witness_utxos that we can drop
517
- for (unsigned int i : to_drop) {
518
- psbtx.inputs .at (i).non_witness_utxo = nullptr ;
516
+ if (input.non_witness_utxo ) {
517
+ to_drop.push_back (i);
519
518
}
520
519
}
520
+
521
+ // Drop the non_witness_utxos that we can drop
522
+ for (unsigned int i : to_drop) {
523
+ psbtx.inputs .at (i).non_witness_utxo = nullptr ;
524
+ }
521
525
}
522
526
523
527
bool FinalizePSBT (PartiallySignedTransaction& psbtx)
0 commit comments