Skip to content

Commit 1c2a38b

Browse files
committed
tapdb: modify BindMintingBatchWithTx to return batch ID
Update the SQL query in BindMintingBatchWithTx to return the batch ID. This ID will be used for populating the universe commitment anchor rows in the database.
1 parent 03c2d2d commit 1c2a38b

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

tapdb/asset_minting.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ type PendingAssetStore interface {
199199

200200
// BindMintingBatchWithTx adds the minting transaction to an existing
201201
// batch.
202-
BindMintingBatchWithTx(ctx context.Context, arg BatchChainUpdate) error
202+
BindMintingBatchWithTx(ctx context.Context,
203+
arg BatchChainUpdate) (int64, error)
203204

204205
// UpdateBatchGenesisTx updates the batch tx attached to an existing
205206
// batch.
@@ -382,7 +383,7 @@ func (a *AssetMintingStore) CommitMintingBatch(ctx context.Context,
382383
ErrUpsertGenesisPoint, err)
383384
}
384385

385-
err = q.BindMintingBatchWithTx(ctx, BatchChainUpdate{
386+
_, err = q.BindMintingBatchWithTx(ctx, BatchChainUpdate{
386387
RawKey: rawBatchKey,
387388
MintingTxPsbt: psbtBuf.Bytes(),
388389
ChangeOutputIndex: sqlInt32(changeIdx),
@@ -1301,14 +1302,15 @@ func (a *AssetMintingStore) CommitBatchTx(ctx context.Context,
13011302
return fmt.Errorf("%w: %w", ErrUpsertGenesisPoint, err)
13021303
}
13031304

1304-
return q.BindMintingBatchWithTx(ctx, BatchChainUpdate{
1305+
_, err = q.BindMintingBatchWithTx(ctx, BatchChainUpdate{
13051306
RawKey: rawBatchKey,
13061307
MintingTxPsbt: psbtBuf.Bytes(),
13071308
ChangeOutputIndex: sqlInt32(
13081309
genesisPacket.ChangeOutputIndex,
13091310
),
13101311
GenesisID: sqlInt64(genesisPointID),
13111312
})
1313+
return err
13121314
})
13131315
}
13141316

@@ -1459,7 +1461,7 @@ func (a *AssetMintingStore) AddSproutsToBatch(ctx context.Context,
14591461
if err := genesisPacket.Pkt.Serialize(&psbtBuf); err != nil {
14601462
return fmt.Errorf("%w: %w", ErrEncodePsbt, err)
14611463
}
1462-
err = q.BindMintingBatchWithTx(ctx, BatchChainUpdate{
1464+
_, err = q.BindMintingBatchWithTx(ctx, BatchChainUpdate{
14631465
RawKey: rawBatchKey,
14641466
MintingTxPsbt: psbtBuf.Bytes(),
14651467
ChangeOutputIndex: sqlInt32(

tapdb/sqlc/assets.sql.go

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/queries/assets.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,18 @@ JOIN internal_keys keys
530530
ON keys.key_id = batches.batch_id
531531
WHERE keys.raw_key = $1;
532532

533-
-- name: BindMintingBatchWithTx :exec
533+
-- name: BindMintingBatchWithTx :one
534534
WITH target_batch AS (
535535
SELECT batch_id
536536
FROM asset_minting_batches batches
537537
JOIN internal_keys keys
538538
ON batches.batch_id = keys.key_id
539539
WHERE keys.raw_key = $1
540540
)
541-
UPDATE asset_minting_batches
541+
UPDATE asset_minting_batches
542542
SET minting_tx_psbt = $2, change_output_index = $3, genesis_id = $4
543-
WHERE batch_id IN (SELECT batch_id FROM target_batch);
543+
WHERE batch_id IN (SELECT batch_id FROM target_batch)
544+
RETURNING batch_id;
544545

545546
-- name: BindMintingBatchWithTapSibling :exec
546547
WITH target_batch AS (

0 commit comments

Comments
 (0)