-
Notifications
You must be signed in to change notification settings - Fork 174
/
totals.sql
36 lines (34 loc) · 1.06 KB
/
totals.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
CREATE FUNCTION grest.totals (_epoch_no numeric DEFAULT NULL)
RETURNS TABLE (
epoch_no word31type,
circulation text,
treasury text,
reward text,
supply text,
reserves text
)
LANGUAGE PLPGSQL
AS $$
BEGIN
IF _epoch_no IS NULL THEN
RETURN QUERY (
SELECT
ap.epoch_no, ap.utxo::text, ap.treasury::text, ap.rewards::text, (ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text as supply, ap.reserves::text
FROM
public.ada_pots as ap
ORDER BY
ap.epoch_no DESC) ;
ELSE
RETURN QUERY (
SELECT
ap.epoch_no, ap.utxo::text, ap.treasury::text, ap.rewards::text, (ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text as supply, ap.reserves::text
FROM
public.ada_pots as ap
WHERE
ap.epoch_no = _epoch_no
ORDER BY
ap.epoch_no DESC);
END IF;
END;
$$;
COMMENT ON FUNCTION grest.totals IS 'Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified epoch, all epochs if empty';