From ca2260072485addeae0b3e067dd948f74b1ee9b6 Mon Sep 17 00:00:00 2001 From: rdlrt <3169068+rdlrt@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:14:51 +1000 Subject: [PATCH] Retire v0 endpoint SQLs --- files/grest/rpc/blocks/block_tx_info.sql | 2 +- files/grest/rpc/transactions/tx_info.sql | 2 +- files/grest/rpc/v0/00_blockchain.sql | 76 ------- files/grest/rpc/v0/account.sql | 184 ---------------- files/grest/rpc/v0/address.sql | 132 ------------ files/grest/rpc/v0/assets.sql | 211 ------------------- files/grest/rpc/v0/blocks.sql | 64 ------ files/grest/rpc/v0/epoch.sql | 81 ------- files/grest/rpc/v0/pool.sql | 255 ----------------------- files/grest/rpc/v0/script.sql | 79 ------- files/grest/rpc/v0/transactions.sql | 87 -------- files/grest/rpc/v0/views.sql | 56 ----- 12 files changed, 2 insertions(+), 1227 deletions(-) delete mode 100644 files/grest/rpc/v0/00_blockchain.sql delete mode 100644 files/grest/rpc/v0/account.sql delete mode 100644 files/grest/rpc/v0/address.sql delete mode 100644 files/grest/rpc/v0/assets.sql delete mode 100644 files/grest/rpc/v0/blocks.sql delete mode 100644 files/grest/rpc/v0/epoch.sql delete mode 100644 files/grest/rpc/v0/pool.sql delete mode 100644 files/grest/rpc/v0/script.sql delete mode 100644 files/grest/rpc/v0/transactions.sql delete mode 100644 files/grest/rpc/v0/views.sql diff --git a/files/grest/rpc/blocks/block_tx_info.sql b/files/grest/rpc/blocks/block_tx_info.sql index 05bd3bb4..10710f8b 100644 --- a/files/grest/rpc/blocks/block_tx_info.sql +++ b/files/grest/rpc/blocks/block_tx_info.sql @@ -279,7 +279,7 @@ BEGIN ) END ) AS reference_script, - REPLACE(multi_assets_descr,'fromList ','') AS asset_descr + REPLACE(multi_assets_descr,'fromList ','')::jsonb AS asset_descr FROM collateral_tx_out AS tx_out INNER JOIN tx ON tx_out.tx_id = tx.id diff --git a/files/grest/rpc/transactions/tx_info.sql b/files/grest/rpc/transactions/tx_info.sql index 71f329e1..39c8e4f6 100644 --- a/files/grest/rpc/transactions/tx_info.sql +++ b/files/grest/rpc/transactions/tx_info.sql @@ -262,7 +262,7 @@ BEGIN ) END ) AS reference_script, - REPLACE(multi_assets_descr,'fromList ','') AS asset_descr + REPLACE(multi_assets_descr,'fromList ','')::jsonb AS asset_descr FROM collateral_tx_out AS tx_out INNER JOIN tx ON tx_out.tx_id = tx.id diff --git a/files/grest/rpc/v0/00_blockchain.sql b/files/grest/rpc/v0/00_blockchain.sql deleted file mode 100644 index aa141bb8..00000000 --- a/files/grest/rpc/v0/00_blockchain.sql +++ /dev/null @@ -1,76 +0,0 @@ --- NETWORK - -CREATE OR REPLACE FUNCTION grestv0.genesis() -RETURNS TABLE ( - networkmagic varchar, - networkid varchar, - activeslotcoeff varchar, - updatequorum varchar, - maxlovelacesupply varchar, - epochlength varchar, - systemstart integer, - slotsperkesperiod varchar, - slotlength varchar, - maxkesrevolutions varchar, - securityparam varchar, - alonzogenesis varchar -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.genesis(); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.param_updates() -RETURNS TABLE ( - tx_hash text, - block_height word31type, - block_time integer, - epoch_no word31type, - data jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * - FROM grest.param_updates(); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.tip() -RETURNS TABLE ( - hash text, - epoch_no word31type, - abs_slot word63type, - epoch_slot word31type, - block_no word31type, - block_time integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * - FROM grest.tip(); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.totals(_epoch_no numeric DEFAULT NULL) -RETURNS TABLE ( - epoch_no word31type, - circulation text, - treasury text, - reward text, - supply text, - reserves text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.totals(_epoch_no); -END; -$$; diff --git a/files/grest/rpc/v0/account.sql b/files/grest/rpc/v0/account.sql deleted file mode 100644 index fce8ec08..00000000 --- a/files/grest/rpc/v0/account.sql +++ /dev/null @@ -1,184 +0,0 @@ --- ACCOUNT - -CREATE OR REPLACE FUNCTION grestv0.account_addresses(_stake_addresses text [], _first_only boolean DEFAULT FALSE, _empty boolean DEFAULT FALSE) -RETURNS TABLE ( - stake_address varchar, - addresses jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.account_addresses(_stake_addresses,_first_only,_empty); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_assets(_stake_addresses text []) -RETURNS TABLE ( - stake_address varchar, - asset_list jsonb -) -LANGUAGE plpgsql -AS $$ -DECLARE - sa_id_list integer[]; -BEGIN - SELECT INTO sa_id_list - ARRAY_AGG(stake_address.id) - FROM - stake_address - WHERE - stake_address.view = ANY(_stake_addresses); - RETURN QUERY - WITH _all_assets AS ( - SELECT - sa.view, - ma.policy, - ma.name, - ma.fingerprint, - COALESCE(aic.decimals, 0) AS decimals, - SUM(mtx.quantity) AS quantity - FROM - ma_tx_out AS mtx - INNER JOIN multi_asset AS ma ON ma.id = mtx.ident - INNER JOIN tx_out AS txo ON txo.id = mtx.tx_out_id - INNER JOIN stake_address AS sa ON sa.id = txo.stake_address_id - LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id - WHERE sa.id = ANY(sa_id_list) - AND txo.consumed_by_tx_id IS NULL - GROUP BY - sa.view, ma.policy, ma.name, ma.fingerprint, aic.decimals - ) - - SELECT - assets_grouped.view AS stake_address, - assets_grouped.assets - FROM ( - SELECT - aa.view, - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'policy_id', ENCODE(aa.policy, 'hex'), - 'asset_name', ENCODE(aa.name, 'hex'), - 'fingerprint', aa.fingerprint, - 'decimals', COALESCE(aa.decimals, 0), - 'quantity', aa.quantity::text - ) - ) AS assets - FROM - _all_assets AS aa - GROUP BY - aa.view - ) AS assets_grouped; -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_history(_stake_addresses text [], _epoch_no integer DEFAULT NULL) -RETURNS TABLE ( - stake_address varchar, - history jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.account_history(_stake_addresses, _epoch_no); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_info(_stake_addresses text []) -RETURNS TABLE ( - stake_address varchar, - status text, - delegated_pool varchar, - total_balance text, - utxo text, - rewards text, - withdrawals text, - rewards_available text, - reserves text, - treasury text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.account_info(_stake_addresses); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_info_cached(_stake_addresses text []) -RETURNS TABLE ( - stake_address varchar, - status text, - delegated_pool varchar, - total_balance text, - utxo text, - rewards text, - withdrawals text, - rewards_available text, - reserves text, - treasury text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.account_info_cached(_stake_addresses); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_rewards(_stake_addresses text [], _epoch_no numeric DEFAULT NULL) -RETURNS TABLE ( - stake_address varchar, - rewards jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.account_rewards(_stake_addresses, _epoch_no); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_updates(_stake_addresses text []) -RETURNS TABLE ( - stake_address varchar, - updates jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.account_updates(_stake_addresses); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.account_utxos(_stake_address text) -RETURNS TABLE ( - tx_hash text, - tx_index smallint, - address varchar, - value text, - block_height word31type, - block_time integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT - ENCODE(tx.hash,'hex') AS tx_hash, - tx_out.index::smallint AS tx_index, - tx_out.address, - tx_out.value::text AS value, - b.block_no AS block_height, - EXTRACT(EPOCH FROM b.time)::integer AS block_time - FROM - tx_out - INNER JOIN tx ON tx.id = tx_out.tx_id - LEFT JOIN block AS b ON b.id = tx.block_id - WHERE tx_out.consumed_by_tx_id IS NULL - AND tx_out.stake_address_id = (SELECT id FROM stake_address WHERE view = _stake_address); -END; -$$; diff --git a/files/grest/rpc/v0/address.sql b/files/grest/rpc/v0/address.sql deleted file mode 100644 index f8f750d5..00000000 --- a/files/grest/rpc/v0/address.sql +++ /dev/null @@ -1,132 +0,0 @@ --- ADDRESS - -CREATE OR REPLACE FUNCTION grestv0.address_assets(_addresses text []) -RETURNS TABLE ( - address varchar, - asset_list jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - - WITH _all_assets AS ( - SELECT - txo.address, - ma.policy, - ma.name, - ma.fingerprint, - COALESCE(aic.decimals, 0) AS decimals, - SUM(mtx.quantity) AS quantity - FROM - ma_tx_out AS mtx - INNER JOIN multi_asset AS ma ON ma.id = mtx.ident - LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id - INNER JOIN tx_out AS txo ON txo.id = mtx.tx_out_id - WHERE - txo.address = ANY(_addresses) - AND txo.consumed_by_tx_id IS NULL - GROUP BY - txo.address, ma.policy, ma.name, ma.fingerprint, aic.decimals - ) - - SELECT - assets_grouped.address, - assets_grouped.asset_list - FROM ( - SELECT - aa.address, - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'policy_id', ENCODE(aa.policy, 'hex'), - 'asset_name', ENCODE(aa.name, 'hex'), - 'fingerprint', aa.fingerprint, - 'decimals', aa.decimals, - 'quantity', aa.quantity::text - ) - ) AS asset_list - FROM - _all_assets AS aa - GROUP BY - aa.address - ) assets_grouped; -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.address_info(_addresses text []) -RETURNS TABLE ( - address varchar, - balance text, - stake_address character varying, - script_address boolean, - utxo_set jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.address_info(_addresses); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.address_txs(_addresses text [], _after_block_height integer DEFAULT 0) -RETURNS TABLE ( - tx_hash text, - epoch_no word31type, - block_height word31type, - block_time integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.address_txs(_addresses, _after_block_height); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.credential_txs(_payment_credentials text [], _after_block_height integer DEFAULT 0) -RETURNS TABLE ( - tx_hash text, - epoch_no word31type, - block_height word31type, - block_time integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.credential_txs(_payment_credentials,_after_block_height); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.credential_utxos(_payment_credentials text []) -RETURNS TABLE ( - tx_hash text, - tx_index smallint, - value text -) -LANGUAGE plpgsql -AS $$ -DECLARE - _payment_cred_bytea bytea[]; - -BEGIN - SELECT INTO _payment_cred_bytea ARRAY_AGG(cred_bytea) - FROM ( - SELECT - DECODE(cred_hex, 'hex') AS cred_bytea - FROM - UNNEST(_payment_credentials) AS cred_hex - ) AS tmp; - - RETURN QUERY - SELECT - ENCODE(tx.hash, 'hex')::text AS tx_hash, - tx_out.index::smallint, - tx_out.value::text AS balance - FROM tx_out - INNER JOIN tx ON tx_out.tx_id = tx.id - WHERE payment_cred = ANY(_payment_cred_bytea) - AND tx_out.consumed_by_tx_id IS NULL; -END; -$$; diff --git a/files/grest/rpc/v0/assets.sql b/files/grest/rpc/v0/assets.sql deleted file mode 100644 index 7a49d776..00000000 --- a/files/grest/rpc/v0/assets.sql +++ /dev/null @@ -1,211 +0,0 @@ --- ASSETS - -CREATE OR REPLACE FUNCTION grestv0.asset_address_list(_asset_policy text, _asset_name text DEFAULT '') -RETURNS TABLE ( - payment_address varchar, - quantity text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_addresses(_asset_policy, _asset_name); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_addresses(_asset_policy text, _asset_name text DEFAULT '') -RETURNS TABLE ( - payment_address varchar, - quantity text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_addresses(_asset_policy, _asset_name); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_history(_asset_policy text, _asset_name text DEFAULT '') -RETURNS TABLE ( - policy_id text, - asset_name text, - fingerprint character varying, - minting_txs jsonb [] -) -LANGUAGE plpgsql -AS $$ -DECLARE - _asset_policy_decoded bytea; - _asset_name_decoded bytea; -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_history(_asset_policy, _asset_name); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_info(_asset_policy text, _asset_name text DEFAULT '') -RETURNS TABLE ( - policy_id text, - asset_name text, - asset_name_ascii text, - fingerprint character varying, - minting_tx_hash text, - total_supply text, - mint_cnt bigint, - burn_cnt bigint, - creation_time integer, - minting_tx_metadata jsonb, - token_registry_metadata jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_info(_asset_policy,_asset_name); - -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_info(_asset_list text [] []) -RETURNS TABLE ( - policy_id text, - asset_name text, - asset_name_ascii text, - fingerprint character varying, - minting_tx_hash text, - total_supply text, - mint_cnt bigint, - burn_cnt bigint, - creation_time integer, - minting_tx_metadata jsonb, - token_registry_metadata jsonb, - cip68_metadata jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - -- find all asset id's based ON nested array input - RETURN QUERY - SELECT * FROM grest.asset_info(_asset_list); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_nft_address(_asset_policy text, _asset_name text DEFAULT '') -RETURNS TABLE ( - payment_address varchar -) LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_nft_address(_asset_policy, _asset_name); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_summary(_asset_policy text, _asset_name text DEFAULT '') -RETURNS TABLE ( - policy_id text, - asset_name text, - fingerprint character varying, - total_transactions bigint, - staked_wallets bigint, - unstaked_addresses bigint -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_summary(_asset_policy, _asset_name); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_txs( - _asset_policy text, - _asset_name text DEFAULT '', - _after_block_height integer DEFAULT 0, - _history boolean DEFAULT FALSE -) -RETURNS TABLE ( - tx_hash text, - epoch_no word31type, - block_height word31type, - block_time integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.asset_txs(_asset_policy, _asset_name, _after_block_height, _history); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.policy_asset_addresses(_asset_policy text) -RETURNS TABLE ( - asset_name text, - payment_address varchar, - quantity text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.policy_asset_addresses(_asset_policy); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.asset_policy_info(_asset_policy text) -RETURNS TABLE ( - asset_name text, - asset_name_ascii text, - fingerprint varchar, - minting_tx_hash text, - total_supply text, - mint_cnt bigint, - burn_cnt bigint, - creation_time integer, - minting_tx_metadata jsonb, - token_registry_metadata jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.policy_asset_info(_asset_policy); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.policy_asset_info(_asset_policy text) -RETURNS TABLE ( - asset_name text, - asset_name_ascii text, - fingerprint varchar, - minting_tx_hash text, - total_supply text, - mint_cnt bigint, - burn_cnt bigint, - creation_time integer, - minting_tx_metadata jsonb, - token_registry_metadata jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.policy_asset_info(_asset_policy); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.policy_asset_list(_asset_policy text) -RETURNS TABLE ( - asset_name text, - fingerprint varchar, - total_supply text, - decimals integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.policy_asset_list(_asset_policy); -END; -$$; diff --git a/files/grest/rpc/v0/blocks.sql b/files/grest/rpc/v0/blocks.sql deleted file mode 100644 index 4f346afe..00000000 --- a/files/grest/rpc/v0/blocks.sql +++ /dev/null @@ -1,64 +0,0 @@ --- BLOCKS - -CREATE OR REPLACE FUNCTION grestv0.block_info(_block_hashes text []) -RETURNS TABLE ( - hash text, - epoch_no word31type, - abs_slot word63type, - epoch_slot word31type, - block_height word31type, - block_size word31type, - block_time integer, - tx_count bigint, - vrf_key varchar, - op_cert text, - op_cert_counter word63type, - pool varchar, - proto_major word31type, - proto_minor word31type, - total_output text, - total_fees text, - num_confirmations integer, - parent_hash text, - child_hash text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.block_info(_block_hashes); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.block_txs(_block_hashes text []) -RETURNS TABLE ( - block_hash text, - tx_hashes text [] -) -LANGUAGE plpgsql -AS $$ -DECLARE - _block_hashes_bytea bytea[]; - _block_ids integer[]; -BEGIN - SELECT INTO _block_hashes_bytea ARRAY_AGG(block_hashes_bytea) - FROM ( - SELECT DECODE(hex, 'hex') AS block_hashes_bytea - FROM UNNEST(_block_hashes) AS hex - ) AS tmp; - - SELECT INTO _block_ids ARRAY_AGG(b.id) - FROM public.block AS b - WHERE b.hash = ANY(_block_hashes_bytea); - - RETURN QUERY - SELECT - encode(b.hash, 'hex'), - ARRAY_AGG(ENCODE(tx.hash::bytea, 'hex')) - FROM - public.block AS b - INNER JOIN public.tx ON tx.block_id = b.id - WHERE b.id = ANY(_block_ids) - GROUP BY b.hash; -END; -$$; diff --git a/files/grest/rpc/v0/epoch.sql b/files/grest/rpc/v0/epoch.sql deleted file mode 100644 index e999b4b2..00000000 --- a/files/grest/rpc/v0/epoch.sql +++ /dev/null @@ -1,81 +0,0 @@ --- EPOCH - -CREATE OR REPLACE FUNCTION grestv0.epoch_block_protocols(_epoch_no numeric DEFAULT NULL) -RETURNS TABLE ( - proto_major word31type, - proto_minor word31type, - blocks bigint -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.epoch_block_protocols(_epoch_no); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.epoch_info(_epoch_no numeric DEFAULT NULL, _include_next_epoch boolean DEFAULT FALSE) -RETURNS TABLE ( - epoch_no word31type, - out_sum text, - fees text, - tx_count word31type, - blk_count word31type, - start_time integer, - end_time integer, - first_block_time integer, - last_block_time integer, - active_stake text, - total_rewards text, - avg_blk_reward text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.epoch_info(_epoch_no, _include_next_epoch); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.epoch_params(_epoch_no numeric DEFAULT NULL) -RETURNS TABLE ( - epoch_no word31type, - min_fee_a word31type, - min_fee_b word31type, - max_block_size word31type, - max_tx_size word31type, - max_bh_size word31type, - key_deposit text, - pool_deposit text, - max_epoch word31type, - optimal_pool_count word31type, - influence double precision, - monetary_expand_rate double precision, - treasury_growth_rate double precision, - decentralisation double precision, - extra_entropy text, - protocol_major word31type, - protocol_minor word31type, - min_utxo_value text, - min_pool_cost text, - nonce text, - block_hash text, - cost_models jsonb, - price_mem double precision, - price_step double precision, - max_tx_ex_mem word64type, - max_tx_ex_steps word64type, - max_block_ex_mem word64type, - max_block_ex_steps word64type, - max_val_size word64type, - collateral_percent word31type, - max_collateral_inputs word31type, - coins_per_utxo_size text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.epoch_params(_epoch_no); -END; -$$; diff --git a/files/grest/rpc/v0/pool.sql b/files/grest/rpc/v0/pool.sql deleted file mode 100644 index bdbd0242..00000000 --- a/files/grest/rpc/v0/pool.sql +++ /dev/null @@ -1,255 +0,0 @@ --- POOL - -CREATE OR REPLACE FUNCTION grestv0.pool_blocks(_pool_bech32 text, _epoch_no word31type DEFAULT NULL) -RETURNS TABLE ( - epoch_no word31type, - epoch_slot word31type, - abs_slot word63type, - block_height word31type, - block_hash text, - block_time integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN query - SELECT * FROM grest.pool_blocks(_pool_bech32, _epoch_no); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_delegators(_pool_bech32 text) -RETURNS TABLE ( - stake_address character varying, - amount text, - active_epoch_no bigint, - latest_delegation_tx_hash text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_delegators(_pool_bech32); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_delegators_history(_pool_bech32 text, _epoch_no word31type DEFAULT NULL) -RETURNS TABLE ( - stake_address character varying, - amount text, - epoch_no word31type -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_delegators_history(_pool_bech32, _epoch_no); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_history(_pool_bech32 text, _epoch_no word31type DEFAULT NULL) -RETURNS TABLE ( - epoch_no bigint, - active_stake text, - active_stake_pct numeric, - saturation_pct numeric, - block_cnt bigint, - delegator_cnt bigint, - margin double precision, - fixed_cost text, - pool_fees text, - deleg_rewards text, - member_rewards text, - epoch_ros numeric -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_history(_pool_bech32, _epoch_no); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_info(_pool_bech32_ids text []) -RETURNS TABLE ( - pool_id_bech32 character varying, - pool_id_hex text, - active_epoch_no bigint, - vrf_key_hash text, - margin double precision, - fixed_cost text, - pledge text, - reward_addr character varying, - owners character varying [], - relays jsonb [], - meta_url character varying, - meta_hash text, - meta_json jsonb, - pool_status text, - retiring_epoch word31type, - op_cert text, - op_cert_counter word63type, - active_stake text, - sigma numeric, - block_count numeric, - live_pledge text, - live_stake text, - live_delegators bigint, - live_saturation numeric -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_info(_pool_bech32_ids); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_list() -RETURNS TABLE ( - pool_id_bech32 character varying, - ticker character varying -) -LANGUAGE plpgsql -AS $$ -# variable_conflict use_column -BEGIN - RETURN QUERY ( - WITH - -- Get last pool update for each pool - _pool_list AS ( - SELECT - DISTINCT ON (pic.pool_id_bech32) pool_id_bech32, - pool_status - FROM - grest.pool_info_cache AS pic - ORDER BY - pic.pool_id_bech32, - pic.tx_id DESC - ), - - _pool_meta AS ( - SELECT - DISTINCT ON (pic.pool_id_bech32) pool_id_bech32, - ocpd.ticker_name - FROM - grest.pool_info_cache AS pic - LEFT JOIN public.off_chain_pool_data AS ocpd ON ocpd.pmr_id = pic.meta_id - WHERE ocpd.ticker_name IS NOT NULL - ORDER BY - pic.pool_id_bech32, - pic.tx_id DESC - ) - - SELECT - pl.pool_id_bech32, - pm.ticker_name - FROM - _pool_list AS pl - LEFT JOIN _pool_meta AS pm ON pl.pool_id_bech32 = pm.pool_id_bech32 - WHERE - pool_status != 'retired' - ); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_metadata(_pool_bech32_ids text [] DEFAULT NULL) -RETURNS TABLE ( - pool_id_bech32 character varying, - meta_url character varying, - meta_hash text, - meta_json jsonb, - pool_status text -) -LANGUAGE plpgsql -AS $$ -#variable_conflict use_column -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_metadata(_pool_bech32_ids); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_relays() -RETURNS TABLE ( - pool_id_bech32 character varying, - relays jsonb [], - pool_status text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_relays(); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_stake_snapshot(_pool_bech32 text) -RETURNS TABLE ( - snapshot text, - epoch_no bigint, - nonce text, - pool_stake text, - active_stake text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.pool_stake_snapshot(_pool_bech32); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.pool_updates(_pool_bech32 text DEFAULT NULL) -RETURNS TABLE ( - tx_hash text, - block_time integer, - pool_id_bech32 character varying, - pool_id_hex text, - active_epoch_no bigint, - vrf_key_hash text, - margin double precision, - fixed_cost text, - pledge text, - reward_addr character varying, - owners character varying [], - relays jsonb [], - meta_url character varying, - meta_hash text, - meta_json jsonb, - pool_status text, - retiring_epoch word31type -) -LANGUAGE plpgsql -AS $$ -#variable_conflict use_column -BEGIN - RETURN QUERY - SELECT - tx_hash, - block_time::integer, - pool_id_bech32, - pool_id_hex, - active_epoch_no, - vrf_key_hash, - margin, - fixed_cost::text, - pledge::text, - reward_addr, - owners, - relays, - meta_url, - meta_hash, - ocpd.json, - pool_status, - retiring_epoch - FROM - grest.pool_info_cache AS pic - LEFT JOIN public.off_chain_pool_data AS ocpd ON ocpd.pmr_id = pic.meta_id - WHERE - _pool_bech32 IS NULL - OR - pool_id_bech32 = _pool_bech32 - ORDER BY - tx_id DESC; -END; -$$; diff --git a/files/grest/rpc/v0/script.sql b/files/grest/rpc/v0/script.sql deleted file mode 100644 index 3702a433..00000000 --- a/files/grest/rpc/v0/script.sql +++ /dev/null @@ -1,79 +0,0 @@ --- SCRIPT - -CREATE OR REPLACE FUNCTION grestv0.datum_info(_datum_hashes text []) -RETURNS TABLE ( - hash text, - value jsonb, - bytes text -) -LANGUAGE plpgsql -AS $$ -DECLARE - _datum_hashes_decoded bytea[]; -BEGIN - SELECT INTO _datum_hashes_decoded ARRAY_AGG(DECODE(d_hash, 'hex')) - FROM UNNEST(_datum_hashes) AS d_hash; - RETURN QUERY - SELECT - ENCODE(d.hash, 'hex'), - d.value, - ENCODE(d.bytes, 'hex') - FROM - datum AS d - WHERE - d.hash = ANY(_datum_hashes_decoded); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.native_script_list() -RETURNS TABLE ( - script_hash text, - creation_tx_hash text, - type scripttype, - script jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT - ENCODE(script.hash, 'hex'), - ENCODE(tx.hash, 'hex'), - script.type, - script.json - FROM script - INNER JOIN tx ON tx.id = script.tx_id - WHERE script.type IN ('timelock', 'multisig'); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.plutus_script_list() -RETURNS TABLE ( - script_hash text, - creation_tx_hash text -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT - ENCODE(script.hash, 'hex') AS script_hash, - ENCODE(tx.hash, 'hex') AS creation_tx_hash - FROM script - INNER JOIN tx ON tx.id = script.tx_id - WHERE script.type IN ('plutusV1', 'plutusV2'); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.script_redeemers(_script_hash text) -RETURNS TABLE ( - script_hash text, - redeemers jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.script_redeemers(_script_hash); -END; -$$; diff --git a/files/grest/rpc/v0/transactions.sql b/files/grest/rpc/v0/transactions.sql deleted file mode 100644 index 6e12da14..00000000 --- a/files/grest/rpc/v0/transactions.sql +++ /dev/null @@ -1,87 +0,0 @@ --- TX - -CREATE OR REPLACE FUNCTION grestv0.tx_info(_tx_hashes text []) -RETURNS TABLE ( - tx_hash text, - block_hash text, - block_height word31type, - epoch_no word31type, - epoch_slot word31type, - absolute_slot word63type, - tx_timestamp integer, - tx_block_index word31type, - tx_size word31type, - total_output text, - fee text, - deposit text, - invalid_before text, - invalid_after text, - collateral_inputs jsonb, - collateral_output jsonb, - reference_inputs jsonb, - inputs jsonb, - outputs jsonb, - withdrawals jsonb, - assets_minted jsonb, - metadata jsonb, - certificates jsonb, - native_scripts jsonb, - plutus_contracts jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM tx_info(_tx_hashes); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.tx_metadata(_tx_hashes text []) -RETURNS TABLE ( - tx_hash text, - metadata jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.tx_metadata(_tx_hashes); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.tx_metalabels() -RETURNS TABLE (key text) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.tx_metalabels(); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.tx_status(_tx_hashes text []) -RETURNS TABLE ( - tx_hash text, - num_confirmations integer -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.tx_status(_tx_hashes); -END; -$$; - -CREATE OR REPLACE FUNCTION grestv0.tx_utxos(_tx_hashes text []) -RETURNS TABLE ( - tx_hash text, - inputs jsonb, - outputs jsonb -) -LANGUAGE plpgsql -AS $$ -BEGIN - RETURN QUERY - SELECT * FROM grest.tx_utxos(_tx_hashes); -END; -$$; diff --git a/files/grest/rpc/v0/views.sql b/files/grest/rpc/v0/views.sql deleted file mode 100644 index 177e99e2..00000000 --- a/files/grest/rpc/v0/views.sql +++ /dev/null @@ -1,56 +0,0 @@ --- VIEWS - -DROP VIEW IF EXISTS grestv0.account_list; - -CREATE VIEW grestv0.account_list AS -SELECT stake_address.view AS id -FROM - stake_address; - -DROP VIEW IF EXISTS grestv0.asset_list; - -CREATE VIEW grestv0.asset_list AS -SELECT - ENCODE(ma.policy, 'hex') AS policy_id, - ENCODE(ma.name, 'hex') AS asset_name, - ma.fingerprint -FROM - public.multi_asset AS ma -ORDER BY ma.policy, ma.name; - -DROP VIEW IF EXISTS grestv0.asset_token_registry; - -CREATE VIEW grestv0.asset_token_registry AS -SELECT - asset_policy AS policy_id, - asset_name, - name AS asset_name_ascii, - ticker, - description, - url, - decimals, - logo -FROM - grest.asset_registry_cache; - -DROP VIEW IF EXISTS grestv0.blocks; - -CREATE VIEW grestv0.blocks AS -SELECT - ENCODE(b.hash::bytea, 'hex') AS hash, - b.epoch_no, - b.slot_no AS abs_slot, - b.epoch_slot_no AS epoch_slot, - b.block_no AS block_height, - b.size AS block_size, - EXTRACT(EPOCH FROM b.time)::integer AS block_time, - b.tx_count, - b.vrf_key, - ph.view AS pool, - b.proto_major, - b.proto_minor, - b.op_cert_counter -FROM block AS b -LEFT JOIN slot_leader AS sl ON b.slot_leader_id = sl.id -LEFT JOIN pool_hash AS ph ON sl.pool_hash_id = ph.id -ORDER BY b.id DESC;