Skip to content

Commit

Permalink
Trigger fix (#251)
Browse files Browse the repository at this point in the history
## Description
<!--- Describe your changes -->

Three fixes for issues found.

1. Trigger drop wasn't executed correctly on setup-grest.sh deployment.
2. asset_cache_control.sql moved to its correct place in
01_cached_tables, wasn't deployed.
3. asset_nft_address endpoint didn't handle some edge case mint/burn
correctly.

---------

Co-authored-by: Scitz0 <[email protected]>
  • Loading branch information
rdlrt and Scitz0 authored Dec 15, 2023
1 parent db94293 commit e1c9b89
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
27 changes: 19 additions & 8 deletions files/grest/rpc/assets/asset_nft_address.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ BEGIN
AND ma.name = _asset_name_decoded
AND aic.total_supply = 1;

RETURN QUERY
SELECT address
FROM tx_out
WHERE id = (
SELECT MAX(tx_out_id)
FROM ma_tx_out
WHERE ident = _asset_id
);
IF EXISTS (SELECT * FROM ma_tx_mint WHERE ident = _asset_id and quantity < 0 LIMIT 1) THEN
RETURN QUERY
SELECT address
FROM tx_out
WHERE id = (
SELECT MAX(tx_out_id)
FROM ma_tx_out
WHERE ident = _asset_id
);
ELSE
RETURN QUERY
SELECT address
FROM tx_out
INNER JOIN ma_tx_out mto ON mto.tx_out_id = tx_out.id
WHERE mto.ident = _asset_id
AND tx_out.consumed_by_tx_in_id IS NULL
ORDER BY tx_out.id DESC
LIMIT 1;
END IF;
END;
$$;

Expand Down
5 changes: 5 additions & 0 deletions files/grest/rpc/db-scripts/basics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ BEGIN
END
$do$;

-- DROP EXISTING GREST ADDED TRIGGERS ON PUBLIC SCHEMA
FOR r IN (SELECT trigger_name, event_object_table FROM information_schema.triggers WHERE trigger_schema = 'public' AND action_statement LIKE '%grest.%') LOOP
EXECUTE 'DROP TRIGGER IF EXISTS ' || quote_ident(r.trigger_name) || ' ON ' || quote_ident(r.event_object_table);
END LOOP;

-- HELPER FUNCTIONS --
CREATE FUNCTION grest.get_query_pids_partial_match(_query text)
RETURNS TABLE (
Expand Down
5 changes: 0 additions & 5 deletions files/grest/rpc/db-scripts/reset_grest.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
-- Drop triggers first that depend on grest.functions()
SELECT 'DROP TRIGGER ' || trigger_name || ' ON ' || event_object_table || ';'
FROM information_schema.triggers
WHERE trigger_schema = 'public';

-- Recreate grest schema
DROP SCHEMA IF EXISTS grest CASCADE;

Expand Down

0 comments on commit e1c9b89

Please sign in to comment.