Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5912a1
commit 1697fcf
Showing
1 changed file
with
37 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
DROP FUNCTION IF EXISTS grest.tx_metadata (text[]); | ||
|
||
CREATE FUNCTION grest.tx_metadata (_tx_hashes text[]) | ||
RETURNS TABLE ( | ||
tx_hash text, | ||
metadata json) | ||
LANGUAGE PLPGSQL | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
T1.tx_hash, | ||
METADATA_T.metadata | ||
FROM ( | ||
SELECT | ||
tx.id, | ||
ENCODE(tx.hash, 'hex') as tx_hash | ||
FROM | ||
public.tx | ||
WHERE | ||
tx.hash::bytea = ANY ( | ||
SELECT | ||
DECODE(hashes, 'hex') | ||
FROM | ||
UNNEST(_tx_hashes) AS hashes)) T1 | ||
LEFT JOIN LATERAL ( | ||
SELECT | ||
JSON_OBJECT_AGG(tx_metadata.key, tx_metadata.json) as metadata | ||
FROM | ||
tx_metadata | ||
WHERE | ||
tx_id = T1.id) METADATA_T ON TRUE; | ||
END; | ||
$$; | ||
|
||
COMMENT ON FUNCTION grest.tx_metadata IS 'Get transaction metadata.'; | ||
|