Skip to content

Commit 401ff43

Browse files
committed
sqlc: deposit queries, models and migrations
1 parent 3891d5d commit 401ff43

File tree

7 files changed

+332
-1
lines changed

7 files changed

+332
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS deposits;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- deposits stores historic and unspent static address outputs.
2+
CREATE TABLE IF NOT EXISTS deposits (
3+
-- id is the auto-incrementing primary key for a static address.
4+
id INTEGER PRIMARY KEY,
5+
6+
-- deposit_id is the unique identifier for the deposit.
7+
deposit_id BLOB NOT NULL UNIQUE,
8+
9+
-- tx_hash is the transaction hash of the deposit.
10+
tx_hash BYTEA NOT NULL,
11+
12+
-- output_index is the index of the output in the transaction.
13+
out_index INT NOT NULL,
14+
15+
-- amount is the amount of the deposit.
16+
amount BIGINT NOT NULL,
17+
18+
-- confirmation_height is the absolute height at which the deposit was
19+
-- confirmed.
20+
confirmation_height BIGINT NOT NULL,
21+
22+
-- timeout_sweep_pk_script is the public key script that will be used to
23+
-- sweep the deposit after has expired.
24+
timeout_sweep_pk_script BYTEA NOT NULL,
25+
26+
-- expiry_sweep_txid is the transaction id of the expiry sweep.
27+
expiry_sweep_txid BLOB
28+
);
29+
30+
-- deposit_updates contains all the updates to a deposit.
31+
CREATE TABLE IF NOT EXISTS deposit_updates (
32+
-- id is the auto incrementing primary key.
33+
id INTEGER PRIMARY KEY,
34+
35+
-- deposit_id is the unique identifier for the deposit.
36+
deposit_id BLOB NOT NULL REFERENCES deposits(deposit_id),
37+
38+
-- update_state is the state of the deposit at the time of the update.
39+
update_state TEXT NOT NULL,
40+
41+
-- update_timestamp is the timestamp of the update.
42+
update_timestamp TIMESTAMP NOT NULL
43+
);

loopdb/sqlc/models.go

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

loopdb/sqlc/querier.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
-- name: CreateDeposit :exec
2+
INSERT INTO deposits (
3+
deposit_id,
4+
tx_hash,
5+
out_index,
6+
amount,
7+
confirmation_height,
8+
timeout_sweep_pk_script,
9+
expiry_sweep_txid
10+
) VALUES (
11+
$1,
12+
$2,
13+
$3,
14+
$4,
15+
$5,
16+
$6,
17+
$7
18+
);
19+
20+
-- name: UpdateDeposit :exec
21+
UPDATE deposits
22+
SET
23+
tx_hash = $2,
24+
out_index = $3,
25+
confirmation_height = $4,
26+
expiry_sweep_txid = $5
27+
WHERE
28+
deposits.deposit_id = $1;
29+
30+
-- name: InsertDepositUpdate :exec
31+
INSERT INTO deposit_updates (
32+
deposit_id,
33+
update_state,
34+
update_timestamp
35+
) VALUES (
36+
$1,
37+
$2,
38+
$3
39+
);
40+
41+
-- name: GetDeposit :one
42+
SELECT
43+
*
44+
FROM
45+
deposits
46+
WHERE
47+
deposit_id = $1;
48+
49+
-- name: AllDeposits :many
50+
SELECT
51+
*
52+
FROM
53+
deposits
54+
ORDER BY
55+
id ASC;
56+
57+
-- name: GetLatestDepositUpdate :one
58+
SELECT
59+
*
60+
FROM
61+
deposit_updates
62+
WHERE
63+
deposit_id = $1
64+
ORDER BY
65+
update_timestamp DESC
66+
LIMIT 1;

loopdb/sqlc/static_address_deposits.sql.go

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

loopdb/sqlc/static_addresses.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)