· 5 years ago · Apr 24, 2020, 12:00 PM
1package data_store
2
3const (
4 createTransactionsTableStatement = `CREATE TABLE IF NOT EXISTS transactions (
5 height BIGINT SIGNED NOT NULL,
6 canonical INT SIGNED NOT NULL,
7 timestamp BIGINT SIGNED NOT NULL,
8 type TINYINT SIGNED NOT NULL,
9 sender BINARY(32),
10 recipient BINARY(32) NOT NULL,
11 data BINARY(32),
12 amount BIGINT NOT NULL,
13 amount_after_fees BIGINT NOT NULL,
14 sender_balance BIGINT,
15 recipient_balance BIGINT NOT NULL,
16 signature BINARY(64),
17 INDEX(sender(4)),
18 INDEX(recipient(4)),
19 INDEX(timestamp),
20 PRIMARY KEY (height, canonical))`
21 addTransactionStatement = `REPLACE INTO transactions(height, canonical, timestamp, type, sender, recipient, data, amount, amount_after_fees, sender_balance, recipient_balance, signature) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
22 createBlocksTableStatement = `CREATE TABLE IF NOT EXISTS blocks (
23 chain_version SMALLINT SIGNED NOT NULL,
24 height BIGINT SIGNED NOT NULL,
25 hash BINARY(32) NOT NULL,
26 previous_hash BINARY(32) NOT NULL,
27 cycle_length INT SIGNED NOT NULL,
28 start BIGINT SIGNED NOT NULL,
29 verification BIGINT SIGNED NOT NULL,
30 transaction_count INT SIGNED NOT NULL,
31 balance_list_hash BINARY(32) NOT NULL,
32 verifier BINARY(32) NOT NULL,
33 signature BINARY(64) NOT NULL,
34 PRIMARY KEY (height))`
35 addBlockStatement = `REPLACE INTO blocks(chain_version, height, hash, previous_hash, cycle_length, start, verification, transaction_count, balance_list_hash, verifier, signature) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
36 createCycleEventsTableStatement = `CREATE TABLE IF NOT EXISTS cycle_events (
37 height BIGINT SIGNED NOT NULL,
38 joined_id BINARY(32),
39 left_id BINARY(32),
40 PRIMARY KEY (height))`
41 addCycleEventStatement = `REPLACE INTO cycle_events(height, joined_id, left_id) VALUES(?, ?, ?)`
42 highestBlockStatement = `SELECT COALESCE(MAX(height), 0) AS max_height FROM blocks`
43)