@@ -369,6 +369,23 @@ func (f *AssetWallet) FundPacket(ctx context.Context,
369369 return nil , address .ErrMismatchedHRP
370370 }
371371
372+ // Each anchor output must have a valid set of AltLeaves at this point.
373+ outputAltLeaves := make (map [uint32 ][]asset.AltLeaf [asset.Asset ])
374+ for _ , vOut := range vPkt .Outputs {
375+ outputAltLeaves [vOut .AnchorOutputIndex ] = append (
376+ outputAltLeaves [vOut .AnchorOutputIndex ],
377+ asset .CopyAltLeaves (vOut .AltLeaves )... ,
378+ )
379+ }
380+
381+ for anchorIdx , leaves := range outputAltLeaves {
382+ err := asset .ValidAltLeaves (leaves )
383+ if err != nil {
384+ return nil , fmt .Errorf ("anchor output %d invalid alt " +
385+ "leaves: %w" , anchorIdx , err )
386+ }
387+ }
388+
372389 // We need to find a commitment that has enough assets to satisfy this
373390 // send request. We'll map the address to a set of constraints, so we
374391 // can use that to do Taproot asset coin selection.
@@ -910,6 +927,16 @@ func createAndSetInput(vPkt *tappsbt.VPacket, idx int,
910927 }
911928 vPkt .SetInputAsset (idx , assetInput .Asset )
912929
930+ inputAltLeaves , err := assetInput .Commitment .FetchAltLeaves ()
931+ if err != nil {
932+ return fmt .Errorf ("cannot fetch alt leaves from input: %w" , err )
933+ }
934+
935+ err = vPkt .Inputs [idx ].SetAltLeaves (inputAltLeaves )
936+ if err != nil {
937+ return fmt .Errorf ("cannot set alt leaves on vInput: %w" , err )
938+ }
939+
913940 return nil
914941}
915942
0 commit comments