Skip to content

Commit 7dbfda2

Browse files
committed
sqlc: deposit queries, models and migrations
1 parent 22a8f65 commit 7dbfda2

File tree

6 files changed

+315
-0
lines changed

6 files changed

+315
-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 deposits;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
27+
-- deposit_updates contains all the updates to a deposit.
28+
CREATE TABLE IF NOT EXISTS deposit_updates (
29+
-- id is the auto incrementing primary key.
30+
id INTEGER PRIMARY KEY,
31+
32+
-- deposit_id is the unique identifier for the deposit.
33+
deposit_id BLOB NOT NULL REFERENCES deposits(deposit_id),
34+
35+
-- update_state is the state of the deposit at the time of the update.
36+
update_state TEXT NOT NULL,
37+
38+
-- update_timestamp is the timestamp of the update.
39+
update_timestamp TIMESTAMP NOT NULL
40+
);

loopdb/sqlc/models.go

Lines changed: 17 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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
) VALUES (
10+
$1,
11+
$2,
12+
$3,
13+
$4,
14+
$5,
15+
$6
16+
);
17+
18+
-- name: UpdateDeposit :exec
19+
UPDATE deposits
20+
SET
21+
tx_hash = $2,
22+
out_index = $3,
23+
confirmation_height = $4
24+
WHERE
25+
deposits.deposit_id = $1;
26+
27+
-- name: InsertDepositUpdate :exec
28+
INSERT INTO deposit_updates (
29+
deposit_id,
30+
update_state,
31+
update_timestamp
32+
) VALUES (
33+
$1,
34+
$2,
35+
$3
36+
);
37+
38+
-- name: GetDeposit :one
39+
SELECT
40+
*
41+
FROM
42+
deposits
43+
WHERE
44+
deposit_id = $1;
45+
46+
-- name: AllDeposits :many
47+
SELECT
48+
*
49+
FROM
50+
deposits
51+
ORDER BY
52+
id ASC;
53+
54+
-- name: GetLatestDepositUpdate :one
55+
SELECT
56+
*
57+
FROM
58+
deposit_updates
59+
WHERE
60+
deposit_id = $1
61+
ORDER BY
62+
update_timestamp DESC
63+
LIMIT 1;

loopdb/sqlc/static_address_deposits.sql.go

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