-
Notifications
You must be signed in to change notification settings - Fork 41
/
schema.sql
238 lines (213 loc) · 5.18 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
create table if not exists blocks
(
id bigint not null
constraint blocks_pkey
primary key,
date_created timestamp with time zone,
trie text,
parent_hash text,
witness_id bigint,
witness_address text,
hash text,
size integer,
transactions integer,
confirmed boolean default false not null
)
;
create table if not exists transactions
(
date_created timestamp with time zone,
block bigint
constraint transactions_blocks_id_fk
references blocks
on update cascade on delete cascade,
hash text not null
constraint transactions_hash_pk
primary key,
confirmed boolean default false not null,
contract_data jsonb default '{}'::jsonb not null,
contract_type integer default '-1'::integer not null,
owner_address text default ''::text not null,
to_address text default ''::text not null,
data text default ''::text not null
)
;
create index if not exists transactions_date_created_index
on transactions (date_created desc)
;
create index if not exists transactions_block_hash_index
on transactions (block, hash)
;
create table if not exists vote_witness_contract
(
id uuid not null
constraint vote_witness_contract_id_pk
primary key,
transaction text,
voter_address text,
candidate_address text,
votes bigint,
date_created timestamp with time zone,
block bigint
)
;
create table if not exists participate_asset_issue
(
id uuid not null
constraint participate_asset_issue_id_pk
primary key,
transaction_hash text,
block bigint,
date_created timestamp with time zone,
owner_address text,
to_address text,
token_name text,
amount bigint
)
;
create table if not exists accounts
(
address text not null
constraint accounts_pkey
primary key,
name text,
balance bigint,
token_balances jsonb,
date_created timestamp with time zone default now() not null,
date_updated timestamp with time zone default now() not null,
date_synced timestamp with time zone default now() not null,
power bigint default 0 not null
)
;
create table if not exists asset_issue_contract
(
id uuid
constraint asset_issue_contract_id_pk
unique,
owner_address text,
name text,
total_supply bigint,
trx_num integer,
num integer,
date_end timestamp with time zone,
date_start timestamp with time zone,
decay_ratio integer,
vote_score integer,
description text,
url text,
block bigint,
transaction text,
date_created timestamp with time zone default now(),
frozen jsonb default '[]'::jsonb not null,
abbr text default ''::text
)
;
create table if not exists address_balance
(
address text,
token text,
balance bigint,
constraint address_balance_address_token_pk
unique (address, token)
)
;
create table if not exists witness_create_contract
(
address text not null
constraint witness_create_contract_pkey
primary key,
url text
)
;
create table if not exists ip_geo
(
ip text,
city text,
country text,
lat numeric,
lng numeric
)
;
create table if not exists sr_account
(
address text not null
constraint sr_account_pkey
primary key,
github_link text
)
;
CREATE SCHEMA IF NOT EXISTS analytics;
create table if not exists analytics.vote_snapshot
(
id bigserial not null
constraint vote_snapshot_pkey
primary key,
address text not null,
timestamp timestamp with time zone default now() not null,
votes bigint default 0 not null
)
;
create table if not exists transfers
(
id uuid not null
constraint transfers_pkey
primary key,
date_created timestamp with time zone,
transfer_from_address text,
transfer_to_address text,
amount bigint default 0,
token_name text default 'TRX'::text,
block bigint
constraint transfers_blocks_id_fk
references blocks
on update cascade on delete cascade,
transaction_hash text not null,
confirmed boolean default false not null
)
;
create index if not exists transfers_transfer_from_address_transfer_to_address_date_cre
on transfers (transfer_from_address asc, transfer_to_address asc, date_created desc)
;
create index if not exists transfers_block_hash_index
on transfers (block, transaction_hash)
;
create index if not exists transfers_date_created_index
on transfers (date_created desc)
;
create index if not exists transfers_transfer_from_address_date_created_index
on transfers (transfer_from_address asc, date_created desc)
;
create index if not exists transfers_transfer_to_address_date_created_index
on transfers (transfer_to_address asc, date_created desc)
;
create index if not exists transfers_transfer_from_address_index
on transfers (transfer_from_address)
;
create index if not exists transfers_transfer_to_address_index
on transfers (transfer_to_address)
;
create table if not exists analytics.requests
(
id uuid not null,
timestamp timestamp with time zone default now() not null,
host text default ''::text,
uri text default ''::text,
referer text default ''::text not null,
ip text default ''::text not null
)
;
create table if not exists trx_request
(
address text not null
constraint trx_request_pkey
primary key,
ip text not null,
date_created timestamp with time zone default now() not null
)
;
create table if not exists funds
(
id int,
address text
)
;