From 369161a00bc486d212c043422a4b894fc55ab5bb Mon Sep 17 00:00:00 2001 From: Ola Date: Thu, 22 Aug 2024 23:54:13 +0200 Subject: [PATCH] committee_info update and voter_proposal_list added --- files/grest/rpc/governance/committee_info.sql | 21 +++- .../rpc/governance/voter_proposal_list.sql | 110 ++++++++++++++++++ specs/results/koiosapi-guild.yaml | 12 +- specs/results/koiosapi-mainnet.yaml | 12 +- specs/results/koiosapi-preprod.yaml | 12 +- specs/results/koiosapi-preview.yaml | 12 +- specs/templates/4-api-schemas.yaml | 12 +- 7 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 files/grest/rpc/governance/voter_proposal_list.sql diff --git a/files/grest/rpc/governance/committee_info.sql b/files/grest/rpc/governance/committee_info.sql index ca82aae3..bd7f3aad 100644 --- a/files/grest/rpc/governance/committee_info.sql +++ b/files/grest/rpc/governance/committee_info.sql @@ -53,6 +53,18 @@ BEGIN c.quorum_denominator, JSONB_AGG( JSONB_BUILD_OBJECT( + 'status', + CASE + WHEN 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 + ) THEN 'resigned' + WHEN hot_key.raw IS NULL THEN 'not_authorized' + ELSE + 'authorized' + END, '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, @@ -78,10 +90,11 @@ BEGIN WHERE cdr.cold_key_id = cr.cold_key_id AND cdr.tx_id > cr.tx_id ) - AND CASE - WHEN gap_enacted_tx_id IS NULL THEN TRUE - ELSE cr.tx_id > gap_enacted_tx_id - END + -- TODO: fix once we know how to properly check for valid hot key auth cert + --AND CASE + -- WHEN gap_enacted_tx_id IS NULL THEN TRUE + -- ELSE cr.tx_id > gap_enacted_tx_id + --END ORDER BY cr.id DESC LIMIT 1 ) AS hot_key ON TRUE diff --git a/files/grest/rpc/governance/voter_proposal_list.sql b/files/grest/rpc/governance/voter_proposal_list.sql new file mode 100644 index 00000000..ddbafba1 --- /dev/null +++ b/files/grest/rpc/governance/voter_proposal_list.sql @@ -0,0 +1,110 @@ +CREATE OR REPLACE FUNCTION grest.voter_proposal_list(credential text) +RETURNS TABLE ( + block_time integer, + proposal_tx_hash text, + proposal_index bigint, + proposal_type govactiontype, + proposal_description jsonb, + deposit text, + return_address character varying, + proposed_epoch word31type, + ratified_epoch word31type, + enacted_epoch word31type, + dropped_epoch word31type, + expired_epoch word31type, + expiration word31type, + meta_url character varying, + meta_hash text, + meta_json jsonb, + meta_comment character varying, + meta_language character varying, + meta_is_valid boolean, + withdrawal jsonb, + param_proposal jsonb +) +LANGUAGE plpgsql +AS $$ +DECLARE + _drep_id bigint; + _spo_id bigint; + _committee_member_id bigint; + _gap_id_list bigint[]; +BEGIN + + SELECT INTO _drep_id id FROM public.drep_hash WHERE raw = DECODE(credential, 'hex'); + IF _drep_id IS NULL THEN + SELECT INTO _spo_id id FROM public.pool_hash WHERE hash_raw = DECODE(credential, 'hex'); + ELSIF _spo_id IS NULL THEN + SELECT INTO _committee_member_id id FROM public.committee_hash WHERE raw = DECODE(credential, 'hex'); + END IF; + + SELECT INTO _gap_id_list ARRAY_AGG(gov_action_proposal_id) + FROM ( + SELECT DISTINCT gov_action_proposal_id + FROM public.voting_procedure + WHERE + CASE + WHEN _drep_id IS NOT NULL THEN drep_voter = _drep_id + WHEN _spo_id IS NOT NULL THEN pool_voter = _spo_id + WHEN _committee_member_id IS NOT NULL THEN committee_voter = _committee_member_id + ELSE + FALSE + END + ) AS tmp; + + RETURN QUERY ( + SELECT + 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 + JSONB_BUILD_OBJECT( + 'stake_address', ( + SELECT sa2.view + FROM stake_address AS sa2 + WHERE sa2.id = tw.stake_address_id + ), + 'amount', tw.amount::text + ) + END AS withdrawal, + CASE + WHEN pp.id IS NULL THEN NULL + 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 + 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.treasury_withdrawal AS tw ON gap.id = tw.gov_action_proposal_id + LEFT JOIN public.param_proposal AS pp ON gap.param_proposal = pp.id + LEFT JOIN public.cost_model AS cm ON cm.id = pp.cost_model_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 + WHERE + gap.id = ANY(_gap_id_list) + ORDER BY + b.time DESC + ); + +END; +$$; + +COMMENT ON FUNCTION grest.voter_proposal_list IS 'Get a raw listing of all governance proposals for specified DRep, SPO or Committee credential'; --noqa: LT01 diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index 652d3322..80ab5c57 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -5310,7 +5310,7 @@ components: items: $ref: "#/components/schemas/drep_votes/items" proposal_list: - description: List of all votes cast on specified governance action + description: List of all governance action proposals type: array items: properties: @@ -5399,6 +5399,11 @@ components: - object - 'null' example: {"key_deposit": 1000000} + voter_proposal_list: + description: List of all governance action proposals where specified credential(DRep, SPO or Committee member) has cast a vote + type: array + items: + $ref: "#/components/schemas/proposal_list/items" proposal_votes: type: array description: List of all votes cast on specified governance action @@ -5445,6 +5450,11 @@ components: items: type: object properties: + status: + type: string + description: Member authentication status + enum: [ "authorized", "not_authorized", "resigned" ] + example: authorized cc_cold_hex: type: string description: Committee member cold key hash in hex format diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index 7abc4532..400f2a87 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -5310,7 +5310,7 @@ components: items: $ref: "#/components/schemas/drep_votes/items" proposal_list: - description: List of all votes cast on specified governance action + description: List of all governance action proposals type: array items: properties: @@ -5399,6 +5399,11 @@ components: - object - 'null' example: {"key_deposit": 1000000} + voter_proposal_list: + description: List of all governance action proposals where specified credential(DRep, SPO or Committee member) has cast a vote + type: array + items: + $ref: "#/components/schemas/proposal_list/items" proposal_votes: type: array description: List of all votes cast on specified governance action @@ -5445,6 +5450,11 @@ components: items: type: object properties: + status: + type: string + description: Member authentication status + enum: [ "authorized", "not_authorized", "resigned" ] + example: authorized cc_cold_hex: type: string description: Committee member cold key hash in hex format diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index efdf7c64..4f83995e 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -5310,7 +5310,7 @@ components: items: $ref: "#/components/schemas/drep_votes/items" proposal_list: - description: List of all votes cast on specified governance action + description: List of all governance action proposals type: array items: properties: @@ -5399,6 +5399,11 @@ components: - object - 'null' example: {"key_deposit": 1000000} + voter_proposal_list: + description: List of all governance action proposals where specified credential(DRep, SPO or Committee member) has cast a vote + type: array + items: + $ref: "#/components/schemas/proposal_list/items" proposal_votes: type: array description: List of all votes cast on specified governance action @@ -5445,6 +5450,11 @@ components: items: type: object properties: + status: + type: string + description: Member authentication status + enum: [ "authorized", "not_authorized", "resigned" ] + example: authorized cc_cold_hex: type: string description: Committee member cold key hash in hex format diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index fa139328..eb3e4174 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -5310,7 +5310,7 @@ components: items: $ref: "#/components/schemas/drep_votes/items" proposal_list: - description: List of all votes cast on specified governance action + description: List of all governance action proposals type: array items: properties: @@ -5399,6 +5399,11 @@ components: - object - 'null' example: {"key_deposit": 1000000} + voter_proposal_list: + description: List of all governance action proposals where specified credential(DRep, SPO or Committee member) has cast a vote + type: array + items: + $ref: "#/components/schemas/proposal_list/items" proposal_votes: type: array description: List of all votes cast on specified governance action @@ -5445,6 +5450,11 @@ components: items: type: object properties: + status: + type: string + description: Member authentication status + enum: [ "authorized", "not_authorized", "resigned" ] + example: authorized cc_cold_hex: type: string description: Committee member cold key hash in hex format diff --git a/specs/templates/4-api-schemas.yaml b/specs/templates/4-api-schemas.yaml index cad0a724..df537706 100644 --- a/specs/templates/4-api-schemas.yaml +++ b/specs/templates/4-api-schemas.yaml @@ -2520,7 +2520,7 @@ schemas: items: $ref: "#/components/schemas/drep_votes/items" proposal_list: - description: List of all votes cast on specified governance action + description: List of all governance action proposals type: array items: properties: @@ -2609,6 +2609,11 @@ schemas: - object - 'null' example: {"key_deposit": 1000000} + voter_proposal_list: + description: List of all governance action proposals where specified credential(DRep, SPO or Committee member) has cast a vote + type: array + items: + $ref: "#/components/schemas/proposal_list/items" proposal_votes: type: array description: List of all votes cast on specified governance action @@ -2655,6 +2660,11 @@ schemas: items: type: object properties: + status: + type: string + description: Member authentication status + enum: [ "authorized", "not_authorized", "resigned" ] + example: authorized cc_cold_hex: type: string description: Committee member cold key hash in hex format