Skip to content

Commit

Permalink
Merge pull request #984 from lightninglabs/set-spent-duplicate-key
Browse files Browse the repository at this point in the history
tapdb: add anchor point to SetSpent, remove LIMIT 1
  • Loading branch information
Roasbeef authored Jul 1, 2024
2 parents 9bd0b75 + 4113896 commit 88012a5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
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

0 comments on commit 88012a5

Please sign in to comment.