diff --git a/files/grest/rpc/00_blockchain/reserve_withdrawals.sql b/files/grest/rpc/00_blockchain/reserve_withdrawals.sql new file mode 100644 index 00000000..be812417 --- /dev/null +++ b/files/grest/rpc/00_blockchain/reserve_withdrawals.sql @@ -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 \ No newline at end of file diff --git a/files/grest/rpc/00_blockchain/treasury_withdrawals.sql b/files/grest/rpc/00_blockchain/treasury_withdrawals.sql new file mode 100644 index 00000000..afa19182 --- /dev/null +++ b/files/grest/rpc/00_blockchain/treasury_withdrawals.sql @@ -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 \ No newline at end of file diff --git a/files/grest/rpc/pool/pool_registrations.sql b/files/grest/rpc/pool/pool_registrations.sql new file mode 100644 index 00000000..d21e7b5d --- /dev/null +++ b/files/grest/rpc/pool/pool_registrations.sql @@ -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; +$$; \ No newline at end of file diff --git a/files/grest/rpc/pool/pool_relays.sql b/files/grest/rpc/pool/pool_relays.sql index 2b3e2c09..84b70ab9 100644 --- a/files/grest/rpc/pool/pool_relays.sql +++ b/files/grest/rpc/pool/pool_relays.sql @@ -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 \ No newline at end of file diff --git a/files/grest/rpc/pool/pool_retirements.sql b/files/grest/rpc/pool/pool_retirements.sql new file mode 100644 index 00000000..e22d4794 --- /dev/null +++ b/files/grest/rpc/pool/pool_retirements.sql @@ -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; +$$; \ No newline at end of file