Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'alpha' into stake-distribution-sql
- Loading branch information
Showing
1 changed file
with
39 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
CREATE OR REPLACE FUNCTION grest.pool_metadata(_pool_bech32 text) | ||
RETURNS JSON STABLE LANGUAGE PLPGSQL AS $$ | ||
CREATE OR REPLACE FUNCTION grest.pool_metadata (_pool_bech32 text default null) | ||
RETURNS json STABLE | ||
LANGUAGE PLPGSQL | ||
AS $$ | ||
BEGIN | ||
RETURN ( SELECT json_build_object( | ||
'meta_url', pmd.url, | ||
'meta_hash', encode(pmd.hash::bytea, 'hex') | ||
) | ||
FROM public.pool_meta_data AS pmd | ||
WHERE pmd.id = (SELECT id from public.pool_hash where view=_pool_bech32) | ||
); | ||
END; $$; | ||
COMMENT ON FUNCTION grest.pool_metadata IS 'Get pool metadata url and hash'; | ||
IF _pool_bech32 IS NULL THEN | ||
RETURN ( | ||
SELECT | ||
json_agg(js) json_final | ||
FROM ( SELECT DISTINCT ON (ph.id) | ||
json_build_object('pool_id', ph.view, 'meta_url', pmr.url, 'meta_hash', encode(pmr.hash::bytea, 'hex')) js | ||
FROM | ||
public.pool_metadata_ref AS pmr | ||
INNER JOIN pool_hash AS ph ON ph.id = pmr.pool_id | ||
ORDER BY | ||
ph.id, | ||
pmr.registered_tx_id DESC) t); | ||
ELSE | ||
RETURN ( | ||
SELECT | ||
json_build_object('meta_url', pmr.url, 'meta_hash', encode(pmr.hash::bytea, 'hex')) | ||
FROM | ||
public.pool_metadata_ref AS pmr | ||
WHERE | ||
pmr.pool_id = ( | ||
SELECT | ||
id | ||
FROM | ||
public.pool_hash | ||
WHERE | ||
VIEW = _pool_bech32) | ||
ORDER BY | ||
pmr.registered_tx_id DESC | ||
LIMIT 1); | ||
END IF; | ||
END; | ||
$$; | ||
|
||
COMMENT ON FUNCTION grest.pool_metadata IS 'Get pool metadata url and hash, all pools if pool_id empty'; | ||
|