-
Notifications
You must be signed in to change notification settings - Fork 16
/
schema.sql
149 lines (140 loc) · 5.44 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright 2020 bitfly gmbh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
drop table blocks;
drop table snarkjobs;
drop table feetransfers;
drop table userjobs;
drop table accounts;
drop table accounttransactions;
drop table daemonstatus;
drop table statistics;
create table if not exists blocks
(
statehash varchar(400) not null,
canonical bool not null,
previousstatehash varchar(400) not null,
snarkedledgerhash varchar(400) not null,
stagedledgerhash varchar(400) not null,
coinbase numeric not null,
creator varchar(200) not null,
slot int not null,
height int not null,
epoch int not null,
ts timestamp not null,
totalcurrency numeric not null,
usercommandscount int not null,
snarkjobscount int not null,
feetransfercount int not null,
primary key (statehash)
);
create index idx_blocks_creator on blocks (creator);
create index idx_blocks_ts on blocks (ts);
create index idx_blocks_height on blocks (height);
create table if not exists snarkjobs
(
blockstatehash varchar(400) not null,
canonical bool not null,
index int not null,
jobids int[] not null,
prover varchar(200) not null,
fee int not null,
primary key (blockstatehash, index)
);
create index idx_snarkjobs_prover on snarkjobs (prover);
create table if not exists feetransfers
(
blockstatehash varchar(400) not null,
canonical bool not null,
index int not null,
recipient varchar(200) not null,
fee int not null,
primary key (blockstatehash, index)
);
create index idx_feetransfers_recipient on feetransfers (recipient);
create table if not exists userjobs
(
blockstatehash varchar(400) not null,
canonical bool not null,
index int not null,
id text not null,
sender varchar(200) not null,
recipient varchar(200) not null,
memo varchar(200) not null,
fee numeric not null,
amount numeric not null,
nonce varchar(200) not null,
delegation bool not null,
primary key (blockstatehash, index)
);
create index idx_userjobs_id on userjobs (id);
create table if not exists accounts
(
publickey varchar(200) not null primary key,
balance numeric not null,
nonce int not null,
receiptchainhash varchar(400) not null,
delegate varchar(200) not null,
votingfor varchar(200) not null,
txsent int not null,
txreceived int not null,
blocksproposed int not null,
snarkjobs int not null,
firstseen timestamp not null,
lastseen timestamp not null
);
create index idx_accounts_firstseen on accounts (firstseen);
create index idx_accounts_lastseen on accounts (lastseen);
create index idx_accounts_balance on accounts (balance);
create index idx_accounts_delegate on accounts (delegate);
create index idx_accounts_txsent on accounts (txsent);
create index idx_accounts_txreceived on accounts (txreceived);
create index idx_accounts_blocksproposed on accounts (blocksproposed);
create index idx_accounts_snarkjobs on accounts (snarkjobs);
create table if not exists accounttransactions
(
publickey varchar(200) not null,
blockstatehash varchar(400) not null,
canonical bool not null,
id text not null,
ts timestamp not null,
primary key (publickey, ts, blockstatehash, id)
);
create index idx_accounttransactions_blockstatehash on accounttransactions (blockstatehash);
create table if not exists daemonstatus
(
ts timestamp not null primary key,
blockchainlength int not null,
commitid varchar(200) not null,
epochduration int not null,
slotduration int not null,
slotsperepoch int not null,
consensusmechanism varchar(200) not null,
highestblocklengthreceived int not null,
ledgermerkleroot varchar(400) not null,
numaccounts int not null,
peers text[] not null,
peerscount int not null,
statehash varchar(400) not null,
syncstatus varchar(200) not null,
uptime int not null
);
create table if not exists statistics
(
indicator varchar(50) not null,
ts timestamp not null,
value numeric not null,
primary key (indicator, ts)
);