@@ -261,6 +261,27 @@ func (p *VPacket) FirstInteractiveOutput() (*VOutput, error) {
261261 return result , nil
262262}
263263
264+ // AssetID returns the asset ID of the virtual transaction. It returns an error
265+ // if the virtual transaction has no inputs or if the inputs have different
266+ // asset IDs.
267+ func (p * VPacket ) AssetID () (asset.ID , error ) {
268+ if len (p .Inputs ) == 0 {
269+ return asset.ID {}, fmt .Errorf ("no inputs" )
270+ }
271+
272+ firstID := p .Inputs [0 ].PrevID .ID
273+ for idx := range p .Inputs {
274+ if p .Inputs [idx ].PrevID .ID != firstID {
275+ return asset.ID {}, fmt .Errorf ("packet has inputs with " +
276+ "different asset IDs, index 0 has ID %v and " +
277+ "index %d has ID %v" , firstID , idx ,
278+ p .Inputs [idx ].PrevID .ID )
279+ }
280+ }
281+
282+ return firstID , nil
283+ }
284+
264285// Anchor is a struct that contains all the information about an anchor output.
265286type Anchor struct {
266287 // Value is output value of the anchor output.
@@ -584,6 +605,23 @@ func (o *VOutput) AnchorKeyToDesc() (keychain.KeyDescriptor, error) {
584605 return KeyDescFromBip32Derivation (o .AnchorOutputBip32Derivation [0 ])
585606}
586607
608+ // PrevWitnesses returns the previous witnesses of the asset output. If the
609+ // asset is a split root, the witness of the root asset is returned. If the
610+ // output asset is nil an error is returned.
611+ func (o * VOutput ) PrevWitnesses () ([]asset.Witness , error ) {
612+ if o .Asset == nil {
613+ return nil , fmt .Errorf ("asset is not set" )
614+ }
615+
616+ prevWitness := o .Asset .PrevWitnesses
617+ if o .Asset .HasSplitCommitmentWitness () {
618+ rootAsset := prevWitness [0 ].SplitCommitment .RootAsset
619+ prevWitness = rootAsset .PrevWitnesses
620+ }
621+
622+ return prevWitness , nil
623+ }
624+
587625// KeyDescFromBip32Derivation attempts to extract the key descriptor from the
588626// given public key and BIP-0032 derivation information.
589627func KeyDescFromBip32Derivation (
0 commit comments