@@ -239,6 +239,11 @@ type PendingAssetStore interface {
239239 // FetchAssetMetaForAsset fetches the asset meta for a given asset.
240240 FetchAssetMetaForAsset (ctx context.Context ,
241241 assetID []byte ) (sqlc.FetchAssetMetaForAssetRow , error )
242+
243+ // FetchMintAnchorUniCommitment fetches the mint anchor uni commitment
244+ // for a given batch.
245+ FetchMintAnchorUniCommitment (ctx context.Context ,
246+ batchID int32 ) (sqlc.MintAnchorUniCommitment , error )
242247}
243248
244249var (
@@ -1164,11 +1169,59 @@ func marshalMintingBatch(ctx context.Context, q PendingAssetStore,
11641169 if err != nil {
11651170 return nil , err
11661171 }
1167- batch .GenesisPacket = & tapsend.FundedPsbt {
1168- Pkt : genesisPkt ,
1169- ChangeOutputIndex : extractSqlInt32 [int32 ](
1170- dbBatch .ChangeOutputIndex ,
1171- ),
1172+
1173+ if ! dbBatch .AssetsOutputIndex .Valid {
1174+ return nil , fmt .Errorf ("missing asset anchor output " +
1175+ "index" )
1176+ }
1177+ assetAnchorOutIdx := dbBatch .AssetsOutputIndex .Int32
1178+
1179+ // If the batch has universe commitments, we will retrieve
1180+ // the pre-commitment output index from the database.
1181+ var preCommitOut fn.Option [tapgarden.PreCommitmentOutput ]
1182+ if dbBatch .UniverseCommitments {
1183+ res , err := q .FetchMintAnchorUniCommitment (
1184+ ctx , int32 (dbBatch .BatchID ),
1185+ )
1186+ if err != nil {
1187+ return nil , fmt .Errorf ("unable to fetch mint " +
1188+ "anchor uni commitment: %w" , err )
1189+ }
1190+
1191+ // Parse the internal key from the database.
1192+ internalKey , err := btcec .ParsePubKey (
1193+ res .TaprootInternalKey ,
1194+ )
1195+ if err != nil {
1196+ return nil , fmt .Errorf ("error parsing " +
1197+ "taproot internal key: %w" , err )
1198+ }
1199+
1200+ // Parse the group public key from the database.
1201+ groupPubKey , err := btcec .ParsePubKey (res .GroupKey )
1202+ if err != nil {
1203+ return nil , fmt .Errorf ("error parsing " +
1204+ "group public key: %w" , err )
1205+ }
1206+
1207+ preCommitOut = fn .Some (
1208+ tapgarden.PreCommitmentOutput {
1209+ OutIdx : uint32 (res .TxOutputIndex ),
1210+ InternalKey : * internalKey ,
1211+ GroupPubKey : * groupPubKey ,
1212+ },
1213+ )
1214+ }
1215+
1216+ batch .GenesisPacket = & tapgarden.FundedMintAnchorPsbt {
1217+ FundedPsbt : tapsend.FundedPsbt {
1218+ Pkt : genesisPkt ,
1219+ ChangeOutputIndex : extractSqlInt32 [int32 ](
1220+ dbBatch .ChangeOutputIndex ,
1221+ ),
1222+ },
1223+ AssetAnchorOutIdx : uint32 (assetAnchorOutIdx ),
1224+ PreCommitmentOutput : preCommitOut ,
11721225 }
11731226 }
11741227
@@ -1283,7 +1336,8 @@ func encodeOutpoint(outPoint wire.OutPoint) ([]byte, error) {
12831336// CommitBatchTx updates the genesis transaction of a batch based on the batch
12841337// key.
12851338func (a * AssetMintingStore ) CommitBatchTx (ctx context.Context ,
1286- batchKey * btcec.PublicKey , genesisPacket * tapsend.FundedPsbt ) error {
1339+ batchKey * btcec.PublicKey ,
1340+ genesisPacket tapgarden.FundedMintAnchorPsbt ) error {
12871341
12881342 genesisOutpoint := genesisPacket .Pkt .UnsignedTx .TxIn [0 ].PreviousOutPoint
12891343 rawBatchKey := batchKey .SerializeCompressed ()
@@ -1417,7 +1471,8 @@ func fetchSeedlingGroups(ctx context.Context, q PendingAssetStore,
14171471// binds the genesis transaction (which will create the set of assets in the
14181472// batch) to the batch itself.
14191473func (a * AssetMintingStore ) AddSproutsToBatch (ctx context.Context ,
1420- batchKey * btcec.PublicKey , genesisPacket * tapsend.FundedPsbt ,
1474+ batchKey * btcec.PublicKey ,
1475+ genesisPacket * tapgarden.FundedMintAnchorPsbt ,
14211476 assetRoot * commitment.TapCommitment ) error {
14221477
14231478 // Before we open the DB transaction below, we'll fetch the set of
0 commit comments