diff --git a/files/grest/.sqlfluff b/files/grest/.sqlfluff index 55ed4bb6..1a16aea2 100644 --- a/files/grest/.sqlfluff +++ b/files/grest/.sqlfluff @@ -7,7 +7,7 @@ extended_capitalisation_policy = upper idented_joins = True indented_using_on = False tab_space_size = 2 -large_file_skip_byte_limit=35000 +large_file_skip_byte_limit=50000 [sqlfluff:indentation] tab_space_size = 2 diff --git a/files/grest/rpc/000_utilities/cip129.sql b/files/grest/rpc/000_utilities/cip129.sql index 38411446..a08bf389 100644 --- a/files/grest/rpc/000_utilities/cip129.sql +++ b/files/grest/rpc/000_utilities/cip129.sql @@ -142,7 +142,7 @@ END; $$; CREATE OR REPLACE FUNCTION grest.cip129_from_gov_action_id(_proposal_id text) -RETURNS text[] +RETURNS text [] LANGUAGE plpgsql STABLE AS $$ DECLARE diff --git a/files/grest/rpc/000_utilities/cip5.sql b/files/grest/rpc/000_utilities/cip5.sql index 103043ef..1aaaaf33 100644 --- a/files/grest/rpc/000_utilities/cip5.sql +++ b/files/grest/rpc/000_utilities/cip5.sql @@ -16,4 +16,4 @@ BEGIN RETURN b32_encode('stake', _raw::text); END IF; END; -$$; \ No newline at end of file +$$; diff --git a/files/grest/rpc/01_cached_tables/pool_history_cache.sql b/files/grest/rpc/01_cached_tables/pool_history_cache.sql index 9e32ae66..8269a80a 100644 --- a/files/grest/rpc/01_cached_tables/pool_history_cache.sql +++ b/files/grest/rpc/01_cached_tables/pool_history_cache.sql @@ -219,7 +219,7 @@ $$; COMMENT ON FUNCTION grest.get_pool_history_data_bulk IS 'Pool block production and reward history from a given epoch until optional later epoch, for all or particular subset of pools'; -- noqa: LT01 -CREATE OR REPLACE FUNCTION grest.pool_history_cache_update(_epoch_no_to_insert_from bigint DEFAULT NULL) +CREATE OR REPLACE FUNCTION grest.pool_history_cache_update(_epoch_no_to_insert_from bigint DEFAULT null) RETURNS void LANGUAGE plpgsql AS $$ diff --git a/files/grest/rpc/02_indexes/13_3_00.sql b/files/grest/rpc/02_indexes/13_3_00.sql index 789ca696..24835024 100644 --- a/files/grest/rpc/02_indexes/13_3_00.sql +++ b/files/grest/rpc/02_indexes/13_3_00.sql @@ -1,4 +1,4 @@ -CREATE INDEX IF NOT EXISTS pool_stat_pool_hash_id ON pool_stat(pool_hash_id); -CREATE INDEX IF NOT EXISTS pool_stat_epoch_no ON pool_stat(epoch_no); +CREATE INDEX IF NOT EXISTS pool_stat_pool_hash_id ON pool_stat (pool_hash_id); +CREATE INDEX IF NOT EXISTS pool_stat_epoch_no ON pool_stat (epoch_no); CREATE INDEX IF NOT EXISTS idx_reward_rest_addr_id ON reward_rest (addr_id); -CREATE INDEX IF NOT EXISTS idx_reward_rest_spendable_epoch ON reward_rest (spendable_epoch); \ No newline at end of file +CREATE INDEX IF NOT EXISTS idx_reward_rest_spendable_epoch ON reward_rest (spendable_epoch); diff --git a/files/grest/rpc/02_indexes/13_5_0_2.sql b/files/grest/rpc/02_indexes/13_5_0_2.sql index 9e26961a..462c4ba0 100644 --- a/files/grest/rpc/02_indexes/13_5_0_2.sql +++ b/files/grest/rpc/02_indexes/13_5_0_2.sql @@ -1,3 +1,3 @@ DROP INDEX IF EXISTS idx_stake_address_view; CREATE INDEX IF NOT EXISTS idx_stake_address_hash_raw ON stake_address (hash_raw); -CREATE INDEX IF NOT EXISTS idx_drep_hash_raw ON drep_hash (raw); \ No newline at end of file +CREATE INDEX IF NOT EXISTS idx_drep_hash_raw ON drep_hash (raw); diff --git a/files/grest/rpc/02_indexes/13_6_0_1.sql b/files/grest/rpc/02_indexes/13_6_0_1.sql new file mode 100644 index 00000000..ab0c82b4 --- /dev/null +++ b/files/grest/rpc/02_indexes/13_6_0_1.sql @@ -0,0 +1 @@ +CREATE INDEX IF NOT EXISTS idx_address_address ON address USING hash (address); diff --git a/files/grest/rpc/account/account_addresses.sql b/files/grest/rpc/account/account_addresses.sql index acffa3cb..512a2ffb 100644 --- a/files/grest/rpc/account/account_addresses.sql +++ b/files/grest/rpc/account/account_addresses.sql @@ -27,10 +27,11 @@ BEGIN FROM ( SELECT - txo.address, + a.address, txo.stake_address_id, txo.id FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = txo.address_id WHERE txo.stake_address_id = ANY(sa_id_list) AND txo.consumed_by_tx_id IS NULL ) AS x @@ -53,10 +54,11 @@ BEGIN FROM ( SELECT - txo.address, + a.address, txo.stake_address_id, txo.id FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = txo.address_id WHERE txo.stake_address_id = ANY(sa_id_list) LIMIT (CASE WHEN _first_only IS TRUE THEN 1 ELSE NULL END) ) AS x diff --git a/files/grest/rpc/account/account_utxos.sql b/files/grest/rpc/account/account_utxos.sql index e86f39f0..28d33ce5 100644 --- a/files/grest/rpc/account/account_utxos.sql +++ b/files/grest/rpc/account/account_utxos.sql @@ -54,10 +54,10 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, - ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, + ENCODE(a.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, EXTRACT(EPOCH FROM b.time)::integer AS block_time, @@ -89,6 +89,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id diff --git a/files/grest/rpc/address/address_assets.sql b/files/grest/rpc/address/address_assets.sql index fe990662..5079aa14 100644 --- a/files/grest/rpc/address/address_assets.sql +++ b/files/grest/rpc/address/address_assets.sql @@ -14,7 +14,7 @@ BEGIN WITH _all_assets AS ( SELECT - txo.address, + a.address, ma.policy, ma.name, ma.fingerprint, @@ -24,10 +24,11 @@ BEGIN 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) + INNER JOIN address AS a ON a.id = tx_out.address_id + WHERE a.address = ANY(_addresses) AND txo.consumed_by_tx_id IS NULL GROUP BY - txo.address, ma.policy, ma.name, ma.fingerprint, aic.decimals + a.address, ma.policy, ma.name, ma.fingerprint, aic.decimals ) SELECT diff --git a/files/grest/rpc/address/address_info.sql b/files/grest/rpc/address/address_info.sql index c5c9bb2f..84057380 100644 --- a/files/grest/rpc/address/address_info.sql +++ b/files/grest/rpc/address/address_info.sql @@ -13,12 +13,13 @@ DECLARE BEGIN CREATE TEMPORARY TABLE _known_addresses AS SELECT - DISTINCT ON (tx_out.address) tx_out.address, + DISTINCT ON (tx_out.address_id) a.address, sa.hash_raw AS stake_address_raw, - COALESCE(tx_out.address_has_script, 'false') AS script_address + COALESCE(a.has_script, 'false') AS script_address FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON sa.id = tx_out.stake_address_id - WHERE tx_out.address = ANY(_addresses); + WHERE a.address = ANY(_addresses); RETURN QUERY WITH _all_utxos AS ( @@ -26,7 +27,7 @@ BEGIN tx.id, tx.hash, tx_out.id AS txo_id, - tx_out.address, + a.address, tx_out.value, tx_out.index, tx.block_id, @@ -34,9 +35,10 @@ BEGIN tx_out.inline_datum_id, tx_out.reference_script_id FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id INNER JOIN tx ON tx.id = tx_out.tx_id WHERE tx_out.consumed_by_tx_id IS NULL - AND tx_out.address = ANY(_addresses) + AND a.address = ANY(_addresses) ) SELECT diff --git a/files/grest/rpc/address/address_txs.sql b/files/grest/rpc/address/address_txs.sql index c8ccb464..ceaf59de 100644 --- a/files/grest/rpc/address/address_txs.sql +++ b/files/grest/rpc/address/address_txs.sql @@ -28,8 +28,9 @@ BEGIN -- SELECT consumed_by_tx_id FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id WHERE tx_out.consumed_by_tx_id IS NOT NULL - AND tx_out.address = ANY(_addresses) + AND a.address = ANY(_addresses) AND tx_out.consumed_by_tx_id >= _tx_id_min ) AS tmp; diff --git a/files/grest/rpc/address/address_utxos.sql b/files/grest/rpc/address/address_utxos.sql index 5cbc4363..1ffb8130 100644 --- a/files/grest/rpc/address/address_utxos.sql +++ b/files/grest/rpc/address/address_utxos.sql @@ -35,20 +35,21 @@ BEGIN ) END) as assets FROM tx_out AS txo + INNER JOIN address AS a ON a.id = tx_out.address_id INNER JOIN ma_tx_out AS mto ON mto.tx_out_id = txo.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id - WHERE txo.address = ANY(_addresses) + WHERE a.address = ANY(_addresses) AND txo.consumed_by_tx_id IS NULL GROUP BY txo.id ) SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw)::text as stake_address, - ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, + ENCODE(a.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, EXTRACT(EPOCH FROM b.time)::integer AS block_time, @@ -79,13 +80,14 @@ BEGIN ELSE true END) AS is_spent FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id INNER JOIN tx ON tx_out.tx_id = tx.id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id LEFT JOIN script ON script.id = tx_out.reference_script_id LEFT JOIN _assets ON tx_out.id = _assets.id - WHERE tx_out.address = ANY(_addresses) + WHERE a.address = ANY(_addresses) AND tx_out.consumed_by_tx_id IS NULL ; END; diff --git a/files/grest/rpc/address/credential_txs.sql b/files/grest/rpc/address/credential_txs.sql index ee50321c..bc534e9a 100644 --- a/files/grest/rpc/address/credential_txs.sql +++ b/files/grest/rpc/address/credential_txs.sql @@ -29,15 +29,17 @@ BEGIN FROM ( SELECT tx_id FROM tx_out - WHERE payment_cred = ANY(_payment_cred_bytea) + INNER JOIN address AS a ON tx_out.address_id = a.id + WHERE a.payment_cred = ANY(_payment_cred_bytea) AND tx_id >= _tx_id_min -- UNION -- SELECT consumed_by_tx_id AS tx_id FROM tx_out + INNER JOIN address AS a ON tx_out.address_id = a.id WHERE tx_out.consumed_by_tx_id IS NOT NULL - AND tx_out.payment_cred = ANY(_payment_cred_bytea) + AND a.payment_cred = ANY(_payment_cred_bytea) AND tx_out.consumed_by_tx_id >= _tx_id_min ) AS tmp; diff --git a/files/grest/rpc/address/credential_utxos.sql b/files/grest/rpc/address/credential_utxos.sql index 57bfe179..c5c066f1 100644 --- a/files/grest/rpc/address/credential_utxos.sql +++ b/files/grest/rpc/address/credential_utxos.sql @@ -41,20 +41,21 @@ BEGIN ) END) as assets FROM tx_out AS txo + INNER JOIN address ON a.id = txo.address_id INNER JOIN ma_tx_out AS mto ON mto.tx_out_id = txo.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id - WHERE txo.payment_cred = ANY(_payment_cred_bytea) + WHERE a.payment_cred = ANY(_payment_cred_bytea) AND txo.consumed_by_tx_id IS NULL GROUP BY txo.id ) SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw)::text as stake_address, - ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, + ENCODE(a.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, EXTRACT(EPOCH FROM b.time)::integer AS block_time, @@ -85,13 +86,15 @@ BEGIN ELSE true END) AS is_spent FROM tx_out + INNER JOIN address ON a.id = tx_out.address_id INNER JOIN tx ON tx_out.tx_id = tx.id + INNER JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id LEFT JOIN script ON script.id = tx_out.reference_script_id LEFT JOIN _assets ON tx_out.id = _assets.id - WHERE tx_out.payment_cred = ANY(_payment_cred_bytea) + WHERE a.payment_cred = ANY(_payment_cred_bytea) AND tx_out.consumed_by_tx_id IS NULL ; END; diff --git a/files/grest/rpc/assets/asset_addresses.sql b/files/grest/rpc/assets/asset_addresses.sql index 466bdc48..d707119d 100644 --- a/files/grest/rpc/assets/asset_addresses.sql +++ b/files/grest/rpc/assets/asset_addresses.sql @@ -33,11 +33,12 @@ BEGIN FROM ( SELECT - txo.address, + a.address, sa.hash_raw AS stake_address_raw, atoc.quantity FROM grest.asset_tx_out_cache AS atoc LEFT JOIN tx_out AS txo ON atoc.txo_id = txo.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE atoc.ma_id = _asset_id AND txo.consumed_by_tx_id IS NULL @@ -52,11 +53,12 @@ BEGIN FROM ( SELECT - txo.address, + a.address, sa.hash_raw AS stake_address_raw, mto.quantity FROM ma_tx_out AS mto LEFT JOIN tx_out AS txo ON txo.id = mto.tx_out_id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE mto.ident = _asset_id AND txo.consumed_by_tx_id IS NULL diff --git a/files/grest/rpc/assets/asset_nft_address.sql b/files/grest/rpc/assets/asset_nft_address.sql index 2c5ca3f5..cd5949ad 100644 --- a/files/grest/rpc/assets/asset_nft_address.sql +++ b/files/grest/rpc/assets/asset_nft_address.sql @@ -27,9 +27,10 @@ BEGIN IF EXISTS (SELECT * FROM ma_tx_mint WHERE ident = _asset_id and quantity < 0 LIMIT 1) THEN RETURN QUERY SELECT - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE txo.id = ( SELECT MAX(tx_out_id) @@ -39,9 +40,10 @@ BEGIN ELSE RETURN QUERY SELECT - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = tx_out.address_id INNER JOIN ma_tx_out mto ON mto.tx_out_id = txo.id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE mto.ident = _asset_id diff --git a/files/grest/rpc/assets/asset_summary.sql b/files/grest/rpc/assets/asset_summary.sql index 4c77e222..5f3016ba 100644 --- a/files/grest/rpc/assets/asset_summary.sql +++ b/files/grest/rpc/assets/asset_summary.sql @@ -32,10 +32,11 @@ BEGIN txo.tx_id AS tx_id, txo.id AS tx_out_id, txo.index AS tx_out_idx, - txo.address AS address, + a.address AS address, txo.stake_address_id AS sa_id FROM ma_tx_out AS mto INNER JOIN tx_out AS txo ON txo.id = mto.tx_out_id + LEFT JOIN address AS a ON a.id = tx_out.address_id WHERE mto.ident = _asset_id AND txo.consumed_by_tx_id IS NULL) diff --git a/files/grest/rpc/assets/asset_utxos.sql b/files/grest/rpc/assets/asset_utxos.sql index 25d5df08..e82390e5 100644 --- a/files/grest/rpc/assets/asset_utxos.sql +++ b/files/grest/rpc/assets/asset_utxos.sql @@ -64,10 +64,10 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw)::text as stake_address, - ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, + ENCODE(a.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, EXTRACT(EPOCH FROM b.time)::integer AS block_time, @@ -99,6 +99,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id INNER JOIN _assets ON tx_out.id = _assets.id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id diff --git a/files/grest/rpc/assets/policy_asset_addresses.sql b/files/grest/rpc/assets/policy_asset_addresses.sql index 6dc0f3ab..bfbc43ea 100644 --- a/files/grest/rpc/assets/policy_asset_addresses.sql +++ b/files/grest/rpc/assets/policy_asset_addresses.sql @@ -27,12 +27,13 @@ BEGIN ( SELECT atoc.ma_id, - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address, atoc.quantity FROM grest.asset_tx_out_cache AS atoc LEFT JOIN multi_asset AS ma ON ma.id = atoc.ma_id LEFT JOIN tx_out AS txo ON txo.id = atoc.txo_id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE ma.policy = DECODE(_asset_policy, 'hex') AND txo.consumed_by_tx_id IS NULL @@ -46,18 +47,19 @@ BEGIN RETURN QUERY SELECT ENCODE(ma.name, 'hex') AS asset_name, - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address, SUM(mto.quantity)::text FROM multi_asset AS ma LEFT JOIN ma_tx_out AS mto ON mto.ident = ma.id LEFT JOIN tx_out AS txo ON txo.id = mto.tx_out_id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE ma.policy = DECODE(_asset_policy, 'hex') AND txo.consumed_by_tx_id IS NULL GROUP BY ma.name, - txo.address, + a.address, sa.hash_raw; END IF; END; diff --git a/files/grest/rpc/governance/proposal_voting_summary.sql b/files/grest/rpc/governance/proposal_voting_summary.sql index ce665f8a..a7beee6c 100644 --- a/files/grest/rpc/governance/proposal_voting_summary.sql +++ b/files/grest/rpc/governance/proposal_voting_summary.sql @@ -1,4 +1,3 @@ - CREATE OR REPLACE FUNCTION grest.proposal_voting_summary(_proposal_id text) RETURNS TABLE ( proposal_type text, diff --git a/files/grest/rpc/pool/pool_info.sql b/files/grest/rpc/pool/pool_info.sql index 1aa659d9..5bf484f2 100644 --- a/files/grest/rpc/pool/pool_info.sql +++ b/files/grest/rpc/pool/pool_info.sql @@ -1,4 +1,3 @@ - CREATE OR REPLACE FUNCTION grest.pool_info(_pool_bech32_ids text []) RETURNS TABLE ( pool_id_bech32 varchar, diff --git a/files/grest/rpc/script/script_utxos.sql b/files/grest/rpc/script/script_utxos.sql index d5120bb3..7c192855 100644 --- a/files/grest/rpc/script/script_utxos.sql +++ b/files/grest/rpc/script/script_utxos.sql @@ -46,10 +46,10 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, - ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, + ENCODE(a.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, EXTRACT(EPOCH FROM b.time)::integer AS block_time, @@ -81,6 +81,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id INNER JOIN script ON script.tx_id = tx.id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id diff --git a/files/grest/rpc/transactions/tx_info.sql b/files/grest/rpc/transactions/tx_info.sql index 7b5707f7..b695f444 100644 --- a/files/grest/rpc/transactions/tx_info.sql +++ b/files/grest/rpc/transactions/tx_info.sql @@ -88,8 +88,8 @@ BEGIN _all_collateral_inputs AS ( SELECT collateral_tx_in.tx_in_id AS tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -129,6 +129,7 @@ BEGIN INNER JOIN tx_out ON tx_out.tx_id = collateral_tx_in.tx_out_id AND tx_out.index = collateral_tx_in.tx_out_index INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident @@ -143,8 +144,8 @@ BEGIN _all_reference_inputs AS ( SELECT reference_tx_in.tx_in_id AS tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -184,6 +185,7 @@ BEGIN INNER JOIN tx_out ON tx_out.tx_id = reference_tx_in.tx_out_id AND tx_out.index = reference_tx_in.tx_out_index INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident @@ -198,8 +200,8 @@ BEGIN _all_inputs AS ( SELECT tx_out.consumed_by_tx_id AS tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -237,6 +239,7 @@ BEGIN ) AS reference_script FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident @@ -250,8 +253,8 @@ BEGIN _all_collateral_outputs AS ( SELECT tx_out.tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -280,6 +283,7 @@ BEGIN FROM collateral_tx_out AS tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN datum ON _scripts IS TRUE AND datum.id = tx_out.inline_datum_id LEFT JOIN script ON _scripts IS TRUE AND script.id = tx_out.reference_script_id @@ -290,8 +294,8 @@ BEGIN _all_outputs AS ( SELECT tx_out.tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -329,6 +333,7 @@ BEGIN ) AS reference_script FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident diff --git a/files/grest/rpc/transactions/tx_utxos.sql b/files/grest/rpc/transactions/tx_utxos.sql index 6ac76a61..05a23897 100644 --- a/files/grest/rpc/transactions/tx_utxos.sql +++ b/files/grest/rpc/transactions/tx_utxos.sql @@ -39,8 +39,8 @@ BEGIN _all_inputs AS ( SELECT tx_out.consumed_by_tx_id AS tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -58,6 +58,7 @@ BEGIN ) AS asset_list FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident @@ -68,8 +69,8 @@ BEGIN _all_outputs AS ( SELECT tx_out.tx_id, - tx_out.address AS payment_addr_bech32, - ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, + a.address AS payment_addr_bech32, + ENCODE(a.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, tx_out.index AS tx_index, @@ -87,6 +88,7 @@ BEGIN ) AS asset_list FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident diff --git a/files/grest/rpc/transactions/utxo_info.sql b/files/grest/rpc/transactions/utxo_info.sql index b1129cc1..92579939 100644 --- a/files/grest/rpc/transactions/utxo_info.sql +++ b/files/grest/rpc/transactions/utxo_info.sql @@ -64,10 +64,10 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, - ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, + ENCODE(a.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, EXTRACT(EPOCH FROM b.time)::integer AS block_time, @@ -99,6 +99,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id