Skip to content

Commit

Permalink
Add additional fields to drep_metadata (and address missing 'AS ' as …
Browse files Browse the repository at this point in the history
…per sqlfluff)
  • Loading branch information
rdlrt committed Jul 29, 2024
1 parent 0be13d7 commit ad2274b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 37 deletions.
8 changes: 4 additions & 4 deletions files/grest/rpc/governance/committee_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ AS $$
gap.index AS cert_index,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
vp.vote
FROM public.committee_hash ch
INNER JOIN public.voting_procedure vp ON ch.id = vp.committee_voter
INNER JOIN public.gov_action_proposal gap ON vp.gov_action_proposal_id = gap.id
FROM public.committee_hash AS ch
INNER JOIN public.voting_procedure AS vp ON ch.id = vp.committee_voter
INNER JOIN public.gov_action_proposal AS gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.block b ON tx.block_id = b.id
INNER JOIN public.block AS b ON tx.block_id = b.id
WHERE ch.raw = DECODE(_committee_hash, 'hex')
ORDER BY
block_time DESC;
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/governance/drep_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ BEGIN
dr.deposit::text AS deposit,
(CASE WHEN (dd.active_until IS NOT NULL AND dd.active_until > curr_epoch) OR starts_with(dh.view,'drep_') THEN TRUE ELSE FALSE END) AS active,
COALESCE(dd.amount, 0)::text AS amount
FROM public.drep_hash dh
LEFT JOIN public.drep_registration dr ON dh.id = dr.drep_hash_id
LEFT JOIN public.drep_distr dd ON dh.id = dd.hash_id AND dd.epoch_no = curr_epoch
FROM public.drep_hash AS dh
LEFT JOIN public.drep_registration AS dr ON dh.id = dr.drep_hash_id
LEFT JOIN public.drep_distr AS dd ON dh.id = dd.hash_id AND dd.epoch_no = curr_epoch
WHERE dh.view = ANY(_drep_ids)
ORDER BY
dh.view, dr.tx_id DESC;
Expand Down
4 changes: 2 additions & 2 deletions files/grest/rpc/governance/drep_list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ AS $$
WHEN dr.deposit >= 0 THEN TRUE
ELSE FALSE
END) AS registered
FROM public.drep_hash dh
INNER JOIN public.drep_registration dr ON dh.id = dr.drep_hash_id
FROM public.drep_hash AS dh
INNER JOIN public.drep_registration AS dr ON dh.id = dr.drep_hash_id
ORDER BY
dh.view, dr.tx_id DESC;
$$;
Expand Down
22 changes: 16 additions & 6 deletions files/grest/rpc/governance/drep_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ RETURNS TABLE (
drep_id character varying,
url text,
hash text,
json jsonb
json jsonb,
bytes text,
warning text,
language text,
comment text,
is_valid boolean
)
LANGUAGE sql STABLE
AS $$
SELECT
DISTINCT ON (dh.view) dh.view AS drep_id,
va.url,
ENCODE(va.data_hash, 'hex') AS hash,
ocvd.json
FROM public.drep_hash dh
INNER JOIN public.drep_registration dr ON dh.id = dr.drep_hash_id
LEFT JOIN public.voting_anchor va ON dr.voting_anchor_id = va.id
LEFT JOIN public.off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
ocvd.json,
ENCODE(ocvd.bytes,'hex')::text AS bytes,
ocvd.warning AS warning,
ocvd.language AS language,
ovcd.comment AS comment,
is_valid AS is_valid
FROM public.drep_hash AS dh
INNER JOIN public.drep_registration AS dr ON dh.id = dr.drep_hash_id
LEFT JOIN public.voting_anchor AS va ON dr.voting_anchor_id = va.id
LEFT JOIN public.off_chain_vote_data AS ocvd ON va.id = ocvd.voting_anchor_id
WHERE dh.view = ANY(_drep_ids)
ORDER BY
dh.view, dr.tx_id DESC;
Expand Down
10 changes: 5 additions & 5 deletions files/grest/rpc/governance/drep_updates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ AS $$
va.url AS meta_url,
ENCODE(va.data_hash, 'hex') AS meta_hash,
ocvd.json AS meta_json
FROM public.drep_hash dh
INNER JOIN public.drep_registration dr ON dh.id = dr.drep_hash_id
FROM public.drep_hash AS dh
INNER JOIN public.drep_registration AS dr ON dh.id = dr.drep_hash_id
INNER JOIN public.tx ON dr.tx_id = tx.id
INNER JOIN public.block b ON tx.block_id = b.id
LEFT JOIN public.voting_anchor va ON dr.voting_anchor_id = va.id
LEFT JOIN public.off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
INNER JOIN public.block AS b ON tx.block_id = b.id
LEFT JOIN public.voting_anchor AS va ON dr.voting_anchor_id = va.id
LEFT JOIN public.off_chain_vote_data AS ocvd ON va.id = ocvd.voting_anchor_id
WHERE
CASE
WHEN _drep_id IS NULL THEN TRUE
Expand Down
8 changes: 4 additions & 4 deletions files/grest/rpc/governance/drep_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ AS $$
gap.index AS cert_index,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
vp.vote
FROM public.drep_hash dh
INNER JOIN public.voting_procedure vp ON dh.id = vp.drep_voter
INNER JOIN public.gov_action_proposal gap ON vp.gov_action_proposal_id = gap.id
FROM public.drep_hash AS dh
INNER JOIN public.voting_procedure AS vp ON dh.id = vp.drep_voter
INNER JOIN public.gov_action_proposal AS gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.block b ON tx.block_id = b.id
INNER JOIN public.block AS b ON tx.block_id = b.id
WHERE dh.view = _drep_id
ORDER BY
block_time DESC;
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/governance/pool_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ AS $$
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
vp.vote
FROM public.pool_hash ph
INNER JOIN public.voting_procedure vp ON ph.id = vp.pool_voter
INNER JOIN public.gov_action_proposal gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.voting_procedure AS vp ON ph.id = vp.pool_voter
INNER JOIN public.gov_action_proposal AS gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.block b ON tx.block_id = b.id
INNER JOIN public.block AS b ON tx.block_id = b.id
WHERE ph.view = _pool_bech32
ORDER BY
block_time DESC;
Expand Down
8 changes: 4 additions & 4 deletions files/grest/rpc/governance/proposal_list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ AS $$
va.url AS meta_url,
ENCODE(va.data_hash, 'hex') AS meta_hash,
ocvd.json AS meta_json
FROM public.gov_action_proposal gap
FROM public.gov_action_proposal AS gap
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.block b ON tx.block_id = b.id
INNER JOIN public.stake_address sa ON gap.return_address = sa.id
LEFT JOIN public.voting_anchor va ON gap.voting_anchor_id = va.id
INNER JOIN public.block AS b ON tx.block_id = b.id
INNER JOIN public.stake_address AS sa ON gap.return_address = sa.id
LEFT JOIN public.voting_anchor AS va ON gap.voting_anchor_id = va.id
LEFT JOIN public.off_chain_vote_data AS ocvd ON va.id = ocvd.voting_anchor_id
ORDER BY
block_time DESC;
Expand Down
12 changes: 6 additions & 6 deletions files/grest/rpc/governance/proposal_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ AS $$
COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view),
vp.vote
FROM public.voting_procedure AS vp
INNER JOIN public.gov_action_proposal gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.gov_action_proposal AS gap ON vp.gov_action_proposal_id = gap.id
INNER JOIN public.tx ON gap.tx_id = tx.id
INNER JOIN public.tx vote_tx on vp.tx_id = vote_tx.id
INNER JOIN public.block vote_block on vote_tx.block_id = vote_block.id
LEFT JOIN drep_hash dh ON vp.drep_voter = dh.id
LEFT JOIN pool_hash ph ON vp.pool_voter = ph.id
LEFT JOIN committee_hash ch ON vp.committee_voter = ch.id
INNER JOIN public.tx AS vote_tx ON vp.tx_id = vote_tx.id
INNER JOIN public.block AS vote_block ON vote_tx.block_id = vote_block.id
LEFT JOIN public.drep_hash AS dh ON vp.drep_voter = dh.id
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(_tx_hash, 'hex')
ORDER BY block_time DESC;
$$;
Expand Down

0 comments on commit ad2274b

Please sign in to comment.