Skip to content

Commit 6162e05

Browse files
committed
tapdb: add proof_delivery_complete and position to transfer outputs
Add the `proof_delivery_complete` and `position` columns to the `asset_transfer_outputs` table. The `position` column indicates the position of the output in the transfer output list. The position and anchor outpoint uniquely identify a transfer output. This change updates the row insertion and retrieval SQL statements for this table. Additionally, new SQL statements are included for modifying these new columns.
1 parent d70bccd commit 6162e05

File tree

7 files changed

+96
-9
lines changed

7 files changed

+96
-9
lines changed

tapdb/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// daemon.
2323
//
2424
// NOTE: This MUST be updated when a new migration is added.
25-
LatestMigrationVersion = 21
25+
LatestMigrationVersion = 22
2626
)
2727

2828
// MigrationTarget is a functional option that can be passed to applyMigrations
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Remove the unique constraint on the `transfer_id` and `position` columns in
2+
-- the `asset_transfer_outputs` table.
3+
DROP INDEX asset_transfer_outputs_transfer_id_position_unique;
4+
5+
-- Remove the `proof_delivery_complete` column from the `asset_transfer_outputs`
6+
-- table.
7+
ALTER TABLE asset_transfer_outputs DROP COLUMN proof_delivery_complete;
8+
9+
-- Remove the `position` column from the `asset_transfer_outputs` table.
10+
ALTER TABLE asset_transfer_outputs DROP COLUMN position;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Add a column to track if the proof has been delivered for an asset transfer
2+
-- output.
3+
ALTER TABLE asset_transfer_outputs
4+
ADD COLUMN proof_delivery_complete BOOL;
5+
6+
-- Add column `position` which indicates the index of the output in the list of
7+
-- outputs for a given transfer. This index position in conjunction with the
8+
-- transfer id can be used to uniquely identify a transfer output.
9+
--
10+
-- We'll be inserting an actual value in the next query, so we just start
11+
-- with -1.
12+
ALTER TABLE asset_transfer_outputs
13+
ADD COLUMN position INTEGER NOT NULL DEFAULT -1;
14+
15+
-- Update the position to be the same as the output id for existing entries.
16+
-- We'll use the position integer as a uniquely identifiable number of an output
17+
-- within a transfer, so setting the default to the output_id is just to make
18+
-- sure we have a unique value that also satisfies the unique constraint we add
19+
-- below.
20+
UPDATE asset_transfer_outputs SET position = CAST(output_id AS INTEGER)
21+
WHERE position = -1;
22+
23+
-- We enforce a unique constraint such that for a given transfer, the position
24+
-- of an output is unique.
25+
CREATE UNIQUE INDEX asset_transfer_outputs_transfer_id_position_unique
26+
ON asset_transfer_outputs (
27+
transfer_id, position
28+
);

tapdb/sqlc/models.go

Lines changed: 2 additions & 0 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 & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/queries/transfers.sql

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,24 @@ INSERT INTO asset_transfer_outputs (
2323
amount, serialized_witnesses, split_commitment_root_hash,
2424
split_commitment_root_value, proof_suffix, num_passive_assets,
2525
output_type, proof_courier_addr, asset_version, lock_time,
26-
relative_lock_time
26+
relative_lock_time, proof_delivery_complete, position
2727
) VALUES (
28-
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
28+
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
2929
);
3030

31+
-- name: SetTransferOutputProofDeliveryStatus :exec
32+
WITH target(output_id) AS (
33+
SELECT output_id
34+
FROM asset_transfer_outputs output
35+
JOIN managed_utxos
36+
ON output.anchor_utxo = managed_utxos.utxo_id
37+
WHERE managed_utxos.outpoint = @serialized_anchor_outpoint
38+
AND output.position = @position
39+
)
40+
UPDATE asset_transfer_outputs
41+
SET proof_delivery_complete = @delivery_complete
42+
WHERE output_id = (SELECT output_id FROM target);
43+
3144
-- name: QueryAssetTransfers :many
3245
SELECT
3346
id, height_hint, txns.txid, transfer_time_unix
@@ -55,8 +68,8 @@ ORDER BY input_id;
5568
SELECT
5669
output_id, proof_suffix, amount, serialized_witnesses, script_key_local,
5770
split_commitment_root_hash, split_commitment_root_value, num_passive_assets,
58-
output_type, proof_courier_addr, asset_version, lock_time,
59-
relative_lock_time,
71+
output_type, proof_courier_addr, proof_delivery_complete, position,
72+
asset_version, lock_time, relative_lock_time,
6073
utxos.utxo_id AS anchor_utxo_id,
6174
utxos.outpoint AS anchor_outpoint,
6275
utxos.amt_sats AS anchor_value,

tapdb/sqlc/transfers.sql.go

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

0 commit comments

Comments
 (0)