Skip to content

Commit

Permalink
Add tx_metadata RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
dostrelith678 committed Oct 12, 2021
1 parent b5912a1 commit 1697fcf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions files/grest/rpc/transactions/tx_metadata.sql
@@ -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.';

0 comments on commit 1697fcf

Please sign in to comment.