Skip to content

Commit 760442b

Browse files
committed
loopdb: add basic schema for asset deposits
1 parent 8ad77bc commit 760442b

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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_addr is the address we'll use to sweep back the deposit to if it
66+
-- has timed out or withdrawn cooperatively.
67+
sweep_addr TEXT
68+
);
69+
70+
-- asset_deposit_updates contains all the updates to an asset deposit.
71+
CREATE TABLE IF NOT EXISTS asset_deposit_updates (
72+
-- id is the auto incrementing primary key.
73+
id INTEGER PRIMARY KEY,
74+
75+
-- deposit_id is the unique identifier for the deposit.
76+
deposit_id TEXT NOT NULL REFERENCES asset_deposits(deposit_id),
77+
78+
-- update_state is the state of the deposit at the time of the update.
79+
update_state INT NOT NULL,
80+
81+
-- update_timestamp is the timestamp of the update.
82+
update_timestamp TIMESTAMP NOT NULL
83+
);
84+
85+
-- asset_deposit_leased_utxos contains all the UTXOs that were leased to a
86+
-- particular deposit. These leased UTXOs are used to fund the deposit timeout
87+
-- sweep transaction.
88+
CREATE TABLE IF NOT EXISTS asset_deposit_leased_utxos (
89+
-- id is the auto incrementing primary key.
90+
id INTEGER PRIMARY KEY,
91+
92+
-- deposit_id is the unique identifier for the deposit.
93+
deposit_id TEXT NOT NULL REFERENCES asset_deposits(deposit_id),
94+
95+
-- outpoint is the outpoint of the UTXO that was leased.
96+
outpoint TEXT NOT NULL
97+
);

loopdb/sqlc/models.go

Lines changed: 34 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)