diff --git a/files/grest/rpc/01_cached_tables/pool_info_cache.sql b/files/grest/rpc/01_cached_tables/pool_info_cache.sql index 150b45a9..e9c9aa81 100644 --- a/files/grest/rpc/01_cached_tables/pool_info_cache.sql +++ b/files/grest/rpc/01_cached_tables/pool_info_cache.sql @@ -13,8 +13,8 @@ CREATE TABLE grest.pool_info_cache ( fixed_cost lovelace NOT NULL, pledge lovelace NOT NULL, deposit lovelace, - reward_addr character varying, - owners character varying [], + reward_addr bigint, + owners bigint [], relays jsonb [], meta_id bigint, meta_url character varying, @@ -71,8 +71,6 @@ BEGIN tx_hash, block_time, pool_hash_id, - pool_id_bech32, - pool_id_hex, active_epoch_no, vrf_key_hash, margin, @@ -100,11 +98,10 @@ BEGIN _fixed_cost, _pledge, _deposit, - grest.cip5_hex_to_stake_addr(sa.hash_raw), + _reward_addr_id, ARRAY( - SELECT grest.cip5_hex_to_stake_addr(sa.hash_raw) + SELECT po.addr_id FROM public.pool_owner AS po - INNER JOIN public.stake_address AS sa ON sa.id = po.addr_id WHERE po.pool_update_id = _update_id ), ARRAY( @@ -127,7 +124,6 @@ BEGIN INNER JOIN public.tx ON tx.id = _tx_id INNER JOIN public.block AS b ON b.id = tx.block_id LEFT JOIN public.pool_metadata_ref AS pmr ON pmr.id = _meta_id - LEFT JOIN public.stake_address AS sa ON sa.id = _reward_addr_id WHERE ph.id = _hash_id; END; $$; @@ -260,7 +256,7 @@ BEGIN ELSIF (tg_table_name = 'pool_owner') THEN UPDATE grest.pool_info_cache SET - owners = owners || (SELECT sa.view FROM public.stake_address AS sa WHERE sa.id = new.addr_id) + owners = owners || (SELECT sa.id FROM public.stake_address AS sa WHERE sa.id = new.addr_id) WHERE update_id = new.pool_update_id; END IF; diff --git a/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql b/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql index 7aee259d..3567a3a6 100644 --- a/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql +++ b/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS grest.stake_distribution_cache ( - stake_address_raw addr29type PRIMARY KEY, + stake_address_id bigint PRIMARY KEY, pool_id bigint, total_balance numeric, utxo numeric, @@ -31,7 +31,6 @@ BEGIN accounts_with_delegated_pools AS ( SELECT DISTINCT ON (stake_address.id) stake_address.id AS stake_address_id, - stake_address.hash_raw AS stake_address_raw, pool_hash_id FROM stake_address INNER JOIN delegation ON delegation.addr_id = stake_address.id @@ -172,7 +171,7 @@ BEGIN -- INSERT QUERY START INSERT INTO grest.stake_distribution_cache SELECT - awdp.stake_address_raw, + awdp.stake_address_id, pi.pool_id, COALESCE(aas.amount, 0) + COALESCE(ado.amount, 0) - COALESCE(adi.amount, 0) + COALESCE(adr.rewards, 0) + COALESCE(adir.amount, 0) - COALESCE(adw.withdrawals, 0) AS total_balance, COALESCE(aas.amount, 0) + COALESCE(ado.amount, 0) - COALESCE(adi.amount, 0) + COALESCE(adr.rewards, 0) + COALESCE(adir.amount, 0) - COALESCE(adw.withdrawals, 0) - COALESCE(atrew.rewards, 0) - COALESCE(atir.amount, 0) + COALESCE(atw.withdrawals, 0) AS utxo, @@ -190,7 +189,7 @@ BEGIN LEFT JOIN account_delta_rewards AS adr ON adr.stake_address_id = awdp.stake_address_id LEFT JOIN account_delta_instant_rewards AS adir ON adir.stake_address_id = awdp.stake_address_id LEFT JOIN account_delta_withdrawals AS adw ON adw.stake_address_id = awdp.stake_address_id - ON CONFLICT (stake_address_raw) DO + ON CONFLICT (stake_address_id) DO UPDATE SET pool_id = excluded.pool_id, total_balance = excluded.total_balance, @@ -211,9 +210,9 @@ BEGIN -- Clean up de-registered accounts DELETE FROM grest.stake_distribution_cache - WHERE stake_address_raw IN ( + WHERE stake_address_id IN ( SELECT DISTINCT ON (sa.id) - sa.hash_raw + sa.id FROM stake_address AS sa INNER JOIN stake_deregistration AS sd ON sa.id = sd.addr_id WHERE NOT EXISTS ( @@ -227,15 +226,15 @@ BEGIN -- Clean up accounts registered to retired-at-least-once-since pools RAISE NOTICE 'DANGLING delegation cleanup from SDC commencing'; DELETE FROM grest.stake_distribution_cache - WHERE stake_address_raw in ( - SELECT z.stake_address_raw + WHERE stake_address_id in ( + SELECT z.stake_address_id FROM ( SELECT ( SELECT max(d.id) FROM delegation d - INNER JOIN stake_address sd ON sd.hash_raw = sdc.stake_address_raw AND sd.id = d.addr_id) AS last_deleg, - sdc.stake_address_raw + INNER JOIN stake_address sd ON sd.id = sdc.stake_address_id AND sd.id = d.addr_id) AS last_deleg, + sdc.stake_address_id FROM grest.stake_distribution_cache AS sdc ) AS z WHERE grest.is_dangling_delegation(z.last_deleg) diff --git a/files/grest/rpc/01_cached_tables/stake_distribution_new_accounts.sql b/files/grest/rpc/01_cached_tables/stake_distribution_new_accounts.sql index 3a371d52..08e972c0 100644 --- a/files/grest/rpc/01_cached_tables/stake_distribution_new_accounts.sql +++ b/files/grest/rpc/01_cached_tables/stake_distribution_new_accounts.sql @@ -67,7 +67,7 @@ BEGIN -- INSERT QUERY START INSERT INTO grest.stake_distribution_cache SELECT - nra.stake_address_raw, + nra.stake_address_id, ai.delegated_pool AS pool_id, ai.total_balance::lovelace, ai.utxo::lovelace, @@ -76,7 +76,7 @@ BEGIN ai.rewards_available::lovelace FROM newly_registered_accounts AS nra, LATERAL grest.account_info(array[(SELECT grest.cip5_hex_to_stake_addr(nra.stake_address_raw))]) AS ai - ON CONFLICT (stake_address_raw) DO + ON CONFLICT (stake_address_id) DO UPDATE SET pool_id = EXCLUDED.pool_id, diff --git a/files/grest/rpc/03_utilities/cip129.sql b/files/grest/rpc/03_utilities/cip129.sql index 31280fbb..683c7fab 100644 --- a/files/grest/rpc/03_utilities/cip129.sql +++ b/files/grest/rpc/03_utilities/cip129.sql @@ -52,6 +52,7 @@ RETURNS text LANGUAGE plpgsql STABLE AS $$ BEGIN + IF _raw IS NULL THEN RETURN NULL END IF; IF _is_script THEN RETURN b32_encode('cc_hot', ('\x03'::bytea || _raw)::text); ELSE @@ -91,6 +92,7 @@ RETURNS text LANGUAGE plpgsql STABLE AS $$ BEGIN + IF _raw IS NULL THEN RETURN NULL END IF; IF _is_script THEN RETURN b32_encode('cc_cold', ('\x13'::bytea || _raw)::text); ELSE @@ -130,6 +132,7 @@ RETURNS text LANGUAGE plpgsql STABLE AS $$ BEGIN + IF _raw IS NULL THEN RETURN NULL END IF; IF _is_script THEN RETURN b32_encode('drep', ('\x23'::bytea || _raw)::text); ELSE diff --git a/files/grest/rpc/03_utilities/cip5.sql b/files/grest/rpc/03_utilities/cip5.sql index dad66bd3..edd91e50 100644 --- a/files/grest/rpc/03_utilities/cip5.sql +++ b/files/grest/rpc/03_utilities/cip5.sql @@ -2,12 +2,13 @@ -- 0005: Common bech32 prefixes https://cips.cardano.org/cip/CIP-0005 -- 0019: Cardano Addresses https://cips.cardano.org/cip/CIP-0019 -CREATE OR REPLACE FUNCTION grest.cip5_hex_to_stake_addr(hex bytea) +CREATE OR REPLACE FUNCTION grest.cip5_hex_to_stake_addr(_raw bytea) RETURNS text LANGUAGE plpgsql STABLE AS $$ BEGIN - IF SUBSTRING(hex from 2 for 1) = '0' THEN + IF _raw IS NULL THEN RETURN NULL END IF; + IF SUBSTRING(ENCODE(_raw, 'hex') from 2 for 1) = '0' THEN RETURN b32_encode('stake_test', hex::text); ELSE RETURN b32_encode('stake', hex::text); diff --git a/files/grest/rpc/account/account_info_cached.sql b/files/grest/rpc/account/account_info_cached.sql index ca24c9d7..e2b23761 100644 --- a/files/grest/rpc/account/account_info_cached.sql +++ b/files/grest/rpc/account/account_info_cached.sql @@ -31,7 +31,7 @@ BEGIN RETURN QUERY SELECT - grest.cip5_hex_to_stake_addr(sdc.stake_address_raw), + grest.cip5_hex_to_stake_addr(sa.hash_raw), CASE WHEN status_t.registered = TRUE THEN 'registered' ELSE @@ -48,10 +48,10 @@ BEGIN COALESCE(reserves_t.reserves, 0)::text AS reserves, COALESCE(treasury_t.treasury, 0)::text AS treasury FROM grest.stake_distribution_cache AS sdc + INNER JOIN stake_address AS sa ON sa.id = sdc.stake_address_id LEFT JOIN ( SELECT sas.id, - sas.hash_raw, EXISTS ( SELECT TRUE FROM stake_registration WHERE @@ -76,7 +76,7 @@ BEGIN ) AS deposit FROM public.stake_address AS sas WHERE sas.id = ANY(sa_id_list) - ) AS status_t ON sdc.stake_address_raw = status_t.hash_raw + ) AS status_t ON sdc.stake_address_id = status_t.id LEFT JOIN ( SELECT dv.addr_id, @@ -118,10 +118,7 @@ BEGIN GROUP BY t.addr_id ) AS treasury_t ON treasury_t.addr_id = status_t.id - WHERE sdc.stake_address_raw = ANY( - SELECT ARRAY_AGG(DECODE(b32_decode(n), 'hex')) - FROM UNNEST(_stake_addresses) AS n - ) + WHERE sdc.stake_address_id = ANY(sa_id_list) UNION ALL @@ -141,13 +138,13 @@ BEGIN FROM ( SELECT - sa.hash_raw AS stake_address_raw, + grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_address, sa.id AS addr_id FROM stake_address AS sa WHERE sa.id = ANY(sa_id_list) - AND NOT EXISTS (SELECT null FROM grest.stake_distribution_cache AS sdc WHERE sdc.stake_address_raw = sa.hash_raw) + AND NOT EXISTS (SELECT null FROM grest.stake_distribution_cache AS sdc WHERE sdc.stake_address_id = sa.id) ) AS z - , LATERAL grest.account_info(array[(SELECT grest.cip5_hex_to_stake_addr(z.stake_address_raw))]) AS ai + , LATERAL grest.account_info(array[stake_address]) AS ai ; END; diff --git a/files/grest/rpc/governance/drep_delegators.sql b/files/grest/rpc/governance/drep_delegators.sql index 80d759d9..95df4fa5 100644 --- a/files/grest/rpc/governance/drep_delegators.sql +++ b/files/grest/rpc/governance/drep_delegators.sql @@ -89,7 +89,7 @@ BEGIN INNER JOIN stake_address AS sa ON ad.addr_id = sa.id INNER JOIN tx ON ad.tx_id = tx.id INNER JOIN block AS b ON tx.block_id = b.id - LEFT JOIN grest.stake_distribution_cache AS sdc ON sa.view = sdc.stake_address + LEFT JOIN grest.stake_distribution_cache AS sdc ON sa.id = sdc.stake_address_id ORDER BY b.epoch_no DESC, grest.cip5_hex_to_stake_addr(sa.hash_raw) ); diff --git a/files/grest/rpc/pool/pool_delegators.sql b/files/grest/rpc/pool/pool_delegators.sql index 6dab740a..d77c82da 100644 --- a/files/grest/rpc/pool/pool_delegators.sql +++ b/files/grest/rpc/pool/pool_delegators.sql @@ -16,7 +16,7 @@ BEGIN _all_delegations AS ( SELECT sa.id AS stake_address_id, - sdc.stake_address_raw, + sa.hash_raw AS stake_address_raw, ( CASE WHEN sdc.total_balance >= 0 THEN sdc.total_balance @@ -24,7 +24,7 @@ BEGIN END ) AS total_balance FROM grest.stake_distribution_cache AS sdc - INNER JOIN public.stake_address AS sa ON sa.hash_raw = sdc.stake_address_raw + INNER JOIN public.stake_address AS sa ON sa.id = sdc.stake_address_id WHERE sdc.pool_id = _pool_bech32 UNION ALL @@ -43,7 +43,7 @@ BEGIN AND NOT EXISTS (SELECT null FROM delegation AS d2 WHERE d2.addr_id = d.addr_id AND d2.id > d.id) AND NOT EXISTS (SELECT null FROM stake_deregistration AS sd WHERE sd.addr_id = d.addr_id AND sd.tx_id > d.tx_id) -- AND NOT grest.is_dangling_delegation(d.id) - AND NOT EXISTS (SELECT null FROM grest.stake_distribution_cache AS sdc WHERE sdc.stake_address_raw = sa.hash_raw) + AND NOT EXISTS (SELECT null FROM grest.stake_distribution_cache AS sdc WHERE sdc.stake_address_id = sa.id) ) z, LATERAL grest.account_utxos(array[(SELECT grest.cip5_hex_to_stake_addr(z.stake_address_raw))], false) AS acc_info GROUP BY @@ -88,7 +88,7 @@ BEGIN _all_delegations AS ( SELECT sa.id AS stake_address_id, - sdc.stake_address_raw, + sa.hash_raw AS stake_address_raw, ( CASE WHEN sdc.total_balance >= 0 THEN sdc.total_balance @@ -96,7 +96,7 @@ BEGIN END ) AS total_balance FROM grest.stake_distribution_cache AS sdc - INNER JOIN public.stake_address AS sa ON sa.hash_raw = sdc.stake_address_raw + INNER JOIN public.stake_address AS sa ON sa.id = sdc.stake_address_id WHERE sdc.pool_id = _pool_bech32 UNION ALL @@ -114,7 +114,7 @@ BEGIN AND NOT EXISTS (SELECT null FROM delegation AS d2 WHERE d2.addr_id = d.addr_id AND d2.id > d.id) AND NOT EXISTS (SELECT null FROM stake_deregistration AS sd WHERE sd.addr_id = d.addr_id AND sd.tx_id > d.tx_id) -- AND NOT grest.is_dangling_delegation(d.id) - AND NOT EXISTS (SELECT null FROM grest.stake_distribution_cache AS sdc WHERE sdc.stake_address_raw = sa.hash_raw) + AND NOT EXISTS (SELECT null FROM grest.stake_distribution_cache AS sdc WHERE sdc.stake_address_id = sa.id) ) z, LATERAL grest.account_utxos(array[(SELECT grest.cip5_hex_to_stake_addr(z.stake_address_raw))], false) AS acc_info GROUP BY diff --git a/files/grest/rpc/pool/pool_updates.sql b/files/grest/rpc/pool/pool_updates.sql index 14c0368e..990f2879 100644 --- a/files/grest/rpc/pool/pool_updates.sql +++ b/files/grest/rpc/pool/pool_updates.sql @@ -37,8 +37,8 @@ BEGIN pu.margin, pu.fixed_cost::text, pu.pledge::text, - sa.view AS reward_addr, - JSONB_AGG(po.view) AS owners, + grest.cip5_hex_to_stake_addr(sa.hash_raw) AS reward_addr, + JSONB_AGG(po.stake_address) AS owners, JSONB_AGG(JSONB_BUILD_OBJECT ( 'ipv4', pr.ipv4, 'ipv6', pr.ipv6, @@ -57,7 +57,7 @@ BEGIN INNER JOIN public.block AS b ON b.id = tx.block_id LEFT JOIN public.stake_address AS sa ON pu.reward_addr_id = sa.id LEFT JOIN ( - SELECT po1.pool_update_id, sa1.view + SELECT po1.pool_update_id, grest.cip5_hex_to_stake_addr(sa1.hash_raw) AS stake_address FROM public.pool_owner AS po1 LEFT JOIN public.stake_address AS sa1 ON sa1.id = po1.addr_id ) AS po ON pu.id = po.pool_update_id @@ -66,7 +66,7 @@ BEGIN LEFT JOIN public.off_chain_pool_data AS ocpd ON pu.meta_id = ocpd.pmr_id WHERE _pool_bech32 IS NULL OR ph.hash_raw = DECODE(b32_decode(_pool_bech32),'hex') - GROUP BY tx.hash, b.time, ph.hash_raw, ph.hash_raw, pu.active_epoch_no, pu.vrf_key_hash, pu.margin, pu.fixed_cost, pu.pledge, sa.view, pmr.url, pmr.hash, ocpd.json), + GROUP BY tx.hash, b.time, ph.hash_raw, ph.hash_raw, pu.active_epoch_no, pu.vrf_key_hash, pu.margin, pu.fixed_cost, pu.pledge, sa.hash_raw, pmr.url, pmr.hash, ocpd.json), pool_dereg AS ( SELECT ENCODE(tx.hash::bytea, 'hex') AS tx_hash, diff --git a/files/grest/rpc/script/script_utxos.sql b/files/grest/rpc/script/script_utxos.sql index 68419423..d5120bb3 100644 --- a/files/grest/rpc/script/script_utxos.sql +++ b/files/grest/rpc/script/script_utxos.sql @@ -48,7 +48,7 @@ BEGIN tx_out.index::smallint, tx_out.address::text, tx_out.value::text, - sa.view::text as stake_address, + grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no, diff --git a/files/grest/rpc/transactions/tx_info.sql b/files/grest/rpc/transactions/tx_info.sql index cc815165..7b5707f7 100644 --- a/files/grest/rpc/transactions/tx_info.sql +++ b/files/grest/rpc/transactions/tx_info.sql @@ -90,7 +90,7 @@ BEGIN 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, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, @@ -145,7 +145,7 @@ BEGIN 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, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, @@ -200,7 +200,7 @@ BEGIN 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, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, @@ -252,7 +252,7 @@ BEGIN tx_out.tx_id, tx_out.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, @@ -292,7 +292,7 @@ BEGIN tx_out.tx_id, tx_out.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, @@ -347,7 +347,7 @@ BEGIN w.tx_id, JSONB_BUILD_OBJECT( 'amount', w.amount::text, - 'stake_addr', sa.view + 'stake_addr', grest.cip5_hex_to_stake_addr(sa.hash_raw) ) AS data FROM withdrawal AS w INNER JOIN stake_address AS sa ON w.addr_id = sa.id @@ -404,7 +404,7 @@ BEGIN 'index', sr.cert_index, 'type', 'stake_registration', 'info', JSONB_BUILD_OBJECT( - 'stake_address', sa.view, + 'stake_address', grest.cip5_hex_to_stake_addr(sa.hash_raw), 'deposit', sr.deposit::text ) ) AS data @@ -421,7 +421,7 @@ BEGIN 'index', sd.cert_index, 'type', 'stake_deregistration', 'info', JSONB_BUILD_OBJECT( - 'stake_address', sa.view + 'stake_address', grest.cip5_hex_to_stake_addr(sa.hash_raw) ) ) AS data FROM public.stake_deregistration AS sd @@ -437,7 +437,7 @@ BEGIN 'index', d.cert_index, 'type', 'pool_delegation', 'info', JSONB_BUILD_OBJECT( - 'stake_address', sa.view, + 'stake_address', grest.cip5_hex_to_stake_addr(sa.hash_raw), 'pool_id_bech32', b32_encode('pool', ph.hash_raw::text), 'pool_id_hex', ENCODE(ph.hash_raw, 'hex') ) @@ -456,7 +456,7 @@ BEGIN 'index', t.cert_index, 'type', 'treasury_MIR', 'info', JSONB_BUILD_OBJECT( - 'stake_address', sa.view, + 'stake_address', grest.cip5_hex_to_stake_addr(sa.hash_raw), 'amount', t.amount::text ) ) AS data @@ -473,7 +473,7 @@ BEGIN 'index', r.cert_index, 'type', 'reserve_MIR', 'info', JSONB_BUILD_OBJECT( - 'stake_address', sa.view, + 'stake_address', grest.cip5_hex_to_stake_addr(sa.hash_raw), 'amount', r.amount::text ) ) AS data @@ -546,8 +546,8 @@ BEGIN 'margin', pu.margin, 'fixed_cost', pu.fixed_cost::text, 'pledge', pu.pledge::text, - 'reward_addr', sa.view, - 'owners', JSONB_AGG(po.view), + 'reward_addr', grest.cip5_hex_to_stake_addr(sa.hash_raw), + 'owners', JSONB_AGG(po.stake_address), 'relays', JSONB_AGG(JSONB_BUILD_OBJECT ( 'ipv4', pr.ipv4, 'ipv6', pr.ipv6, @@ -563,7 +563,7 @@ BEGIN LEFT JOIN public.pool_hash AS ph ON pu.hash_id = ph.id LEFT JOIN public.stake_address AS sa ON pu.reward_addr_id = sa.id LEFT JOIN ( - SELECT po1.pool_update_id, sa1.view + SELECT po1.pool_update_id, grest.cip5_hex_to_stake_addr(sa1.hash_raw) AS stake_address FROM public.pool_owner AS po1 LEFT JOIN public.stake_address AS sa1 ON sa1.id = po1.addr_id ) AS po ON pu.id = po.pool_update_id @@ -571,7 +571,7 @@ BEGIN LEFT JOIN public.pool_metadata_ref AS pmr ON pu.meta_id = pmr.id WHERE _certs IS TRUE AND pu.registered_tx_id = ANY(_tx_id_list) - GROUP BY pu.registered_tx_id, pu.cert_index, ph.hash_raw, pu.active_epoch_no, pu.vrf_key_hash, pu.margin, pu.fixed_cost, pu.pledge, sa.view, pmr.url, pmr.hash + GROUP BY pu.registered_tx_id, pu.cert_index, ph.hash_raw, pu.active_epoch_no, pu.vrf_key_hash, pu.margin, pu.fixed_cost, pu.pledge, sa.hash_raw, pmr.url, pmr.hash -- UNION ALL -- @@ -581,8 +581,8 @@ BEGIN 'index', dv.cert_index, 'type', 'vote_delegation', 'info', JSONB_BUILD_OBJECT( - 'stake_address', sa.view, - 'drep_id', dh.view, + 'stake_address', grest.cip5_hex_to_stake_addr(sa.hash_raw), + 'drep_id', COALESCE(grest.cip129_hex_to_drep_id(dh.raw, dh.has_script), dh.view::text), 'drep_hex', ENCODE(dh.raw, 'hex') ) ) AS data @@ -600,7 +600,7 @@ BEGIN 'index', dr.cert_index, 'type', 'drep_registration', 'info', JSONB_BUILD_OBJECT( - 'drep_id', dh.view, + 'drep_id', grest.cip129_hex_to_drep_id(dh.raw, dh.has_script), 'drep_hex', ENCODE(dh.raw, 'hex'), 'deposit', dr.deposit::text, 'meta_url', va.url, @@ -623,7 +623,7 @@ BEGIN 'index', dr.cert_index, 'type', 'drep_update', 'info', JSONB_BUILD_OBJECT( - 'drep_id', dh.view, + 'drep_id', grest.cip129_hex_to_drep_id(dh.raw, dh.has_script), 'drep_hex', ENCODE(dh.raw, 'hex'), 'meta_url', va.url, 'meta_hash', va.data_hash @@ -644,7 +644,7 @@ BEGIN 'index', dr.cert_index, 'type', 'drep_retire', 'info', JSONB_BUILD_OBJECT( - 'drep_id', dh.view, + 'drep_id', grest.cip129_hex_to_drep_id(dh.raw, dh.has_script), 'drep_hex', ENCODE(dh.raw, 'hex') ) ) AS data @@ -848,7 +848,7 @@ BEGIN 'proposal_tx_hash', ENCODE(tx.hash, 'hex'), 'proposal_index', gap.index, 'voter_role', vp.voter_role, - 'voter', COALESCE(ENCODE(ch.raw, 'hex'), dh.view, b32_encode('pool', ph.hash_raw::text)), + 'voter', COALESCE(grest.cip129_hex_to_drep_id(dh.raw, dh.has_script), dh.view::text, grest.cip129_hex_to_cc_hot(ch.raw, ch.has_script), b32_encode('pool', ph.hash_raw::text)), 'voter_hex', COALESCE(ENCODE(ch.raw, 'hex'), ENCODE(dh.raw, 'hex'), ENCODE(ph.hash_raw, 'hex')), 'vote', vp.vote ) AS data @@ -876,7 +876,7 @@ BEGIN 'type', gap.type, 'description', gap.description, 'deposit', gap.deposit::text, - 'return_address', sa.view, + 'return_address', grest.cip5_hex_to_stake_addr(sa.hash_raw), 'expiration', gap.expiration, 'meta_url', va.url, 'meta_hash', ENCODE(va.data_hash, 'hex'), @@ -885,7 +885,7 @@ BEGIN ELSE JSONB_BUILD_OBJECT( 'stake_address', ( - SELECT sa2.view + SELECT grest.cip5_hex_to_stake_addr(sa2.hash_raw) FROM stake_address AS sa2 WHERE sa2.id = tw.stake_address_id ), diff --git a/files/grest/rpc/transactions/tx_utxos.sql b/files/grest/rpc/transactions/tx_utxos.sql index 221b3169..6ac76a61 100644 --- a/files/grest/rpc/transactions/tx_utxos.sql +++ b/files/grest/rpc/transactions/tx_utxos.sql @@ -41,7 +41,7 @@ BEGIN 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, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, @@ -70,7 +70,7 @@ BEGIN tx_out.tx_id, tx_out.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, - sa.view AS stake_addr, + 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, tx_out.value::text AS value, diff --git a/files/grest/rpc/transactions/utxo_info.sql b/files/grest/rpc/transactions/utxo_info.sql index 53b65301..b1129cc1 100644 --- a/files/grest/rpc/transactions/utxo_info.sql +++ b/files/grest/rpc/transactions/utxo_info.sql @@ -66,7 +66,7 @@ BEGIN tx_out.index::smallint, tx_out.address::text, tx_out.value::text, - sa.view::text as stake_address, + grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, b.epoch_no, b.block_no,