Skip to content

Commit acf5730

Browse files
committed
loopdb: add basic schema for asset deposits
1 parent 07af5c5 commit acf5730

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS asset_deposits;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
CREATE TABLE IF NOT EXISTS asset_deposits (
2+
deposit_id TEXT PRIMARY KEY,
3+
4+
-- protocol_version is the protocol version that the deposit was
5+
-- created with.
6+
protocol_version INTEGER NOT NULL,
7+
8+
-- created_at is the time at which the deposit was created.
9+
created_at TIMESTAMP NOT NULL,
10+
11+
-- asset_id is the asset that is being deposited.
12+
asset_id BLOB NOT NULL,
13+
14+
-- amount is the amount of the deposit in asset units.
15+
amount BIGINT NOT NULL,
16+
17+
-- client_script_pubkey is the key used for the deposit script path as well
18+
-- as the ephemeral key used for deriving the client's internal key.
19+
client_script_pubkey BLOB NOT NULL,
20+
21+
-- server_script_pubkey is the server's key that is used to construct the
22+
-- deposit spending HTLC.
23+
server_script_pubkey BLOB NOT NULL,
24+
25+
-- client_internal_pubkey is the key derived from the shared secret
26+
-- which is derived from the client's script key.
27+
client_internal_pubkey BLOB NOT NULL,
28+
29+
-- server_internal_pubkey is the server side public key that is used to
30+
-- construct the 2-of-2 MuSig2 anchor output that holds the deposited
31+
-- funds.
32+
server_internal_pubkey BLOB NOT NULL,
33+
34+
-- server_internal_key is the revealed private key corresponding to the
35+
-- server's internal public key. It is only revealed when the deposit is
36+
-- cooperatively withdrawn and therefore may be NULL. Note that the value
37+
-- may be encrypted.
38+
server_internal_key BYTEA,
39+
40+
-- expiry denotes the CSV delay at which funds at a specific static address
41+
-- can be swept back to the client.
42+
expiry INT NOT NULL,
43+
44+
-- client_key_family is the key family of the client's script public key
45+
-- from the client's lnd wallet.
46+
client_key_family INT NOT NULL,
47+
48+
-- client_key_index is the key index of the client's script public key from
49+
-- the client's lnd wallet.
50+
client_key_index INT NOT NULL,
51+
52+
-- addr is the TAP deposit address that the client should send the funds to.
53+
addr TEXT NOT NULL UNIQUE,
54+
55+
-- confirmation_height is the block height at which the deposit was
56+
-- confirmed on-chain.
57+
confirmation_height INT,
58+
59+
-- outpoint is the outpoint of the confirmed deposit.
60+
outpoint TEXT,
61+
62+
-- pk_script is the pkscript of the deposit anchor output.
63+
pk_script BLOB,
64+
65+
-- sweep_script_pubkey is the script key that will be used for the asset
66+
-- after the deposit is swept.
67+
sweep_script_pubkey BLOB,
68+
69+
-- sweep_internal_pubkey is the internal public key that will be used
70+
-- for the asset output after the deposit is swept.
71+
sweep_internal_pubkey BLOB
72+
);
73+
74+
-- asset_deposit_updates contains all the updates to an asset deposit.
75+
CREATE TABLE IF NOT EXISTS asset_deposit_updates (
76+
-- id is the auto incrementing primary key.
77+
id INTEGER PRIMARY KEY,
78+
79+
-- deposit_id is the unique identifier for the deposit.
80+
deposit_id TEXT NOT NULL REFERENCES asset_deposits(deposit_id),
81+
82+
-- update_state is the state of the deposit at the time of the update.
83+
update_state INT NOT NULL,
84+
85+
-- update_timestamp is the timestamp of the update.
86+
update_timestamp TIMESTAMP NOT NULL
87+
);
88+
89+
-- asset_deposit_leased_utxos contains all the UTXOs that were leased to a
90+
-- particular deposit. These leased UTXOs are used to fund the deposit timeout
91+
-- sweep transaction.
92+
CREATE TABLE IF NOT EXISTS asset_deposit_leased_utxos (
93+
-- id is the auto incrementing primary key.
94+
id INTEGER PRIMARY KEY,
95+
96+
-- deposit_id is the unique identifier for the deposit.
97+
deposit_id TEXT NOT NULL REFERENCES asset_deposits(deposit_id),
98+
99+
-- outpoint is the outpoint of the UTXO that was leased.
100+
outpoint TEXT NOT NULL
101+
);

loopdb/sqlc/models.go

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

0 commit comments

Comments
 (0)