Skip to content

Commit

Permalink
Add script_info
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Sep 11, 2023
1 parent 506fd41 commit d6f5346
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
8 changes: 3 additions & 5 deletions files/grest/rpc/script/datum_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ BEGIN
ENCODE(d.hash, 'hex'),
d.value,
ENCODE(d.bytes, 'hex')
FROM
datum AS d
WHERE
d.hash = ANY(_datum_hashes_decoded);
FROM datum AS d
WHERE d.hash = ANY(_datum_hashes_decoded);
END;
$$;

COMMENT ON FUNCTION grest.datum_info IS 'Get information about a given data FROM hashes.'; -- noqa: LT01
COMMENT ON FUNCTION grest.datum_info IS 'Get information about a given datum FROM hashes.'; -- noqa: LT01
29 changes: 29 additions & 0 deletions files/grest/rpc/script/script_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE OR REPLACE FUNCTION grest.script_info(_script_hashes text [], _extended boolean DEFAULT false)
RETURNS TABLE (
script_hash text,
type text,
value jsonb,
bytes text,
size word31type
)
LANGUAGE plpgsql
AS $$
DECLARE
_script_hashes_encoded varchar[];
BEGIN
SELECT INTO _script_hashes_encoded ARRAY_AGG(DECODE(s_hash, 'hex'))
FROM UNNEST(_script_hashes) AS s_hash;
RETURN QUERY
SELECT
ENCODE(s.hash, 'hex')::text AS script_hash,
s.type::text AS type,
s.json AS value,
ENCODE(s.bytes,'hex')::text AS bytes,
s.serialised_size AS size
FROM script AS s
WHERE s.hash = ANY(_script_hashes_encoded)
;
END;
$$;

COMMENT ON FUNCTION grest.script_utxos IS 'Get information about a given script FROM hashes.'; -- noqa: LT01

0 comments on commit d6f5346

Please sign in to comment.