Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tapdb: add anchor point to SetSpent, remove LIMIT 1 #984

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2727,8 +2727,9 @@ func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context,
for idx := range inputs {
spentAssetIDs[idx], err = q.SetAssetSpent(
ctx, SetAssetSpentParams{
ScriptKey: inputs[idx].ScriptKey,
GenAssetID: inputs[idx].AssetID,
ScriptKey: inputs[idx].ScriptKey,
GenAssetID: inputs[idx].AssetID,
AnchorPoint: inputs[idx].AnchorPoint,
},
)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions tapdb/assets_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,19 @@ func (a *assetGenerator) genAssets(t *testing.T, assetStore *AssetStore,
require.NoError(t, err)

if desc.spent {
opBytes, err := encodeOutpoint(desc.anchorPoint)
require.NoError(t, err)

var (
scriptKey = newAsset.ScriptKey.PubKey
id = newAsset.ID()
)
params := SetAssetSpentParams{
ScriptKey: scriptKey.SerializeCompressed(),
GenAssetID: id[:],
ScriptKey: scriptKey.SerializeCompressed(),
GenAssetID: id[:],
AnchorPoint: opBytes,
}
_, err := assetStore.db.SetAssetSpent(ctx, params)
_, err = assetStore.db.SetAssetSpent(ctx, params)
require.NoError(t, err)
}

Expand Down
18 changes: 10 additions & 8 deletions tapdb/sqlc/assets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tapdb/sqlc/queries/assets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,12 @@ WITH target_asset(asset_id) AS (
ON assets.script_key_id = script_keys.script_key_id
JOIN genesis_assets
ON assets.genesis_id = genesis_assets.gen_asset_id
JOIN managed_utxos utxos
ON assets.anchor_utxo_id = utxos.utxo_id AND
(utxos.outpoint = sqlc.narg('anchor_point') OR
sqlc.narg('anchor_point') IS NULL)
WHERE script_keys.tweaked_script_key = @script_key
AND genesis_assets.asset_id = @gen_asset_id
-- TODO(guggero): Fix this by disallowing multiple assets with the same
-- script key!
LIMIT 1
)
UPDATE assets
SET spent = TRUE
Expand Down
Loading