From ba565d189de39d4a656e7cba284aa8b677e84dcd Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 2 Oct 2024 18:22:01 -0700 Subject: [PATCH] update allDelegates query to include version --- migrations/076-new-all-delegates.sql | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 migrations/076-new-all-delegates.sql diff --git a/migrations/076-new-all-delegates.sql b/migrations/076-new-all-delegates.sql new file mode 100644 index 0000000..c3f4172 --- /dev/null +++ b/migrations/076-new-all-delegates.sql @@ -0,0 +1,28 @@ +-- Drop existing functions +DROP FUNCTION IF EXISTS dschief.all_delegates(); +DROP FUNCTION IF EXISTS api.all_delegates(); + +CREATE OR REPLACE FUNCTION dschief.all_delegates() +RETURNS TABLE ( + delegate character varying(66), + vote_delegate character varying(66), + delegate_version int +) AS $$ +SELECT delegate, vote_delegate, delegate_version +FROM dschief.vote_delegate_created_event +$$ LANGUAGE sql STABLE STRICT; + + +--This query would be called by allDelegates() in the sdk +CREATE OR REPLACE FUNCTION api.all_delegates() +RETURNS TABLE ( + delegate character varying(66), + vote_delegate character varying(66), + delegate_version int, + block_timestamp TIMESTAMP WITH TIME ZONE +) AS $$ +SELECT delegate, vote_delegate, delegate_version, b.timestamp +FROM dschief.vote_delegate_created_event d +LEFT JOIN vulcan2x.block b +ON d.block_id = b.id; +$$ LANGUAGE sql STABLE STRICT; \ No newline at end of file