From b7a7d5fb6f8c36ae0b95c2535f78f3be84a9224b Mon Sep 17 00:00:00 2001 From: Ola Date: Mon, 5 Aug 2024 23:31:44 +0200 Subject: [PATCH] various updates - 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 --- files/grest/rpc/governance/committee_info.sql | 26 ++++++++++++++-- .../grest/rpc/governance/committee_votes.sql | 17 ++++++++--- files/grest/rpc/governance/drep_votes.sql | 9 ++++-- files/grest/rpc/governance/proposal_votes.sql | 9 ++++-- files/grest/rpc/pool/pool_votes.sql | 9 ++++-- specs/results/koiosapi-guild.yaml | 30 +++++++++++++++---- specs/results/koiosapi-mainnet.yaml | 30 +++++++++++++++---- specs/results/koiosapi-preprod.yaml | 30 +++++++++++++++---- specs/results/koiosapi-preview.yaml | 30 +++++++++++++++---- specs/templates/4-api-schemas.yaml | 30 +++++++++++++++---- 10 files changed, 182 insertions(+), 38 deletions(-) diff --git a/files/grest/rpc/governance/committee_info.sql b/files/grest/rpc/governance/committee_info.sql index 57cd3e31..1af9dbd8 100644 --- a/files/grest/rpc/governance/committee_info.sql +++ b/files/grest/rpc/governance/committee_info.sql @@ -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 diff --git a/files/grest/rpc/governance/committee_votes.sql b/files/grest/rpc/governance/committee_votes.sql index d96f833b..20b5f875 100644 --- a/files/grest/rpc/governance/committee_votes.sql +++ b/files/grest/rpc/governance/committee_votes.sql @@ -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 $$ @@ -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; $$; diff --git a/files/grest/rpc/governance/drep_votes.sql b/files/grest/rpc/governance/drep_votes.sql index 520eb88f..31214e36 100644 --- a/files/grest/rpc/governance/drep_votes.sql +++ b/files/grest/rpc/governance/drep_votes.sql @@ -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 $$ @@ -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; diff --git a/files/grest/rpc/governance/proposal_votes.sql b/files/grest/rpc/governance/proposal_votes.sql index 20a530ea..c7822697 100644 --- a/files/grest/rpc/governance/proposal_votes.sql +++ b/files/grest/rpc/governance/proposal_votes.sql @@ -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 $$ @@ -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 @@ -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? diff --git a/files/grest/rpc/pool/pool_votes.sql b/files/grest/rpc/pool/pool_votes.sql index f88a5bb6..d61e1c50 100644 --- a/files/grest/rpc/pool/pool_votes.sql +++ b/files/grest/rpc/pool/pool_votes.sql @@ -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 $$ @@ -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; diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index 83f77477..3f21e814 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -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 @@ -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 @@ -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 diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index 198ce5b7..a533bd91 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -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 @@ -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 @@ -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 diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index f148e07f..dcf4f6dd 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -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 @@ -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 @@ -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 diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index b633a68e..652779e5 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -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 @@ -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 @@ -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 diff --git a/specs/templates/4-api-schemas.yaml b/specs/templates/4-api-schemas.yaml index 5d351400..108e7c60 100644 --- a/specs/templates/4-api-schemas.yaml +++ b/specs/templates/4-api-schemas.yaml @@ -2475,6 +2475,10 @@ schemas: 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 @@ -2597,6 +2601,10 @@ schemas: 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 @@ -2617,13 +2625,25 @@ schemas: 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