File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -469,3 +469,36 @@ func FindLeafScript(pInput *PInput,
469469 return nil , fmt .Errorf ("leaf script for target leaf hash %x not " +
470470 "found in input" , targetLeafHash )
471471}
472+
473+ // PrevOutputFetcher returns a txscript.PrevOutFetcher built from the UTXO
474+ // information in a PSBT packet.
475+ func PrevOutputFetcher (packet * Packet ) * txscript.MultiPrevOutFetcher {
476+ fetcher := txscript .NewMultiPrevOutFetcher (nil )
477+ for idx , txIn := range packet .UnsignedTx .TxIn {
478+ in := packet .Inputs [idx ]
479+
480+ // Skip any input that has no UTXO.
481+ if in .WitnessUtxo == nil && in .NonWitnessUtxo == nil {
482+ continue
483+ }
484+
485+ if in .NonWitnessUtxo != nil {
486+ prevIndex := txIn .PreviousOutPoint .Index
487+ fetcher .AddPrevOut (
488+ txIn .PreviousOutPoint ,
489+ in .NonWitnessUtxo .TxOut [prevIndex ],
490+ )
491+
492+ continue
493+ }
494+
495+ // Fall back to witness UTXO only for older wallets.
496+ if in .WitnessUtxo != nil {
497+ fetcher .AddPrevOut (
498+ txIn .PreviousOutPoint , in .WitnessUtxo ,
499+ )
500+ }
501+ }
502+
503+ return fetcher
504+ }
You can’t perform that action at this time.
0 commit comments