Skip to content

Commit

Permalink
fix tx_info, rename cert_index to proposal_index and schema updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Scitz0 committed Aug 5, 2024
1 parent ab01b1c commit 827a220
Show file tree
Hide file tree
Showing 15 changed files with 1,019 additions and 165 deletions.
2 changes: 1 addition & 1 deletion files/grest/rpc/governance/committee_info.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE OR REPLACE FUNCTION grest.committee_info()
RETURNS TABLE (
proposal_tx_hash text,
cert_index bigint,
proposal_index bigint,
quorum_numerator bigint,
quorum_denominator bigint,
members jsonb
Expand Down
10 changes: 5 additions & 5 deletions files/grest/rpc/governance/committee_votes.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
CREATE OR REPLACE FUNCTION grest.committee_votes(_committee_hash text)
RETURNS TABLE (
proposal_tx_hash text,
cert_index integer,
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text
)
LANGUAGE sql STABLE
AS $$
SELECT
ENCODE(prop_tx.hash, 'hex')::text AS proposal_tx_hash,
gap.index AS cert_index,
ENCODE(vote_tx.hash, 'hex')::text AS vote_tx_hash,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
ENCODE(prop_tx.hash, 'hex'),
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote
FROM public.committee_hash AS ch
INNER JOIN public.voting_procedure AS vp ON ch.id = vp.committee_voter
Expand Down
10 changes: 5 additions & 5 deletions files/grest/rpc/governance/drep_votes.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
CREATE OR REPLACE FUNCTION grest.drep_votes(_drep_id text)
RETURNS TABLE (
proposal_tx_hash text,
cert_index integer,
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text
)
LANGUAGE sql STABLE
AS $$
SELECT
ENCODE(prop_tx.hash, 'hex')::text AS proposal_tx_hash,
gap.index AS cert_index,
ENCODE(vote_tx.hash, 'hex')::text AS vote_tx_hash,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
ENCODE(prop_tx.hash, 'hex'),
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote
FROM public.drep_hash AS dh
INNER JOIN public.voting_procedure AS vp ON dh.id = vp.drep_voter
Expand Down
44 changes: 22 additions & 22 deletions files/grest/rpc/governance/proposal_list.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE OR REPLACE FUNCTION grest.proposal_list()
RETURNS TABLE (
proposal_tx_hash text,
cert_index integer,
block_time integer,
proposal_tx_hash text,
proposal_index integer,
proposal_type text,
proposal_description jsonb,
deposit text,
Expand All @@ -25,25 +25,25 @@ RETURNS TABLE (
LANGUAGE sql STABLE
AS $$
SELECT
ENCODE(tx.hash, 'hex')::text AS proposal_tx_hash,
gap.index AS cert_index,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
gap.type AS proposal_type,
gap.description AS proposal_description,
gap.deposit::text AS deposit,
sa.view AS return_address,
b.epoch_no AS proposed_epoch,
gap.ratified_epoch AS ratified_epoch,
gap.enacted_epoch AS enacted_epoch,
gap.dropped_epoch AS dropped_epoch,
gap.expired_epoch AS expired_epoch,
gap.expiration AS expiration,
va.url AS meta_url,
ENCODE(va.data_hash, 'hex') AS meta_hash,
ocvd.json AS meta_json,
ocvd.comment AS meta_comment,
ocvd.language AS meta_language,
ocvd.is_valid AS meta_is_valid,
EXTRACT(EPOCH FROM b.time)::integer,
ENCODE(tx.hash, 'hex'),
gap.index,
gap.type,
gap.description,
gap.deposit::text,
sa.view,
b.epoch_no,
gap.ratified_epoch,
gap.enacted_epoch,
gap.dropped_epoch,
gap.expired_epoch,
gap.expiration,
va.url,
ENCODE(va.data_hash, 'hex'),
ocvd.json,
ocvd.comment,
ocvd.language,
ocvd.is_valid,
CASE
WHEN tw.id IS NULL THEN NULL
ELSE
Expand All @@ -58,7 +58,7 @@ AS $$
END AS withdrawal,
CASE
WHEN pp.id IS NULL THEN NULL
ELSE ( SELECT ROW_TO_JSON(pp.*) )
ELSE ( SELECT JSONB_STRIP_NULLS(TO_JSONB(pp.*)) - array['id','registered_tx_id','epoch_no'] )
END AS param_proposal
FROM public.gov_action_proposal AS gap
INNER JOIN public.tx ON gap.tx_id = tx.id
Expand Down
3 changes: 2 additions & 1 deletion files/grest/rpc/governance/proposal_votes.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE FUNCTION grest.proposal_votes(_proposal_tx_hash text, _cert_index integer)
CREATE OR REPLACE FUNCTION grest.proposal_votes(_proposal_tx_hash text, _proposal_index integer)
RETURNS TABLE (
block_time integer,
voter_role text,
Expand Down Expand Up @@ -26,6 +26,7 @@ AS $$
LEFT JOIN public.pool_hash AS ph ON vp.pool_voter = ph.id
LEFT JOIN public.committee_hash AS ch ON vp.committee_voter = ch.id
WHERE tx.hash = DECODE(_proposal_tx_hash, 'hex')
AND gap.index = _proposal_index
-- will we need a similar filters to the one below for pool and committee member retirements?
AND (
CASE
Expand Down
10 changes: 5 additions & 5 deletions files/grest/rpc/pool/pool_votes.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
CREATE OR REPLACE FUNCTION grest.pool_votes(_pool_bech32 text)
RETURNS TABLE (
proposal_tx_hash text,
cert_index integer,
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text
)
LANGUAGE sql STABLE
AS $$
SELECT
ENCODE(prop_tx.hash, 'hex')::text AS proposal_tx_hash,
gap.index AS cert_index,
ENCODE(vote_tx.hash, 'hex')::text AS vote_tx_hash,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
ENCODE(prop_tx.hash, 'hex'),
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote
FROM public.pool_hash ph
INNER JOIN public.voting_procedure AS vp ON ph.id = vp.pool_voter
Expand Down
Loading

0 comments on commit 827a220

Please sign in to comment.