Skip to content

Commit

Permalink
Add committee_info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Scitz0 committed Aug 4, 2024
1 parent 070efce commit f73007d
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 5 deletions.
64 changes: 64 additions & 0 deletions files/grest/rpc/governance/committee_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CREATE OR REPLACE FUNCTION grest.committee_info()
RETURNS TABLE (
proposal_tx_hash text,
cert_index bigint,
quorum_numerator bigint,
quorum_denominator bigint,
members jsonb
)
LANGUAGE plpgsql
AS $$
DECLARE
gap_id bigint;
BEGIN

SELECT INTO gap_id id
FROM public.gov_action_proposal
WHERE type = 'NewCommittee'
AND enacted_epoch IS NOT NULL
ORDER BY enacted_epoch DESC
LIMIT 1;

RETURN QUERY (
SELECT
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(
JSONB_BUILD_OBJECT(
'hex', ENCODE(ch.raw, 'hex'),
'has_script', ch.has_script,
'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
WHERE
CASE
WHEN gap_id IS NULL THEN c.gov_action_proposal_id IS NULL
ELSE c.gov_action_proposal_id = gap_id
END
GROUP BY c.gov_action_proposal_id, c.quorum_numerator, c.quorum_denominator
);

END;
$$;

COMMENT ON FUNCTION grest.committee_info IS 'Get information about current governance committee'; --noqa: LT01
33 changes: 32 additions & 1 deletion specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5229,7 +5229,38 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"

committee_info:
description: Current governance committee
type: object
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
cert_index:
$ref: "#/components/schemas/drep_updates/items/properties/cert_index"
quorum_numerator:
type: number
example: 67
quorum_denominator:
type: number
example: 100
members:
description: Array of all members part of active governance committee
type: array
items:
type: object
properties:
hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
example: false
expiration_epoch:
type: number
description: Epoch number in which the committee member vote rights expire
example: 324
script_info:
type: array
items:
Expand Down
33 changes: 32 additions & 1 deletion specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5229,7 +5229,38 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"

committee_info:
description: Current governance committee
type: object
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
cert_index:
$ref: "#/components/schemas/drep_updates/items/properties/cert_index"
quorum_numerator:
type: number
example: 67
quorum_denominator:
type: number
example: 100
members:
description: Array of all members part of active governance committee
type: array
items:
type: object
properties:
hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
example: false
expiration_epoch:
type: number
description: Epoch number in which the committee member vote rights expire
example: 324
script_info:
type: array
items:
Expand Down
33 changes: 32 additions & 1 deletion specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5229,7 +5229,38 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"

committee_info:
description: Current governance committee
type: object
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
cert_index:
$ref: "#/components/schemas/drep_updates/items/properties/cert_index"
quorum_numerator:
type: number
example: 67
quorum_denominator:
type: number
example: 100
members:
description: Array of all members part of active governance committee
type: array
items:
type: object
properties:
hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
example: false
expiration_epoch:
type: number
description: Epoch number in which the committee member vote rights expire
example: 324
script_info:
type: array
items:
Expand Down
33 changes: 32 additions & 1 deletion specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5229,7 +5229,38 @@ components:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"

committee_info:
description: Current governance committee
type: object
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
cert_index:
$ref: "#/components/schemas/drep_updates/items/properties/cert_index"
quorum_numerator:
type: number
example: 67
quorum_denominator:
type: number
example: 100
members:
description: Array of all members part of active governance committee
type: array
items:
type: object
properties:
hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
example: false
expiration_epoch:
type: number
description: Epoch number in which the committee member vote rights expire
example: 324
script_info:
type: array
items:
Expand Down
33 changes: 32 additions & 1 deletion specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,38 @@ schemas:
example: drep1l9y2naagv0vqvft9szdt5wf94fqnxn5hdsgusdl7rf6vq4djqck
vote:
$ref: "#/components/schemas/drep_votes/items/properties/vote"

committee_info:
description: Current governance committee
type: object
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
cert_index:
$ref: "#/components/schemas/drep_updates/items/properties/cert_index"
quorum_numerator:
type: number
example: 67
quorum_denominator:
type: number
example: 100
members:
description: Array of all members part of active governance committee
type: array
items:
type: object
properties:
hex:
type: string
description: Committee member in hex format
example: f948a9f7a863d8062565809aba3925aa41334e976c11c837fe1a74c0
has_script:
type: boolean
description: Flag which shows if this committee member credential is a script hash
example: false
expiration_epoch:
type: number
description: Epoch number in which the committee member vote rights expire
example: 324
script_info:
type: array
items:
Expand Down

0 comments on commit f73007d

Please sign in to comment.