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 f83f244
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
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,
slot_no word31type,
tx_hash text,
block_hash text,
block_no 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,
slot_no word31type,
tx_hash text,
block_hash text,
block_no 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
26 changes: 26 additions & 0 deletions files/grest/rpc/pool/pool_registrations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE OR REPLACE FUNCTION grest.pool_registrations(_epoch_no numeric)
RETURNS TABLE (
pool_id_bech32 text,
tx_hash text,
block_hash text,
block_no word31type,
epoch_no word31type,
slot_no 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;
$$;
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
26 changes: 26 additions & 0 deletions files/grest/rpc/pool/pool_retirements.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE OR REPLACE FUNCTION grest.pool_retirements(_epoch_no numeric)
RETURNS TABLE (
pool_id_bech32 text,
tx_hash text,
block_hash text,
block_no word31type,
epoch_no word31type,
slot_no 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;
$$;

0 comments on commit f83f244

Please sign in to comment.