@@ -64,12 +64,34 @@ CREATE FUNCTION public.check_block_order() RETURNS trigger
6464 NEW .parent_blockhash <> (SELECT blockhash FROM eth_blocks WHERE block_number = NEW .block_number - 1 ) THEN
6565 RAISE EXCEPTION ' Parent block hash does not match the parent' ' s block hash' ;
6666 END IF;
67-
67+
6868 RETURN NEW;
6969 END;
7070 $$;
7171
7272
73+ --
74+ -- Name: check_block_order_on_update(); Type: FUNCTION; Schema: public; Owner: -
75+ --
76+
77+ CREATE FUNCTION public .check_block_order_on_update() RETURNS trigger
78+ LANGUAGE plpgsql
79+ AS $$
80+ BEGIN
81+ IF NEW .imported_at IS NOT NULL AND NEW .state_hash IS NULL THEN
82+ RAISE EXCEPTION ' state_hash must be set when imported_at is set' ;
83+ END IF;
84+
85+ IF NEW .is_genesis_block = false AND
86+ NEW .parent_state_hash <> (SELECT state_hash FROM eth_blocks WHERE block_number = NEW .block_number - 1 AND imported_at IS NOT NULL ) THEN
87+ RAISE EXCEPTION ' Parent state hash does not match the state hash of the previous block' ;
88+ END IF;
89+
90+ RETURN NEW;
91+ END;
92+ $$;
93+
94+
7395--
7496-- Name: check_ethscription_order_and_sequence(); Type: FUNCTION; Schema: public; Owner: -
7597--
@@ -208,10 +230,14 @@ CREATE TABLE public.eth_blocks (
208230 blockhash character varying NOT NULL ,
209231 parent_blockhash character varying NOT NULL ,
210232 imported_at timestamp (6 ) without time zone ,
233+ state_hash character varying,
234+ parent_state_hash character varying,
211235 is_genesis_block boolean NOT NULL ,
212236 created_at timestamp (6 ) without time zone NOT NULL ,
213237 updated_at timestamp (6 ) without time zone NOT NULL ,
214238 CONSTRAINT chk_rails_1c105acdac CHECK (((parent_blockhash)::text ~ ' ^0x[a-f0-9]{64}$' ::text )),
239+ CONSTRAINT chk_rails_319237323b CHECK (((state_hash)::text ~ ' ^0x[a-f0-9]{64}$' ::text )),
240+ CONSTRAINT chk_rails_7126b7c9d3 CHECK (((parent_state_hash)::text ~ ' ^0x[a-f0-9]{64}$' ::text )),
215241 CONSTRAINT chk_rails_7e9881ece2 CHECK (((blockhash)::text ~ ' ^0x[a-f0-9]{64}$' ::text ))
216242);
217243
@@ -257,10 +283,10 @@ CREATE TABLE public.eth_transactions (
257283 value numeric NOT NULL ,
258284 created_at timestamp (6 ) without time zone NOT NULL ,
259285 updated_at timestamp (6 ) without time zone NOT NULL ,
260- CONSTRAINT chk_rails_51be5c1aa9 CHECK (((to_address IS NULL ) OR ((to_address)::text ~ ' ^0x[a-f0-9]{40}$' ::text ))),
261- CONSTRAINT chk_rails_93b41d08e7 CHECK (((created_contract_address IS NULL ) OR ((created_contract_address)::text ~ ' ^0x[a-f0-9]{40}$' ::text ))),
286+ CONSTRAINT chk_rails_37ed5d6017 CHECK (((to_address)::text ~ ' ^0x[a-f0-9]{40}$' ::text )),
262287 CONSTRAINT chk_rails_9cdbd3b1ad CHECK (((transaction_hash)::text ~ ' ^0x[a-f0-9]{64}$' ::text )),
263288 CONSTRAINT chk_rails_a4d3f41974 CHECK (((from_address)::text ~ ' ^0x[a-f0-9]{40}$' ::text )),
289+ CONSTRAINT chk_rails_d460e80110 CHECK (((created_contract_address)::text ~ ' ^0x[a-f0-9]{40}$' ::text )),
264290 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 )))),
265291 CONSTRAINT status_check CHECK ((((block_number <= 4370000 ) AND (status IS NULL )) OR ((block_number > 4370000 ) AND (status = 1 ))))
266292);
@@ -400,10 +426,10 @@ CREATE TABLE public.ethscriptions (
400426 created_at timestamp (6 ) without time zone NOT NULL ,
401427 updated_at timestamp (6 ) without time zone NOT NULL ,
402428 CONSTRAINT chk_rails_52497428f2 CHECK (((previous_owner)::text ~ ' ^0x[a-f0-9]{40}$' ::text )),
429+ CONSTRAINT chk_rails_528fcbfbaa CHECK (((content_sha)::text ~ ' ^0x[a-f0-9]{64}$' ::text )),
403430 CONSTRAINT chk_rails_6f8922831e CHECK (((current_owner)::text ~ ' ^0x[a-f0-9]{40}$' ::text )),
404431 CONSTRAINT chk_rails_84591e2730 CHECK (((transaction_hash)::text ~ ' ^0x[a-f0-9]{64}$' ::text )),
405432 CONSTRAINT chk_rails_b577b97822 CHECK (((creator)::text ~ ' ^0x[a-f0-9]{40}$' ::text )),
406- CONSTRAINT chk_rails_d741e3044d CHECK (((content_sha)::text ~ ' ^[a-f0-9]{64}$' ::text )),
407433 CONSTRAINT chk_rails_df21fdbe02 CHECK (((initial_owner)::text ~ ' ^0x[a-f0-9]{40}$' ::text ))
408434);
409435
@@ -696,6 +722,13 @@ CREATE INDEX index_eth_transactions_on_to_address ON public.eth_transactions USI
696722CREATE UNIQUE INDEX index_eth_transactions_on_transaction_hash ON public .eth_transactions USING btree (transaction_hash);
697723
698724
725+ --
726+ -- Name: index_ethscription_ownership_versions_on_block_number; Type: INDEX; Schema: public; Owner: -
727+ --
728+
729+ CREATE INDEX index_ethscription_ownership_versions_on_block_number ON public .ethscription_ownership_versions USING btree (block_number);
730+
731+
699732--
700733-- Name: index_ethscription_ownership_versions_on_transaction_hash; Type: INDEX; Schema: public; Owner: -
701734--
@@ -857,6 +890,13 @@ CREATE TRIGGER check_block_imported_at_trigger BEFORE UPDATE OF imported_at ON p
857890CREATE TRIGGER trigger_check_block_order BEFORE INSERT ON public .eth_blocks FOR EACH ROW EXECUTE FUNCTION public .check_block_order ();
858891
859892
893+ --
894+ -- Name: eth_blocks trigger_check_block_order_on_update; Type: TRIGGER; Schema: public; Owner: -
895+ --
896+
897+ CREATE TRIGGER trigger_check_block_order_on_update BEFORE UPDATE OF imported_at ON public .eth_blocks FOR EACH ROW WHEN ((new .imported_at IS NOT NULL )) EXECUTE FUNCTION public .check_block_order_on_update ();
898+
899+
860900--
861901-- Name: ethscriptions trigger_check_ethscription_order_and_sequence; Type: TRIGGER; Schema: public; Owner: -
862902--
0 commit comments