-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathstructure.sql
More file actions
1449 lines (983 loc) · 46.1 KB
/
Copy pathstructure.sql
File metadata and controls
1449 lines (983 loc) · 46.1 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
--
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
--
-- Name: check_block_imported_at(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.check_block_imported_at() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF NEW.imported_at IS NOT NULL THEN
IF EXISTS (
SELECT 1
FROM eth_blocks
WHERE block_number < NEW.block_number
AND imported_at IS NULL
LIMIT 1
) THEN
RAISE EXCEPTION 'Previous block not yet imported';
END IF;
END IF;
RETURN NEW;
END;
$$;
--
-- Name: check_block_order(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.check_block_order() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF NEW.is_genesis_block = false AND
NEW.block_number <> (SELECT MAX(block_number) + 1 FROM eth_blocks) THEN
RAISE EXCEPTION 'Block number is not sequential';
END IF;
IF NEW.is_genesis_block = false AND
NEW.parent_blockhash <> (SELECT blockhash FROM eth_blocks WHERE block_number = NEW.block_number - 1) THEN
RAISE EXCEPTION 'Parent block hash does not match the parent''s block hash';
END IF;
RETURN NEW;
END;
$$;
--
-- Name: check_block_order_on_update(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.check_block_order_on_update() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF NEW.imported_at IS NOT NULL AND NEW.state_hash IS NULL THEN
RAISE EXCEPTION 'state_hash must be set when imported_at is set';
END IF;
IF (SELECT MAX(block_number) FROM eth_blocks) IS NOT NULL THEN
IF NEW.parent_state_hash <> (SELECT state_hash FROM eth_blocks WHERE block_number = (SELECT MAX(block_number) FROM eth_blocks WHERE block_number < NEW.block_number) AND imported_at IS NOT NULL) THEN
RAISE EXCEPTION 'Parent state hash does not match the state hash of the previous block';
END IF;
END IF;
RETURN NEW;
END;
$$;
--
-- Name: check_ethscription_order_and_sequence(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.check_ethscription_order_and_sequence() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF NEW.block_number < (SELECT MAX(block_number) FROM ethscriptions) OR
(NEW.block_number = (SELECT MAX(block_number) FROM ethscriptions) AND NEW.transaction_index <= (SELECT MAX(transaction_index) FROM ethscriptions WHERE block_number = NEW.block_number)) THEN
RAISE EXCEPTION 'Ethscriptions must be created in order';
END IF;
NEW.ethscription_number := (SELECT COALESCE(MAX(ethscription_number), -1) + 1 FROM ethscriptions);
RETURN NEW;
END;
$$;
--
-- Name: delete_later_blocks(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.delete_later_blocks() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM eth_blocks WHERE block_number > OLD.block_number;
RETURN OLD;
END;
$$;
--
-- Name: update_current_owner(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_current_owner() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
latest_ownership_version RECORD;
BEGIN
IF TG_OP = 'INSERT' THEN
SELECT INTO latest_ownership_version *
FROM ethscription_ownership_versions
WHERE ethscription_transaction_hash = NEW.ethscription_transaction_hash
ORDER BY block_number DESC, transaction_index DESC, transfer_index DESC
LIMIT 1;
UPDATE ethscriptions
SET current_owner = latest_ownership_version.current_owner,
previous_owner = latest_ownership_version.previous_owner,
updated_at = NOW()
WHERE transaction_hash = NEW.ethscription_transaction_hash;
ELSIF TG_OP = 'DELETE' THEN
SELECT INTO latest_ownership_version *
FROM ethscription_ownership_versions
WHERE ethscription_transaction_hash = OLD.ethscription_transaction_hash
AND id != OLD.id
ORDER BY block_number DESC, transaction_index DESC, transfer_index DESC
LIMIT 1;
UPDATE ethscriptions
SET current_owner = latest_ownership_version.current_owner,
previous_owner = latest_ownership_version.previous_owner,
updated_at = NOW()
WHERE transaction_hash = OLD.ethscription_transaction_hash;
END IF;
RETURN NULL;
END;
$$;
--
-- Name: update_token_balances_and_supply(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_token_balances_and_supply() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
latest_token_state RECORD;
BEGIN
IF TG_OP = 'INSERT' THEN
SELECT INTO latest_token_state *
FROM token_states
WHERE deploy_ethscription_transaction_hash = NEW.deploy_ethscription_transaction_hash
ORDER BY block_number DESC
LIMIT 1;
UPDATE tokens
SET balances = COALESCE(latest_token_state.balances, '{}'::jsonb),
total_supply = COALESCE(latest_token_state.total_supply, 0),
updated_at = NOW()
WHERE deploy_ethscription_transaction_hash = NEW.deploy_ethscription_transaction_hash;
ELSIF TG_OP = 'DELETE' THEN
SELECT INTO latest_token_state *
FROM token_states
WHERE deploy_ethscription_transaction_hash = OLD.deploy_ethscription_transaction_hash
AND id != OLD.id
ORDER BY block_number DESC
LIMIT 1;
UPDATE tokens
SET balances = COALESCE(latest_token_state.balances, '{}'::jsonb),
total_supply = COALESCE(latest_token_state.total_supply, 0),
updated_at = NOW()
WHERE deploy_ethscription_transaction_hash = OLD.deploy_ethscription_transaction_hash;
END IF;
RETURN NULL;
END;
$$;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.ar_internal_metadata (
key character varying NOT NULL,
value character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
--
-- Name: eth_blocks; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.eth_blocks (
id bigint NOT NULL,
block_number bigint NOT NULL,
"timestamp" bigint NOT NULL,
blockhash character varying NOT NULL,
parent_blockhash character varying NOT NULL,
imported_at timestamp(6) without time zone,
state_hash character varying,
parent_state_hash character varying,
is_genesis_block boolean NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_1c105acdac CHECK (((parent_blockhash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_319237323b CHECK (((state_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_7126b7c9d3 CHECK (((parent_state_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_7e9881ece2 CHECK (((blockhash)::text ~ '^0x[a-f0-9]{64}$'::text))
);
--
-- Name: eth_blocks_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.eth_blocks_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: eth_blocks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.eth_blocks_id_seq OWNED BY public.eth_blocks.id;
--
-- Name: eth_transactions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.eth_transactions (
id bigint NOT NULL,
transaction_hash character varying NOT NULL,
block_number bigint NOT NULL,
block_timestamp bigint NOT NULL,
block_blockhash character varying NOT NULL,
from_address character varying NOT NULL,
to_address character varying,
input text NOT NULL,
transaction_index bigint NOT NULL,
status integer,
logs jsonb DEFAULT '[]'::jsonb NOT NULL,
created_contract_address character varying,
gas_price numeric NOT NULL,
gas_used bigint NOT NULL,
transaction_fee numeric NOT NULL,
value numeric NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_37ed5d6017 CHECK (((to_address)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_4250f2c315 CHECK (((block_blockhash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_9cdbd3b1ad CHECK (((transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_a4d3f41974 CHECK (((from_address)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_d460e80110 CHECK (((created_contract_address)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT contract_to_check CHECK ((((created_contract_address IS NULL) AND (to_address IS NOT NULL)) OR ((created_contract_address IS NOT NULL) AND (to_address IS NULL)))),
CONSTRAINT status_check CHECK ((((block_number <= 4370000) AND (status IS NULL)) OR ((block_number > 4370000) AND (status = 1))))
);
--
-- Name: eth_transactions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.eth_transactions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: eth_transactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.eth_transactions_id_seq OWNED BY public.eth_transactions.id;
--
-- Name: ethscription_ownership_versions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.ethscription_ownership_versions (
id bigint NOT NULL,
transaction_hash character varying NOT NULL,
ethscription_transaction_hash character varying NOT NULL,
transfer_index bigint NOT NULL,
block_number bigint NOT NULL,
block_blockhash character varying NOT NULL,
transaction_index bigint NOT NULL,
block_timestamp bigint NOT NULL,
current_owner character varying NOT NULL,
previous_owner character varying NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_0401bc8d3b CHECK (((transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_073cb8a4e9 CHECK (((current_owner)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_3c5af30513 CHECK (((block_blockhash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_b5b3ce91a9 CHECK (((previous_owner)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_f8a9e94d3c CHECK (((ethscription_transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text))
);
--
-- Name: ethscription_ownership_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.ethscription_ownership_versions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: ethscription_ownership_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.ethscription_ownership_versions_id_seq OWNED BY public.ethscription_ownership_versions.id;
--
-- Name: ethscription_transfers; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.ethscription_transfers (
id bigint NOT NULL,
ethscription_transaction_hash character varying NOT NULL,
transaction_hash character varying NOT NULL,
from_address character varying NOT NULL,
to_address character varying NOT NULL,
block_number bigint NOT NULL,
block_timestamp bigint NOT NULL,
block_blockhash character varying NOT NULL,
event_log_index bigint,
transfer_index bigint NOT NULL,
transaction_index bigint NOT NULL,
enforced_previous_owner character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_1c9802c481 CHECK (((enforced_previous_owner)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_448edb0194 CHECK (((block_blockhash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_7959eeae60 CHECK (((from_address)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_7f4ef1507d CHECK (((transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_a138317254 CHECK (((to_address)::text ~ '^0x[a-f0-9]{40}$'::text))
);
--
-- Name: ethscription_transfers_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.ethscription_transfers_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: ethscription_transfers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.ethscription_transfers_id_seq OWNED BY public.ethscription_transfers.id;
--
-- Name: ethscriptions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.ethscriptions (
id bigint NOT NULL,
transaction_hash character varying NOT NULL,
block_number bigint NOT NULL,
transaction_index bigint NOT NULL,
block_timestamp bigint NOT NULL,
block_blockhash character varying NOT NULL,
event_log_index bigint,
ethscription_number bigint NOT NULL,
creator character varying NOT NULL,
initial_owner character varying NOT NULL,
current_owner character varying NOT NULL,
previous_owner character varying NOT NULL,
content_uri text NOT NULL,
content_sha character varying NOT NULL,
esip6 boolean NOT NULL,
mimetype character varying(1000) NOT NULL,
media_type character varying(1000) NOT NULL,
mime_subtype character varying(1000) NOT NULL,
gas_price numeric NOT NULL,
gas_used bigint NOT NULL,
transaction_fee numeric NOT NULL,
value numeric NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_52497428f2 CHECK (((previous_owner)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_528fcbfbaa CHECK (((content_sha)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_6f8922831e CHECK (((current_owner)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_788fa87594 CHECK (((block_blockhash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_84591e2730 CHECK (((transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_b577b97822 CHECK (((creator)::text ~ '^0x[a-f0-9]{40}$'::text)),
CONSTRAINT chk_rails_df21fdbe02 CHECK (((initial_owner)::text ~ '^0x[a-f0-9]{40}$'::text))
);
--
-- Name: ethscriptions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.ethscriptions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: ethscriptions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.ethscriptions_id_seq OWNED BY public.ethscriptions.id;
--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.schema_migrations (
version character varying NOT NULL
);
--
-- Name: token_items; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.token_items (
id bigint NOT NULL,
ethscription_transaction_hash character varying NOT NULL,
deploy_ethscription_transaction_hash character varying NOT NULL,
block_number bigint NOT NULL,
transaction_index bigint NOT NULL,
token_item_id bigint NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_37f43f9259 CHECK (((deploy_ethscription_transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_4a492d2c53 CHECK ((token_item_id > 0)),
CONSTRAINT chk_rails_4e045edbe2 CHECK (((ethscription_transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text))
);
--
-- Name: token_items_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.token_items_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: token_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.token_items_id_seq OWNED BY public.token_items.id;
--
-- Name: token_states; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.token_states (
id bigint NOT NULL,
block_number bigint NOT NULL,
block_timestamp bigint NOT NULL,
block_blockhash character varying NOT NULL,
deploy_ethscription_transaction_hash character varying NOT NULL,
balances jsonb DEFAULT '{}'::jsonb NOT NULL,
total_supply bigint DEFAULT 0 NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
CONSTRAINT chk_rails_8b7e9525c6 CHECK (((deploy_ethscription_transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_97e78ee6f4 CHECK (((block_blockhash)::text ~ '^0x[a-f0-9]{64}$'::text))
);
--
-- Name: token_states_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.token_states_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: token_states_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.token_states_id_seq OWNED BY public.token_states.id;
--
-- Name: tokens; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.tokens (
id bigint NOT NULL,
deploy_ethscription_transaction_hash character varying NOT NULL,
deploy_block_number bigint NOT NULL,
deploy_transaction_index bigint NOT NULL,
protocol character varying(1000) NOT NULL,
tick character varying(1000) NOT NULL,
max_supply bigint NOT NULL,
total_supply bigint DEFAULT 0 NOT NULL,
mint_amount bigint NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
balances jsonb DEFAULT '{}'::jsonb NOT NULL,
CONSTRAINT chk_rails_31c1808af4 CHECK (((tick)::text ~ '^[[:alnum:]p{Emoji_Presentation}]+$'::text)),
CONSTRAINT chk_rails_3458514b65 CHECK (((deploy_ethscription_transaction_hash)::text ~ '^0x[a-f0-9]{64}$'::text)),
CONSTRAINT chk_rails_3d55d7040f CHECK (((max_supply % mint_amount) = 0)),
CONSTRAINT chk_rails_53ece3f224 CHECK ((total_supply <= max_supply)),
CONSTRAINT chk_rails_596664ed3b CHECK ((total_supply >= 0)),
CONSTRAINT chk_rails_b41faadd12 CHECK ((mint_amount > 0)),
CONSTRAINT chk_rails_e954152758 CHECK ((max_supply > 0)),
CONSTRAINT chk_rails_f38f6eac6d CHECK (((protocol)::text ~ '^[a-z0-9-]+$'::text))
);
--
-- Name: tokens_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.tokens_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: tokens_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.tokens_id_seq OWNED BY public.tokens.id;
--
-- Name: eth_blocks id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.eth_blocks ALTER COLUMN id SET DEFAULT nextval('public.eth_blocks_id_seq'::regclass);
--
-- Name: eth_transactions id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.eth_transactions ALTER COLUMN id SET DEFAULT nextval('public.eth_transactions_id_seq'::regclass);
--
-- Name: ethscription_ownership_versions id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ethscription_ownership_versions ALTER COLUMN id SET DEFAULT nextval('public.ethscription_ownership_versions_id_seq'::regclass);
--
-- Name: ethscription_transfers id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ethscription_transfers ALTER COLUMN id SET DEFAULT nextval('public.ethscription_transfers_id_seq'::regclass);
--
-- Name: ethscriptions id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ethscriptions ALTER COLUMN id SET DEFAULT nextval('public.ethscriptions_id_seq'::regclass);
--
-- Name: token_items id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.token_items ALTER COLUMN id SET DEFAULT nextval('public.token_items_id_seq'::regclass);
--
-- Name: token_states id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.token_states ALTER COLUMN id SET DEFAULT nextval('public.token_states_id_seq'::regclass);
--
-- Name: tokens id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tokens ALTER COLUMN id SET DEFAULT nextval('public.tokens_id_seq'::regclass);
--
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
--
-- Name: eth_blocks eth_blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.eth_blocks
ADD CONSTRAINT eth_blocks_pkey PRIMARY KEY (id);
--
-- Name: eth_transactions eth_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.eth_transactions
ADD CONSTRAINT eth_transactions_pkey PRIMARY KEY (id);
--
-- Name: ethscription_ownership_versions ethscription_ownership_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ethscription_ownership_versions
ADD CONSTRAINT ethscription_ownership_versions_pkey PRIMARY KEY (id);
--
-- Name: ethscription_transfers ethscription_transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ethscription_transfers
ADD CONSTRAINT ethscription_transfers_pkey PRIMARY KEY (id);
--
-- Name: ethscriptions ethscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.ethscriptions
ADD CONSTRAINT ethscriptions_pkey PRIMARY KEY (id);
--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.schema_migrations
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
--
-- Name: token_items token_items_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.token_items
ADD CONSTRAINT token_items_pkey PRIMARY KEY (id);
--
-- Name: token_states token_states_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.token_states
ADD CONSTRAINT token_states_pkey PRIMARY KEY (id);
--
-- Name: tokens tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tokens
ADD CONSTRAINT tokens_pkey PRIMARY KEY (id);
--
-- Name: idx_on_block_number_deploy_ethscription_transaction_4559fe945a; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_block_number_deploy_ethscription_transaction_4559fe945a ON public.token_states USING btree (block_number, deploy_ethscription_transaction_hash);
--
-- Name: idx_on_block_number_transaction_index_event_log_ind_94b2c4b953; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_block_number_transaction_index_event_log_ind_94b2c4b953 ON public.ethscription_transfers USING btree (block_number, transaction_index, event_log_index);
--
-- Name: idx_on_block_number_transaction_index_transfer_inde_8090d24b9e; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_block_number_transaction_index_transfer_inde_8090d24b9e ON public.ethscription_ownership_versions USING btree (block_number, transaction_index, transfer_index);
--
-- Name: idx_on_block_number_transaction_index_transfer_inde_fc9ee59957; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_block_number_transaction_index_transfer_inde_fc9ee59957 ON public.ethscription_transfers USING btree (block_number, transaction_index, transfer_index);
--
-- Name: idx_on_current_owner_previous_owner_7bb4bbf3cf; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_on_current_owner_previous_owner_7bb4bbf3cf ON public.ethscription_ownership_versions USING btree (current_owner, previous_owner);
--
-- Name: idx_on_deploy_block_number_deploy_transaction_index_16cfcbe277; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_deploy_block_number_deploy_transaction_index_16cfcbe277 ON public.tokens USING btree (deploy_block_number, deploy_transaction_index);
--
-- Name: idx_on_deploy_ethscription_transaction_hash_token_i_8afe3c6082; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_deploy_ethscription_transaction_hash_token_i_8afe3c6082 ON public.token_items USING btree (deploy_ethscription_transaction_hash, token_item_id);
--
-- Name: idx_on_ethscription_transaction_hash_deploy_ethscri_5f2ffeede2; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_ethscription_transaction_hash_deploy_ethscri_5f2ffeede2 ON public.token_items USING btree (ethscription_transaction_hash, deploy_ethscription_transaction_hash, token_item_id);
--
-- Name: idx_on_ethscription_transaction_hash_e9e1b526f9; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_on_ethscription_transaction_hash_e9e1b526f9 ON public.ethscription_ownership_versions USING btree (ethscription_transaction_hash);
--
-- Name: idx_on_transaction_hash_event_log_index_c192a81bef; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_transaction_hash_event_log_index_c192a81bef ON public.ethscription_transfers USING btree (transaction_hash, event_log_index);
--
-- Name: idx_on_transaction_hash_transfer_index_4389678e0a; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_transaction_hash_transfer_index_4389678e0a ON public.ethscription_transfers USING btree (transaction_hash, transfer_index);
--
-- Name: idx_on_transaction_hash_transfer_index_b79931daa1; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_on_transaction_hash_transfer_index_b79931daa1 ON public.ethscription_ownership_versions USING btree (transaction_hash, transfer_index);
--
-- Name: index_eth_blocks_on_block_number; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_blocks_on_block_number ON public.eth_blocks USING btree (block_number);
--
-- Name: index_eth_blocks_on_blockhash; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_blocks_on_blockhash ON public.eth_blocks USING btree (blockhash);
--
-- Name: index_eth_blocks_on_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_blocks_on_created_at ON public.eth_blocks USING btree (created_at);
--
-- Name: index_eth_blocks_on_imported_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_blocks_on_imported_at ON public.eth_blocks USING btree (imported_at);
--
-- Name: index_eth_blocks_on_imported_at_and_block_number; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_blocks_on_imported_at_and_block_number ON public.eth_blocks USING btree (imported_at, block_number);
--
-- Name: index_eth_blocks_on_parent_blockhash; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_blocks_on_parent_blockhash ON public.eth_blocks USING btree (parent_blockhash);
--
-- Name: index_eth_blocks_on_parent_state_hash; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_blocks_on_parent_state_hash ON public.eth_blocks USING btree (parent_state_hash);
--
-- Name: index_eth_blocks_on_state_hash; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_blocks_on_state_hash ON public.eth_blocks USING btree (state_hash);
--
-- Name: index_eth_blocks_on_timestamp; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_blocks_on_timestamp ON public.eth_blocks USING btree ("timestamp");
--
-- Name: index_eth_blocks_on_updated_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_blocks_on_updated_at ON public.eth_blocks USING btree (updated_at);
--
-- Name: index_eth_transactions_on_block_blockhash; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_block_blockhash ON public.eth_transactions USING btree (block_blockhash);
--
-- Name: index_eth_transactions_on_block_number; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_block_number ON public.eth_transactions USING btree (block_number);
--
-- Name: index_eth_transactions_on_block_number_and_transaction_index; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_transactions_on_block_number_and_transaction_index ON public.eth_transactions USING btree (block_number, transaction_index);
--
-- Name: index_eth_transactions_on_block_timestamp; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_block_timestamp ON public.eth_transactions USING btree (block_timestamp);
--
-- Name: index_eth_transactions_on_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_created_at ON public.eth_transactions USING btree (created_at);
--
-- Name: index_eth_transactions_on_from_address; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_from_address ON public.eth_transactions USING btree (from_address);
--
-- Name: index_eth_transactions_on_logs; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_logs ON public.eth_transactions USING gin (logs);
--
-- Name: index_eth_transactions_on_status; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_status ON public.eth_transactions USING btree (status);
--
-- Name: index_eth_transactions_on_to_address; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_to_address ON public.eth_transactions USING btree (to_address);
--
-- Name: index_eth_transactions_on_transaction_hash; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_eth_transactions_on_transaction_hash ON public.eth_transactions USING btree (transaction_hash);
--
-- Name: index_eth_transactions_on_updated_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_eth_transactions_on_updated_at ON public.eth_transactions USING btree (updated_at);
--
-- Name: index_ethscription_ownership_versions_on_block_blockhash; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_ethscription_ownership_versions_on_block_blockhash ON public.ethscription_ownership_versions USING btree (block_blockhash);
--
-- Name: index_ethscription_ownership_versions_on_block_number; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_ethscription_ownership_versions_on_block_number ON public.ethscription_ownership_versions USING btree (block_number);
--
-- Name: index_ethscription_ownership_versions_on_block_timestamp; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_ethscription_ownership_versions_on_block_timestamp ON public.ethscription_ownership_versions USING btree (block_timestamp);
--
-- Name: index_ethscription_ownership_versions_on_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_ethscription_ownership_versions_on_created_at ON public.ethscription_ownership_versions USING btree (created_at);
--
-- Name: index_ethscription_ownership_versions_on_current_owner; Type: INDEX; Schema: public; Owner: -
--