Skip to content

Commit

Permalink
Add drep_history, closes #311
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Jan 2, 2025
1 parent ab9b0df commit ead1e5e
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 0 deletions.
27 changes: 27 additions & 0 deletions files/grest/rpc/governance/drep_history.sql
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions specs/templates/api-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ead1e5e

Please sign in to comment.