func (po *POutput) deserialize(r io.Reader) error {
	for {
		keyint, keydata, err := getKey(r)
		if err != nil {
			return err
		}
		if keyint == -1 {
			break
		}
		value, err := wire.ReadVarBytes(
			r, 0, psbt.MaxPsbtValueLength, "PSET value",
		)
		if err != nil {
			return err
		}
		switch psbt.OutputType(keyint) {
		case psbt.RedeemScriptOutputType:
			if po.RedeemScript != nil {
				return psbt.ErrDuplicateKey
			}
			if keydata != nil {
				return psbt.ErrInvalidKeydata
			}
			po.RedeemScript = value
		case psbt.WitnessScriptOutputType:
			if po.WitnessScript != nil {
				return psbt.ErrDuplicateKey
			}
			if keydata != nil {
				return psbt.ErrInvalidKeydata
			}
			po.WitnessScript = value
		case psbt.Bip32DerivationOutputType:
			if !validatePubkey(keydata) {
				return psbt.ErrInvalidKeydata
			}
			master, derivationPath, err := readBip32Derivation(value)
			if err != nil {
				return err
			}
			for _, x := range po.Bip32Derivation {
				if bytes.Equal(x.PubKey, keydata) {
					return psbt.ErrDuplicateKey
				}
			}
			po.Bip32Derivation = append(po.Bip32Derivation,
				&psbt.Bip32Derivation{
					PubKey:               keydata,
					MasterKeyFingerprint: master,
					Bip32Path:            derivationPath,
				},
			)
		default:
			return psbt.ErrInvalidPsbtFormat
		}
	}
	return nil
}
deserialize attempts to recode a new POutput from the passed io.Reader.
package pset
import (
	"bytes"
	"io"
	"sort"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil/psbt"
)
type POutput struct {
	RedeemScript    []byte
	WitnessScript   []byte
	Bip32Derivation []*psbt.Bip32Derivation
}
func NewPsbtOutput(redeemScript []byte, witnessScript []byte,
	bip32Derivation []*psbt.Bip32Derivation) *POutput {
	return &POutput{
		RedeemScript:    redeemScript,
		WitnessScript:   witnessScript,
		Bip32Derivation: bip32Derivation,
	}
}