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
5ee5130
commit f3f02f1
Showing
2 changed files
with
44 additions
and
1 deletion.
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
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,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; | ||
$$; |