Skip to content

Commit

Permalink
various updates
Browse files Browse the repository at this point in the history
- update committee_info to include both cold and hot(if available) key info
- make committee_votes input optional
- add url & hash to all _votes endpoints
- schema updates
  • Loading branch information
Scitz0 committed Aug 5, 2024
1 parent 827a220 commit b7a7d5f
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 38 deletions.
26 changes: 23 additions & 3 deletions files/grest/rpc/governance/committee_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,34 @@ BEGIN
c.quorum_denominator,
JSONB_AGG(
JSONB_BUILD_OBJECT(
'hex', ENCODE(ch.raw, 'hex'),
'has_script', ch.has_script,
'cc_cold_hex', ENCODE(ch_cold.raw, 'hex'),
'cc_cold_has_script', ch_cold.has_script,
'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
FROM public.committee AS c
INNER JOIN public.committee_member AS cm ON c.id = cm.committee_id
INNER JOIN public.committee_hash AS ch ON cm.committee_hash_id = ch.id
INNER JOIN public.committee_hash AS ch_cold ON ch_cold.id = cm.committee_hash_id
LEFT JOIN LATERAL (
SELECT
ch_hot.raw,
ch_hot.has_script
FROM
public.committee_registration AS cr
INNER JOIN public.committee_hash AS ch_hot ON ch_hot.id = cr.hot_key_id
WHERE
cr.cold_key_id = ch_cold.id
AND NOT EXISTS (
SELECT TRUE
FROM committee_de_registration AS cdr
WHERE cdr.cold_key_id = cr.cold_key_id
AND cdr.tx_id > cr.tx_id
)
ORDER BY cr.id DESC
LIMIT 1
) AS hot_key ON TRUE
WHERE
CASE
WHEN gap_id IS NULL THEN c.gov_action_proposal_id IS NULL
Expand Down
17 changes: 13 additions & 4 deletions files/grest/rpc/governance/committee_votes.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
CREATE OR REPLACE FUNCTION grest.committee_votes(_committee_hash text)
CREATE OR REPLACE FUNCTION grest.committee_votes(_committee_hash text DEFAULT NULL)
RETURNS TABLE (
proposal_tx_hash text,
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text
vote text,
meta_url text,
meta_hash text
)
LANGUAGE sql STABLE
AS $$
Expand All @@ -13,14 +15,21 @@ AS $$
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote
vp.vote,
va.url,
ENCODE(va.data_hash, 'hex')
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 prop_tx ON gap.tx_id = prop_tx.id
INNER JOIN public.tx vote_tx on vp.tx_id = vote_tx.id
INNER JOIN public.block AS b ON vote_tx.block_id = b.id
WHERE ch.raw = DECODE(_committee_hash, 'hex')
LEFT JOIN public.voting_anchor AS va ON vp.voting_anchor_id = va.id
WHERE
CASE
WHEN _committee_hash IS NULL THEN TRUE
ELSE ch.raw = DECODE(_committee_hash, 'hex')
END
ORDER BY
vote_tx.id DESC;
$$;
Expand Down
9 changes: 7 additions & 2 deletions files/grest/rpc/governance/drep_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ RETURNS TABLE (
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text
vote text,
meta_url text,
meta_hash text
)
LANGUAGE sql STABLE
AS $$
Expand All @@ -13,13 +15,16 @@ AS $$
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote
vp.vote,
va.url,
ENCODE(va.data_hash, 'hex')
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 prop_tx ON gap.tx_id = prop_tx.id
INNER JOIN public.tx vote_tx on vp.tx_id = vote_tx.id
INNER JOIN public.block AS b ON vote_tx.block_id = b.id
LEFT JOIN public.voting_anchor AS va ON vp.voting_anchor_id = va.id
WHERE dh.view = _drep_id
ORDER BY
vote_tx.id DESC;
Expand Down
9 changes: 7 additions & 2 deletions files/grest/rpc/governance/proposal_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ RETURNS TABLE (
voter_role text,
voter text,
voter_hex text,
vote text
vote text,
meta_url text,
meta_hash text
)
LANGUAGE sql STABLE
AS $$
Expand All @@ -16,7 +18,9 @@ AS $$
vp.voter_role,
COALESCE(ENCODE(ch.raw, 'hex'), dh.view, ph.view) as voter,
COALESCE(ENCODE(ch.raw, 'hex'), ENCODE(dh.raw, 'hex'), ENCODE(ph.hash_raw, 'hex')) as voter_hex,
vp.vote
vp.vote,
va.url,
ENCODE(va.data_hash, 'hex')
FROM public.voting_procedure AS vp
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
Expand All @@ -25,6 +29,7 @@ AS $$
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
LEFT JOIN public.voting_anchor AS va ON vp.voting_anchor_id = va.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?
Expand Down
9 changes: 7 additions & 2 deletions files/grest/rpc/pool/pool_votes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ RETURNS TABLE (
proposal_index integer,
vote_tx_hash text,
block_time integer,
vote text
vote text,
meta_url text,
meta_hash text
)
LANGUAGE sql STABLE
AS $$
Expand All @@ -13,13 +15,16 @@ AS $$
gap.index,
ENCODE(vote_tx.hash, 'hex'),
EXTRACT(EPOCH FROM b.time)::integer,
vp.vote
vp.vote,
va.url,
ENCODE(va.data_hash, 'hex')
FROM public.pool_hash ph
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 prop_tx ON gap.tx_id = prop_tx.id
INNER JOIN public.tx vote_tx on vp.tx_id = vote_tx.id
INNER JOIN public.block AS b ON vote_tx.block_id = b.id
LEFT JOIN public.voting_anchor AS va ON vp.voting_anchor_id = va.id
WHERE ph.view = _pool_bech32
ORDER BY
vote_tx.id DESC;
Expand Down
30 changes: 25 additions & 5 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5265,6 +5265,10 @@ components:
enum: ["Yes","No","Abstain"]
description: Actual Vote casted
example: "Yes"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
pool_votes:
description: List of all votes casted by requested pool
type: array
Expand Down Expand Up @@ -5387,6 +5391,10 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
committee_info:
description: Current governance committee
type: object
Expand All @@ -5407,13 +5415,25 @@ components:
items:
type: object
properties:
hex:
cc_cold_hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
description: Committee member cold key hash in hex format
example: 6095e643ea6f1cccb6e463ec34349026b3a48621aac5d512655ab1bf
cc_cold_has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
description: Flag which shows if this committee member cold credential is a script hash
example: false
cc_hot_hex:
type:
- string
- 'null'
description: Committee member key hash from last hot key authorization certificate in hex format
example: 65d497b875c56ab213586a4006d4f6658970573ea8e2398893857472
cc_hot_has_script:
type:
- boolean
- 'null'
description: Flag which shows if this committee member hot credential is a script hash
example: false
expiration_epoch:
type: number
Expand Down
30 changes: 25 additions & 5 deletions specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5265,6 +5265,10 @@ components:
enum: ["Yes","No","Abstain"]
description: Actual Vote casted
example: "Yes"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
pool_votes:
description: List of all votes casted by requested pool
type: array
Expand Down Expand Up @@ -5387,6 +5391,10 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
committee_info:
description: Current governance committee
type: object
Expand All @@ -5407,13 +5415,25 @@ components:
items:
type: object
properties:
hex:
cc_cold_hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
description: Committee member cold key hash in hex format
example: 6095e643ea6f1cccb6e463ec34349026b3a48621aac5d512655ab1bf
cc_cold_has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
description: Flag which shows if this committee member cold credential is a script hash
example: false
cc_hot_hex:
type:
- string
- 'null'
description: Committee member key hash from last hot key authorization certificate in hex format
example: 65d497b875c56ab213586a4006d4f6658970573ea8e2398893857472
cc_hot_has_script:
type:
- boolean
- 'null'
description: Flag which shows if this committee member hot credential is a script hash
example: false
expiration_epoch:
type: number
Expand Down
30 changes: 25 additions & 5 deletions specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5265,6 +5265,10 @@ components:
enum: ["Yes","No","Abstain"]
description: Actual Vote casted
example: "Yes"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
pool_votes:
description: List of all votes casted by requested pool
type: array
Expand Down Expand Up @@ -5387,6 +5391,10 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
committee_info:
description: Current governance committee
type: object
Expand All @@ -5407,13 +5415,25 @@ components:
items:
type: object
properties:
hex:
cc_cold_hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
description: Committee member cold key hash in hex format
example: 6095e643ea6f1cccb6e463ec34349026b3a48621aac5d512655ab1bf
cc_cold_has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
description: Flag which shows if this committee member cold credential is a script hash
example: false
cc_hot_hex:
type:
- string
- 'null'
description: Committee member key hash from last hot key authorization certificate in hex format
example: 65d497b875c56ab213586a4006d4f6658970573ea8e2398893857472
cc_hot_has_script:
type:
- boolean
- 'null'
description: Flag which shows if this committee member hot credential is a script hash
example: false
expiration_epoch:
type: number
Expand Down
30 changes: 25 additions & 5 deletions specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5265,6 +5265,10 @@ components:
enum: ["Yes","No","Abstain"]
description: Actual Vote casted
example: "Yes"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
pool_votes:
description: List of all votes casted by requested pool
type: array
Expand Down Expand Up @@ -5387,6 +5391,10 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"
meta_url:
$ref: "#/components/schemas/drep_metadata/items/properties/url"
meta_hash:
$ref: "#/components/schemas/drep_metadata/items/properties/hash"
committee_info:
description: Current governance committee
type: object
Expand All @@ -5407,13 +5415,25 @@ components:
items:
type: object
properties:
hex:
cc_cold_hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
description: Committee member cold key hash in hex format
example: 6095e643ea6f1cccb6e463ec34349026b3a48621aac5d512655ab1bf
cc_cold_has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
description: Flag which shows if this committee member cold credential is a script hash
example: false
cc_hot_hex:
type:
- string
- 'null'
description: Committee member key hash from last hot key authorization certificate in hex format
example: 65d497b875c56ab213586a4006d4f6658970573ea8e2398893857472
cc_hot_has_script:
type:
- boolean
- 'null'
description: Flag which shows if this committee member hot credential is a script hash
example: false
expiration_epoch:
type: number
Expand Down
Loading

0 comments on commit b7a7d5f

Please sign in to comment.