Skip to content

Commit 87af3d3

Browse files
committed
fix: add COALESCE fallback to near_amount for delegators without ft_burn
1 parent 3ab24b4 commit 87af3d3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

sql_files/views/delegation_events.sql

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,28 @@ SELECT
8181
LIMIT 1
8282
) AS owner_id
8383

84-
, (
84+
, COALESCE(
85+
(
8586
SELECT (safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->'data'->0->>'amount')::NUMERIC
8687
FROM UNNEST(ra.logs) AS t(l)
8788
WHERE safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->>'error' IS NULL
8889
AND safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->>'event' = 'ft_burn'
8990
LIMIT 1
90-
) AS near_amount
91+
),
92+
(
93+
SELECT (safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->'data'->0->>'amount')::NUMERIC
94+
FROM UNNEST(ra.logs) AS t(l)
95+
WHERE safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->>'error' IS NULL
96+
AND safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->>'event' = 'ft_mint'
97+
AND safe_json_parse(REPLACE(l, 'EVENT_JSON:', ''))->'data'->0->>'owner_id' =
98+
CASE
99+
WHEN safe_json_parse(CONVERT_FROM(ra.args, 'UTF8'))->>'error' IS NULL
100+
THEN safe_json_parse(CONVERT_FROM(ra.args, 'UTF8'))->>'receiver_id'
101+
ELSE NULL
102+
END
103+
LIMIT 1
104+
)
105+
) AS near_amount
91106

92107
--Block Data
93108
, ra.block_height

0 commit comments

Comments
 (0)