Skip to content

Commit

Permalink
Restore output to include hex etc in addition to CIP-129 ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Scitz0 committed Aug 25, 2024
1 parent 88d2c44 commit cce4421
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 0 deletions.
23 changes: 23 additions & 0 deletions files/grest/rpc/governance/committee_info.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE OR REPLACE FUNCTION grest.committee_info()
RETURNS TABLE (
proposal_id text,
proposal_tx_hash text,
proposal_index bigint,
quorum_numerator bigint,
quorum_denominator bigint,
members jsonb
Expand Down Expand Up @@ -40,6 +42,23 @@ BEGIN
WHERE gap.id = c.gov_action_proposal_id
)
END,
CASE
WHEN c.gov_action_proposal_id IS NULL THEN NULL
ELSE (
SELECT ENCODE(tx.hash, 'hex')
FROM gov_action_proposal AS gap
INNER JOIN tx on gap.tx_id = tx.id
WHERE gap.id = c.gov_action_proposal_id
)
END,
CASE
WHEN c.gov_action_proposal_id IS NULL THEN NULL
ELSE (
SELECT index
FROM gov_action_proposal AS gap
WHERE gap.id = c.gov_action_proposal_id
)
END,
c.quorum_numerator,
c.quorum_denominator,
JSONB_AGG(
Expand All @@ -57,7 +76,11 @@ BEGIN
'authorized'
END,
'cc_cold_id', (SELECT grest.cip129_hex_to_cc_cold(ch_cold.raw, ch_cold.has_script)),
'cc_cold_hex', ENCODE(ch_cold.raw, 'hex'),
'cc_cold_has_script', ch_cold.has_script,
'cc_hot_id', CASE WHEN hot_key.raw IS NULL THEN NULL ELSE (SELECT grest.cip129_hex_to_cc_hot(hot_key.raw, hot_key.has_script)) END,
'cc_hot_hex', CASE WHEN hot_key.raw IS NULL THEN NULL ELSE ENCODE(hot_key.raw, 'hex') END,
'cc_hot_has_script', CASE WHEN hot_key.has_script IS NULL THEN NULL ELSE hot_key.has_script END,
'expiration_epoch', cm.expiration_epoch
)
) AS members
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/committee_votes.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE OR REPLACE FUNCTION grest.committee_votes(_cc_hot_id text DEFAULT NULL)
RETURNS TABLE (
proposal_id text,
proposal_tx_hash text,
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text,
Expand All @@ -11,6 +13,8 @@ LANGUAGE sql STABLE
AS $$
SELECT
grest.cip129_to_gov_action_id(prop_tx.hash, gap.index),
ENCODE(prop_tx.hash, 'hex'),
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote,
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/drep_info.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE OR REPLACE FUNCTION grest.drep_info(_drep_ids text [])
RETURNS TABLE (
drep_id text,
hex text,
has_script boolean,
registered boolean,
deposit text,
active boolean,
Expand Down Expand Up @@ -120,6 +122,8 @@ BEGIN
ELSE
grest.cip129_hex_to_drep_id(dh.raw, dh.has_script)
END AS drep_id,
ENCODE(dh.raw, 'hex')::text AS hex,
dh.has_script AS has_script,
(CASE WHEN starts_with(dh.view,'drep_') OR (COALESCE(dr.deposit, 0) >= 0 AND dr.drep_hash_id IS NOT NULL) THEN TRUE ELSE FALSE END) AS registered,
(CASE WHEN (dr.deposit < 0) OR starts_with(dh.view,'drep_') THEN NULL ELSE ds.deposit END)::text AS deposit,
(CASE WHEN starts_with(dh.view,'drep_') THEN TRUE ELSE COALESCE(dr.deposit, 0) >= 0 AND ds.active END) AS active,
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/drep_list.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
CREATE OR REPLACE FUNCTION grest.drep_list()
RETURNS TABLE (
drep_id text,
hex text,
has_script boolean,
registered boolean
)
LANGUAGE sql STABLE
AS $$
SELECT DISTINCT ON (dh.raw)
grest.cip129_hex_to_drep_id(dh.raw, dh.has_script) AS drep_id,
ENCODE(dh.raw, 'hex')::text AS hex,
dh.has_script AS has_script,
(CASE
WHEN coalesce(dr.deposit, 0) >= 0 THEN TRUE
ELSE FALSE
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/drep_metadata.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE OR REPLACE FUNCTION grest.drep_metadata(_drep_ids text [])
RETURNS TABLE (
drep_id text,
hex text,
has_script boolean,
url character varying,
hash text,
json jsonb,
Expand All @@ -21,6 +23,8 @@ BEGIN
RETURN QUERY (
SELECT DISTINCT ON (dh.raw)
grest.cip129_hex_to_drep_id(dh.raw, dh.has_script) AS drep_id,
ENCODE(dh.raw, 'hex')::text AS hex,
dh.has_script AS has_script,
va.url,
ENCODE(va.data_hash, 'hex') AS hash,
ocvd.json,
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/drep_updates.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE OR REPLACE FUNCTION grest.drep_updates(_drep_id text DEFAULT NULL)
RETURNS TABLE (
drep_id text,
hex text,
has_script boolean,
update_tx_hash text,
cert_index integer,
block_time integer,
Expand All @@ -14,6 +16,8 @@ LANGUAGE sql STABLE
AS $$
SELECT
grest.cip129_hex_to_drep_id(dh.raw, dh.has_script) AS drep_id,
ENCODE(dh.raw, 'hex')::text AS hex,
dh.has_script AS has_script,
ENCODE(tx.hash, 'hex')::text AS update_tx_hash,
dr.cert_index,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/drep_votes.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CREATE OR REPLACE FUNCTION grest.drep_votes(_drep_id text)
RETURNS TABLE (
proposal_id text,
proposal_tx_hash text,
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text,
Expand All @@ -11,6 +13,8 @@ LANGUAGE sql STABLE
AS $$
SELECT
grest.cip129_to_gov_action_id(prop_tx.hash, gap.index),
ENCODE(prop_tx.hash, 'hex'),
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote,
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/proposal_list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CREATE OR REPLACE FUNCTION grest.proposal_list()
RETURNS TABLE (
block_time integer,
proposal_id text,
proposal_tx_hash text,
proposal_index integer,
proposal_type text,
proposal_description jsonb,
deposit text,
Expand All @@ -26,6 +28,8 @@ AS $$
SELECT
EXTRACT(EPOCH FROM b.time)::integer,
grest.cip129_to_gov_action_id(tx.hash, gap.index),
ENCODE(tx.hash, 'hex'),
gap.index,
gap.type,
gap.description,
gap.deposit::text,
Expand Down
11 changes: 11 additions & 0 deletions files/grest/rpc/governance/proposal_votes.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
CREATE OR REPLACE FUNCTION grest.proposal_votes(_proposal_id text)
RETURNS TABLE (
block_time integer,
voter_role text,
voter_id text,
voter_hex text,
voter_has_script boolean,
vote vote,
meta_url character varying,
meta_hash text
Expand All @@ -19,13 +22,21 @@ BEGIN
FROM (
SELECT DISTINCT ON (COALESCE(dh.raw, ph.hash_raw, ch.raw))
EXTRACT(EPOCH FROM vote_block.time)::integer AS block_time,
vp.voter_role::text,
CASE
WHEN dh.raw IS NOT NULL THEN grest.cip129_hex_to_drep_id(dh.raw, dh.has_script)
WHEN ph.view IS NOT NULL THEN ph.view
WHEN ch.raw IS NOT NULL THEN grest.cip129_hex_to_cc_hot(ch.raw, ch.has_script)
ELSE
'' -- shouldn't happen
END,
COALESCE(ENCODE(ch.raw, 'hex'), ENCODE(dh.raw, 'hex'), ENCODE(ph.hash_raw, 'hex')) AS voter_hex,
CASE
WHEN dh.raw IS NOT NULL THEN dh.has_script
WHEN ch.raw IS NOT NULL THEN ch.has_script
ELSE
FALSE
END AS voter_has_script,
vp.vote,
va.url,
ENCODE(va.data_hash, 'hex')
Expand Down
4 changes: 4 additions & 0 deletions files/grest/rpc/governance/voter_proposal_list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CREATE OR REPLACE FUNCTION grest.voter_proposal_list(_voter_id text)
RETURNS TABLE (
block_time integer,
proposal_id text,
proposal_tx_hash text,
proposal_index bigint,
proposal_type govactiontype,
proposal_description jsonb,
deposit text,
Expand Down Expand Up @@ -56,6 +58,8 @@ BEGIN
SELECT
EXTRACT(EPOCH FROM b.time)::integer,
grest.cip129_to_gov_action_id(tx.hash, gap.index),
ENCODE(tx.hash, 'hex'),
gap.index,
gap.type,
gap.description,
gap.deposit::text,
Expand Down

0 comments on commit cce4421

Please sign in to comment.