Skip to content

Commit 88532c5

Browse files
committed
staticaddr: deposit sql queries and models
1 parent 3256e52 commit 88532c5

File tree

6 files changed

+323
-1
lines changed

6 files changed

+323
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
-- time_out_sweep_pk_script is the public key script that will be used to
23+
-- sweep the deposit after has expired.
24+
time_out_sweep_pk_script BYTEA NOT NULL
25+
);
26+
27+
CREATE INDEX IF NOT EXISTS deposits_deposit_id_idx ON deposits(deposit_id);
28+
29+
-- deposit_updates contains all the updates to a deposit.
30+
CREATE TABLE IF NOT EXISTS deposit_updates (
31+
-- id is the auto incrementing primary key.
32+
id INTEGER PRIMARY KEY,
33+
34+
-- deposit_id is the unique identifier for the deposit.
35+
deposit_id BLOB NOT NULL REFERENCES deposits(deposit_id),
36+
37+
-- update_state is the state of the deposit at the time of the update.
38+
update_state TEXT NOT NULL,
39+
40+
-- update_timestamp is the timestamp of the update.
41+
update_timestamp TIMESTAMP NOT NULL
42+
);

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.

loopdb/sqlc/queries/static_addresses.sql

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,67 @@ INSERT INTO static_addresses (
2222
$5,
2323
$6,
2424
$7
25-
);
25+
);
26+
27+
-- name: CreateDeposit :exec
28+
INSERT INTO deposits (
29+
deposit_id,
30+
tx_hash,
31+
out_index,
32+
amount,
33+
confirmation_height,
34+
time_out_sweep_pk_script
35+
) VALUES (
36+
$1,
37+
$2,
38+
$3,
39+
$4,
40+
$5,
41+
$6
42+
);
43+
44+
-- name: UpdateDeposit :exec
45+
UPDATE deposits
46+
SET
47+
tx_hash = $2,
48+
out_index = $3,
49+
confirmation_height = $4
50+
WHERE
51+
deposits.deposit_id = $1;
52+
53+
-- name: InsertDepositUpdate :exec
54+
INSERT INTO deposit_updates (
55+
deposit_id,
56+
update_state,
57+
update_timestamp
58+
) VALUES (
59+
$1,
60+
$2,
61+
$3
62+
);
63+
64+
-- name: GetDeposit :one
65+
SELECT
66+
*
67+
FROM
68+
deposits
69+
WHERE
70+
deposit_id = $1;
71+
72+
-- name: AllDeposits :many
73+
SELECT
74+
*
75+
FROM
76+
deposits
77+
ORDER BY
78+
id ASC;
79+
80+
-- name: GetDepositUpdates :many
81+
SELECT
82+
deposit_updates.*
83+
FROM
84+
deposit_updates
85+
WHERE
86+
deposit_id = $1
87+
ORDER BY
88+
id ASC;

loopdb/sqlc/static_addresses.sql.go

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