Address comments and add subscription for state_accounts and access_list_elements

This commit is contained in:
Arijit Das 2021-12-14 15:57:54 +05:30
parent 35f72bc438
commit 852b5da40c

View File

@ -906,35 +906,47 @@ ALTER TABLE ONLY eth.uncle_cids
CREATE FUNCTION eth.graphql_subscription() RETURNS TRIGGER AS $$
DECLARE
hash text;
obj jsonb;
BEGIN
EXECUTE 'select $1.' || quote_ident(TG_ARGV[0])
USING NEW
INTO hash;
IF (TG_RELNAME = 'state_cids' ) THEN
IF (TG_TABLE_NAME = 'state_cids') OR (TG_TABLE_NAME = 'state_accounts') THEN
obj := json_build_array(
TG_TABLE_NAME,
NEW.header_id,
NEW.state_path
);
ELSIF (TG_TABLE_NAME = 'storage_cids') THEN
obj := json_build_array(
TG_RELNAME,
hash,
NEW.state_path
);
ELSIF (TG_RELNAME = 'storage_cids') THEN
obj := json_build_array(
TG_RELNAME,
hash,
TG_TABLE_NAME,
NEW.header_id,
NEW.state_path,
NEW.storage_path
);
ELSIF (TG_RELNAME = 'log_cids') THEN
ELSIF (TG_TABLE_NAME = 'log_cids') THEN
obj := json_build_array(
TG_RELNAME,
hash,
TG_TABLE_NAME,
NEW.rct_id,
NEW.index
);
ELSE
ELSIF (TG_TABLE_NAME = 'receipt_cids') THEN
obj := json_build_array(
TG_RELNAME,
hash
TG_TABLE_NAME,
NEW.tx_id
);
ELSIF (TG_TABLE_NAME = 'transaction_cids') THEN
obj := json_build_array(
TG_TABLE_NAME,
NEW.tx_hash
);
ELSIF (TG_TABLE_NAME = 'access_list_elements') THEN
obj := json_build_array(
TG_TABLE_NAME,
NEW.tx_id,
NEW.index
);
ELSIF (TG_TABLE_NAME = 'uncle_cids') OR (TG_TABLE_NAME = 'header_cids') THEN
obj := json_build_array(
TG_TABLE_NAME,
NEW.block_hash
);
END IF;
@ -949,37 +961,47 @@ $$ language plpgsql;
CREATE TRIGGER eth_header_cids
AFTER INSERT ON eth.header_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('block_hash');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_uncle_cids
AFTER INSERT ON eth.uncle_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('block_hash');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_transaction_cids
AFTER INSERT ON eth.transaction_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('tx_hash');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_receipt_cids
AFTER INSERT ON eth.receipt_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('tx_id');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_state_cids
AFTER INSERT ON eth.state_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('header_id','state_path');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_log_cids
AFTER INSERT ON eth.log_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('rct_id', 'index');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_storage_cids
AFTER INSERT ON eth.storage_cids
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription('header_id','state_path', 'storage_path');
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_state_accounts
AFTER INSERT ON eth.state_accounts
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription();
CREATE TRIGGER eth_access_list_elements
AFTER INSERT ON eth.access_list_elements
FOR EACH ROW
EXECUTE PROCEDURE eth.graphql_subscription();
--
-- PostgreSQL database dump complete