From ead1e5e3c54ed67cae32b8bd86d76552e0b145f1 Mon Sep 17 00:00:00 2001 From: rdlrt <3169068+rdlrt@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:54:07 +1100 Subject: [PATCH] Add drep_history, closes #311 --- files/grest/rpc/governance/drep_history.sql | 27 ++++++++++++++++ specs/results/koiosapi-guild.yaml | 35 +++++++++++++++++++++ specs/results/koiosapi-mainnet.yaml | 35 +++++++++++++++++++++ specs/results/koiosapi-preprod.yaml | 35 +++++++++++++++++++++ specs/results/koiosapi-preview.yaml | 35 +++++++++++++++++++++ specs/templates/4-api-schemas.yaml | 12 +++++++ specs/templates/api-main.yaml | 23 ++++++++++++++ 7 files changed, 202 insertions(+) create mode 100644 files/grest/rpc/governance/drep_history.sql diff --git a/files/grest/rpc/governance/drep_history.sql b/files/grest/rpc/governance/drep_history.sql new file mode 100644 index 0000000..adeaade --- /dev/null +++ b/files/grest/rpc/governance/drep_history.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE FUNCTION grest.drep_history(_epoch_no numeric DEFAULT NULL, _drep_id text DEFAULT NULL) +RETURNS TABLE ( + drep_id text, + epoch_no word31type, + amount text +) +LANGUAGE sql STABLE +AS $$ + SELECT + CASE + WHEN STARTS_WITH(_drep_id,'drep_always') THEN _drep_id + ELSE grest.cip129_hex_to_drep_id(dh.raw, dh.has_script) + END AS drep_id, + dd.epoch_no, + dd.amount::text AS amount + FROM public.drep_distr AS dd + INNER JOIN public.drep_hash AS dh ON dh.id = dd.hash_id + WHERE (CASE WHEN _epoch_no IS NULL THEN TRUE ELSE dd.epoch_no = _epoch_no END) + AND (CASE + WHEN _drep_id IS NULL THEN TRUE + WHEN STARTS_WITH(_drep_id,'drep_always') THEN dh.view = _drep_id + ELSE dh.raw = DECODE(grest.cip129_drep_id_to_hex(_drep_id), 'hex') + END) + ORDER BY dd.epoch_no DESC; +$$; + +COMMENT ON FUNCTION grest.drep_history IS 'Get history for dreps voting power distribution'; --noqa: LT01 diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index 99b3f1d..fe9b517 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -1434,6 +1434,29 @@ paths: summary: DReps Updates description: List of updates for requested (or all) delegated representatives (DReps) operationId: drep_updates + /drep_history: #RPC + get: + tags: + - Governance + parameters: + - $ref: "#/components/parameters/_epoch_no" + - $ref: "#/components/parameters/_drep_id_optional" + responses: + "200": + description: Success!! + content: + application/json: + schema: + $ref: "#/components/schemas/drep_history" + "400": + $ref: "#/components/responses/BadRequest" + "401": + $ref: "#/components/responses/Unauthorized" + "404": + $ref: "#/components/responses/NotFound" + summary: DReps Voting Power History + description: History of voting power for DReps against each epoch + operationId: drep_history /drep_votes: #RPC get: tags: @@ -5411,6 +5434,18 @@ components: $ref: "#/components/schemas/drep_metadata/items/properties/meta_hash" meta_json: $ref: "#/components/schemas/drep_metadata/items/properties/meta_json" + drep_history: + description: History of DReps voting power against each (or requested) epoch + type: array + items: + properties: + drep_id: + $ref: "#/components/schemas/drep_info/items/properties/drep_id" + epoch_no: + $ref: "#/components/schemas/blocks/items/properties/epoch_no" + amount: + type: string + description: The voting power for the DRep drep_votes: description: List of all votes casted by requested delegated representative (DRep) type: array diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index 5a7b660..cbf92ea 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -1434,6 +1434,29 @@ paths: summary: DReps Updates description: List of updates for requested (or all) delegated representatives (DReps) operationId: drep_updates + /drep_history: #RPC + get: + tags: + - Governance + parameters: + - $ref: "#/components/parameters/_epoch_no" + - $ref: "#/components/parameters/_drep_id_optional" + responses: + "200": + description: Success!! + content: + application/json: + schema: + $ref: "#/components/schemas/drep_history" + "400": + $ref: "#/components/responses/BadRequest" + "401": + $ref: "#/components/responses/Unauthorized" + "404": + $ref: "#/components/responses/NotFound" + summary: DReps Voting Power History + description: History of voting power for DReps against each epoch + operationId: drep_history /drep_votes: #RPC get: tags: @@ -5411,6 +5434,18 @@ components: $ref: "#/components/schemas/drep_metadata/items/properties/meta_hash" meta_json: $ref: "#/components/schemas/drep_metadata/items/properties/meta_json" + drep_history: + description: History of DReps voting power against each (or requested) epoch + type: array + items: + properties: + drep_id: + $ref: "#/components/schemas/drep_info/items/properties/drep_id" + epoch_no: + $ref: "#/components/schemas/blocks/items/properties/epoch_no" + amount: + type: string + description: The voting power for the DRep drep_votes: description: List of all votes casted by requested delegated representative (DRep) type: array diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index 37fe14a..380fb92 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -1434,6 +1434,29 @@ paths: summary: DReps Updates description: List of updates for requested (or all) delegated representatives (DReps) operationId: drep_updates + /drep_history: #RPC + get: + tags: + - Governance + parameters: + - $ref: "#/components/parameters/_epoch_no" + - $ref: "#/components/parameters/_drep_id_optional" + responses: + "200": + description: Success!! + content: + application/json: + schema: + $ref: "#/components/schemas/drep_history" + "400": + $ref: "#/components/responses/BadRequest" + "401": + $ref: "#/components/responses/Unauthorized" + "404": + $ref: "#/components/responses/NotFound" + summary: DReps Voting Power History + description: History of voting power for DReps against each epoch + operationId: drep_history /drep_votes: #RPC get: tags: @@ -5411,6 +5434,18 @@ components: $ref: "#/components/schemas/drep_metadata/items/properties/meta_hash" meta_json: $ref: "#/components/schemas/drep_metadata/items/properties/meta_json" + drep_history: + description: History of DReps voting power against each (or requested) epoch + type: array + items: + properties: + drep_id: + $ref: "#/components/schemas/drep_info/items/properties/drep_id" + epoch_no: + $ref: "#/components/schemas/blocks/items/properties/epoch_no" + amount: + type: string + description: The voting power for the DRep drep_votes: description: List of all votes casted by requested delegated representative (DRep) type: array diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index b363066..83a0329 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -1434,6 +1434,29 @@ paths: summary: DReps Updates description: List of updates for requested (or all) delegated representatives (DReps) operationId: drep_updates + /drep_history: #RPC + get: + tags: + - Governance + parameters: + - $ref: "#/components/parameters/_epoch_no" + - $ref: "#/components/parameters/_drep_id_optional" + responses: + "200": + description: Success!! + content: + application/json: + schema: + $ref: "#/components/schemas/drep_history" + "400": + $ref: "#/components/responses/BadRequest" + "401": + $ref: "#/components/responses/Unauthorized" + "404": + $ref: "#/components/responses/NotFound" + summary: DReps Voting Power History + description: History of voting power for DReps against each epoch + operationId: drep_history /drep_votes: #RPC get: tags: @@ -5411,6 +5434,18 @@ components: $ref: "#/components/schemas/drep_metadata/items/properties/meta_hash" meta_json: $ref: "#/components/schemas/drep_metadata/items/properties/meta_json" + drep_history: + description: History of DReps voting power against each (or requested) epoch + type: array + items: + properties: + drep_id: + $ref: "#/components/schemas/drep_info/items/properties/drep_id" + epoch_no: + $ref: "#/components/schemas/blocks/items/properties/epoch_no" + amount: + type: string + description: The voting power for the DRep drep_votes: description: List of all votes casted by requested delegated representative (DRep) type: array diff --git a/specs/templates/4-api-schemas.yaml b/specs/templates/4-api-schemas.yaml index f453803..f8d9f9b 100644 --- a/specs/templates/4-api-schemas.yaml +++ b/specs/templates/4-api-schemas.yaml @@ -2553,6 +2553,18 @@ schemas: $ref: "#/components/schemas/drep_metadata/items/properties/meta_hash" meta_json: $ref: "#/components/schemas/drep_metadata/items/properties/meta_json" + drep_history: + description: History of DReps voting power against each (or requested) epoch + type: array + items: + properties: + drep_id: + $ref: "#/components/schemas/drep_info/items/properties/drep_id" + epoch_no: + $ref: "#/components/schemas/blocks/items/properties/epoch_no" + amount: + type: string + description: The voting power for the DRep drep_votes: description: List of all votes casted by requested delegated representative (DRep) type: array diff --git a/specs/templates/api-main.yaml b/specs/templates/api-main.yaml index c8b8659..e7768eb 100644 --- a/specs/templates/api-main.yaml +++ b/specs/templates/api-main.yaml @@ -1289,6 +1289,29 @@ paths: summary: DReps Updates description: List of updates for requested (or all) delegated representatives (DReps) operationId: drep_updates + /drep_history: #RPC + get: + tags: + - Governance + parameters: + - $ref: "#/components/parameters/_epoch_no" + - $ref: "#/components/parameters/_drep_id_optional" + responses: + "200": + description: Success!! + content: + application/json: + schema: + $ref: "#/components/schemas/drep_history" + "400": + $ref: "#/components/responses/BadRequest" + "401": + $ref: "#/components/responses/Unauthorized" + "404": + $ref: "#/components/responses/NotFound" + summary: DReps Voting Power History + description: History of voting power for DReps against each epoch + operationId: drep_history /drep_votes: #RPC get: tags: