From f73007d6f3f0af3d91c60e76a438acb2bd46ab68 Mon Sep 17 00:00:00 2001 From: Ola Date: Sun, 4 Aug 2024 19:21:20 +0200 Subject: [PATCH] Add committee_info endpoint --- files/grest/rpc/governance/committee_info.sql | 64 +++++++++++++++++++ specs/results/koiosapi-guild.yaml | 33 +++++++++- specs/results/koiosapi-mainnet.yaml | 33 +++++++++- specs/results/koiosapi-preprod.yaml | 33 +++++++++- specs/results/koiosapi-preview.yaml | 33 +++++++++- specs/templates/4-api-schemas.yaml | 33 +++++++++- 6 files changed, 224 insertions(+), 5 deletions(-) create mode 100644 files/grest/rpc/governance/committee_info.sql diff --git a/files/grest/rpc/governance/committee_info.sql b/files/grest/rpc/governance/committee_info.sql new file mode 100644 index 00000000..1de55545 --- /dev/null +++ b/files/grest/rpc/governance/committee_info.sql @@ -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 diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index 0fce8c81..69cdfad8 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -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: diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index 71a975e6..4357712c 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -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: diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index e1c35242..7cc6dbca 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -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: diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index 454d172c..cbbc0080 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -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: diff --git a/specs/templates/4-api-schemas.yaml b/specs/templates/4-api-schemas.yaml index cb618268..afdc29d2 100644 --- a/specs/templates/4-api-schemas.yaml +++ b/specs/templates/4-api-schemas.yaml @@ -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: