Skip to content

Commit

Permalink
Add reserve/treasury withdrawals and pool_registrations/deregistrations
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Sep 21, 2023
1 parent da96b9b commit 0da2422
Show file tree
Hide file tree
Showing 12 changed files with 703 additions and 3 deletions.
27 changes: 27 additions & 0 deletions files/grest/rpc/00_blockchain/reserve_withdrawals.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE OR REPLACE FUNCTION grest.reserve_withdrawals()
RETURNS TABLE (
epoch_no word31type,
epoch_slot word31type,
tx_hash text,
block_hash text,
block_height word31type,
amount text,
stake_address text
)
LANGUAGE SQL STABLE
AS $$
SELECT
b.epoch_no,
b.epoch_slot_no,
ENCODE(tx.hash,'hex'),
ENCODE(b.hash,'hex'),
b.block_no,
r.amount::text,
sa.view
FROM reserve AS r
LEFT JOIN tx ON r.tx_id = tx.id
INNER JOIN block AS b ON tx.block_id = b.id
LEFT JOIN stake_address AS sa ON sa.id = r.addr_id;
$$;

COMMENT ON FUNCTION grest.reserve_withdrawals IS 'A list of withdrawals made from reserves (MIRs)'; --noqa: LT01
27 changes: 27 additions & 0 deletions files/grest/rpc/00_blockchain/treasury_withdrawals.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE OR REPLACE FUNCTION grest.treasury_withdrawals()
RETURNS TABLE (
epoch_no word31type,
epoch_slot word31type,
tx_hash text,
block_hash text,
block_height word31type,
amount text,
stake_address text
)
LANGUAGE SQL STABLE
AS $$
SELECT
b.epoch_no,
b.epoch_slot_no,
ENCODE(tx.hash,'hex'),
ENCODE(b.hash,'hex'),
b.block_no,
t.amount::text,
sa.view
FROM treasury AS t
LEFT JOIN tx ON t.tx_id = tx.id
INNER JOIN block AS b ON tx.block_id = b.id
LEFT JOIN stake_address AS sa ON sa.id = t.addr_id;
$$;

COMMENT ON FUNCTION grest.treasury_withdrawals IS 'A list of withdrawals made from treasury'; --noqa: LT01
28 changes: 28 additions & 0 deletions files/grest/rpc/pool/pool_registrations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE OR REPLACE FUNCTION grest.pool_registrations(_epoch_no numeric)
RETURNS TABLE (
pool_id_bech32 text,
tx_hash text,
block_hash text,
block_height word31type,
epoch_no word31type,
epoch_slot word31type,
active_epoch_no word31type
)
LANGUAGE SQL STABLE
AS $$
SELECT
ph.view,
ENCODE(tx.hash,'hex'),
ENCODE(b.hash,'hex'),
b.block_no,
b.epoch_no,
b.epoch_slot_no,
pu.active_epoch_no
FROM pool_update AS pu
LEFT JOIN tx ON pu.registered_tx_id = tx.id
INNER JOIN block AS b ON tx.block_id = b.id
LEFT JOIN pool_hash AS ph ON ph.id = pu.hash_id
WHERE b.epoch_no = _epoch_no;
$$;

COMMENT ON FUNCTION grest.pool_registrations IS 'A list of all pool registrations initiated in the requested epoch'; --noqa: LT01
2 changes: 1 addition & 1 deletion files/grest/rpc/pool/pool_relays.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ BEGIN
END;
$$;

COMMENT ON FUNCTION grest.pool_relays IS 'A list of registered relays for all pools'; --noqa: LT01
COMMENT ON FUNCTION grest.pool_relays IS 'A list of registered relays for all pools'; --noqa: LT01
28 changes: 28 additions & 0 deletions files/grest/rpc/pool/pool_retirements.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE OR REPLACE FUNCTION grest.pool_retirements(_epoch_no numeric)
RETURNS TABLE (
pool_id_bech32 text,
tx_hash text,
block_hash text,
block_height word31type,
epoch_no word31type,
epoch_slot word31type,
active_epoch_no word31type
)
LANGUAGE SQL STABLE
AS $$
SELECT
ph.view,
ENCODE(tx.hash,'hex'),
ENCODE(b.hash,'hex'),
b.block_no,
b.epoch_no,
b.epoch_slot_no,
pr.retiring_epoch
FROM pool_retire AS pr
LEFT JOIN tx ON pr.announced_tx_id = tx.id
INNER JOIN block AS b ON tx.block_id = b.id
LEFT JOIN pool_hash AS ph ON ph.id = pr.hash_id
WHERE b.epoch_no = _epoch_no;
$$;

COMMENT ON FUNCTION grest.pool_registrations IS 'A list of all pool retirements initiated in the requested epoch'; --noqa: LT01
118 changes: 118 additions & 0 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,44 @@ paths:
$ref: "#/components/responses/NotFound"
summary: Param Update Proposals
description: Get all parameter update proposals submitted to the chain starting Shelley era
/reserve_withdrawals: #RPC
get:
tags:
- Network
responses:
"200":
description: Array of withdrawals from reserves against stake accounts
content:
application/json:
schema:
$ref: "#/components/schemas/reserve_withdrawals"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Reserve Withdrawals
description: List of all withdrawals from reserves against stake accounts
/treasury_withdrawals: #RPC
get:
tags:
- Network
responses:
"200":
description: Array of withdrawals from treasury against stake accounts
content:
application/json:
schema:
$ref: "#/components/schemas/reserve_withdrawals"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Treasury Withdrawals
description: List of all withdrawals from treasury against stake accounts

/epoch_info: #RPC
get:
Expand Down Expand Up @@ -1362,6 +1400,48 @@ paths:
$ref: "#/components/responses/NotFound"
summary: Pool Updates (History)
description: Return all pool updates for all pools or only updates for specific pool if specified
/pool_registrations: #RPC
get:
tags:
- Pool
parameters:
- $ref: "#/components/parameters/_epoch_no"
responses:
"200":
description: Array of historical pool updates
content:
application/json:
schema:
$ref: "#/components/schemas/pool_registrations"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Pool Registrations
description: Return all pool registrations initiated in the requested epoch
/pool_retirements: #RPC
get:
tags:
- Pool
parameters:
- $ref: "#/components/parameters/_epoch_no"
responses:
"200":
description: Array of historical pool updates
content:
application/json:
schema:
$ref: "#/components/schemas/pool_registrations"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
summary: Pool Retirements
description: Return all pool retirements initiated in the requested epoch
/pool_relays: #RPC
get:
tags:
Expand Down Expand Up @@ -2281,6 +2361,24 @@ components:
type: string
description: JSON encoded data with details about the parameter update
example: {"decentralisation": 0.9}
reserve_withdrawals:
type: array
items:
properties:
epoch_no:
$ref: "#/components/schemas/epoch_info/items/properties/epoch_no"
epoch_slot:
$ref: "#/components/schemas/blocks/items/properties/epoch_slot"
tx_hash:
$ref: "#/components/schemas/tx_info/items/properties/tx_hash"
block_hash:
$ref: "#/components/schemas/blocks/items/properties/hash"
block_height:
$ref: "#/components/schemas/blocks/items/properties/block_height"
amount:
$ref: "#/components/schemas/pool_delegators/items/properties/amount"
stake_address:
$ref: "#/components/schemas/account_history/items/properties/stake_address"
pool_list:
type: array
items:
Expand Down Expand Up @@ -2569,6 +2667,26 @@ components:
type: string
description: Latest transaction hash used for delegation by the account
example: 368d08fe86804d637649341d3aec4a9baa7dffa6d00f16de2ba9dba814f1c948
pool_registrations:
type: array
nullable: true
items:
type: object
properties:
pool_id_bech32:
$ref: "#/components/schemas/pool_info/items/properties/pool_id_bech32"
tx_hash:
$ref: "#/components/schemas/tx_info/items/properties/tx_hash"
block_hash:
$ref: "#/components/schemas/blocks/items/properties/hash"
block_height:
$ref: "#/components/schemas/blocks/items/properties/block_height"
epoch_no:
$ref: "#/components/schemas/epoch_info/items/properties/epoch_no"
epoch_slot:
$ref: "#/components/schemas/blocks/items/properties/epoch_slot"
active_epoch_no:
$ref: "#/components/schemas/pool_updates/items/properties/active_epoch_no"
pool_delegators_history:
type: array
nullable: true
Expand Down
Loading

0 comments on commit 0da2422

Please sign in to comment.