Skip to content

Commit

Permalink
asset_tx_history rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
dostrelith678 committed Jan 15, 2022
1 parent 5ee5130 commit f3f02f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion files/grest/rpc/account/account_history.sql
@@ -1,7 +1,7 @@
DROP FUNCTION IF EXISTS grest.account_history (text, integer);

CREATE FUNCTION grest.account_history (
_address text DEFAULT NULL,
_address text,
_epoch_no integer DEFAULT NULL
) RETURNS TABLE (
stake_address varchar,
Expand Down
43 changes: 43 additions & 0 deletions files/grest/rpc/assets/asset_tx_history.sql
@@ -0,0 +1,43 @@
DROP FUNCTION IF EXISTS grest.asset_tx_history (text, text);

CREATE FUNCTION grest.asset_tx_history (_asset_policy text, _asset_name text)
RETURNS TABLE (
policy_id text,
asset_name text,
tx_hashes text[]
)
LANGUAGE PLPGSQL
AS $$
DECLARE
_asset_policy_decoded bytea;
_asset_name_decoded bytea;
_asset_id int;
BEGIN
SELECT DECODE(_asset_policy, 'hex') INTO _asset_policy_decoded;
SELECT DECODE(_asset_name, 'hex') INTO _asset_name_decoded;
SELECT id INTO _asset_id FROM multi_asset MA WHERE MA.policy = _asset_policy_decoded AND MA.name = _asset_name_decoded;

RETURN QUERY
SELECT
_asset_policy,
_asset_name,
array_agg(
ENCODE(tx_hashes.hash, 'hex')
ORDER BY tx_hashes.id
)
FROM (
SELECT DISTINCT ON (tx.hash)
tx.id,
tx.hash
FROM
ma_tx_out MTO
INNER JOIN tx_out TXO ON TXO.id = MTO.tx_out_id
INNER JOIN tx ON tx.id = TXO.tx_id
WHERE
MTO.ident = _asset_id
GROUP BY
ident,
tx.id
) tx_hashes;
END;
$$;

0 comments on commit f3f02f1

Please sign in to comment.