Skip to content

Commit

Permalink
committee_info update and voter_proposal_list added
Browse files Browse the repository at this point in the history
  • Loading branch information
Scitz0 committed Aug 22, 2024
1 parent 6d07974 commit 369161a
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 9 deletions.
21 changes: 17 additions & 4 deletions files/grest/rpc/governance/committee_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
110 changes: 110 additions & 0 deletions files/grest/rpc/governance/voter_proposal_list.sql
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 369161a

Please sign in to comment.