You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JOIN ins_outs io ON (((io.code=ws.code) AND (io.script=ws.script))))
23
+
LEFT JOIN ((wallets_descriptors wd
24
+
JOIN descriptors_scripts ds ON (((ds.code=wd.code) AND (ds.descriptor=wd.descriptor))))
25
+
JOIN descriptors d ON (((d.code=ds.code) AND (d.descriptor=ds.descriptor)))) ON (((wd.wallet_id=ws.wallet_id) AND (wd.code=ws.code) AND (ds.script=ws.script))))
26
+
WHERE ((io.blk_idIS NOT NULL) OR (io.mempool IS TRUE));
27
+
28
+
-- Convert a template '0/1/*/2/3' and a keypath `0/1/123/2/3` to 123
29
+
CREATE OR REPLACEFUNCTIONnbxv1_get_keypath_index(metadata JSONB, keypath TEXT) RETURNS BIGINT language SQL IMMUTABLE AS $$
30
+
SELECT
31
+
CASE WHEN keypath LIKE (prefix ||'%') AND
32
+
keypath LIKE ('%'|| suffix) AND
33
+
idx ~ '^\d+$'
34
+
THEN CAST(idx ASBIGINT) END
35
+
FROM (SELECTSUBSTRING(
36
+
keypath
37
+
FROM LENGTH(prefix) +1
38
+
FOR LENGTH(keypath) - LENGTH(prefix) - LENGTH(suffix)
39
+
) idx, prefix, suffix
40
+
FROM (
41
+
SELECT
42
+
split_part(metadata->>'keyPathTemplate', '*', 1) AS prefix,
43
+
split_part(metadata->>'keyPathTemplate', '*', 2) AS suffix
44
+
) parts) q;
45
+
$$;
46
+
47
+
CREATE OR REPLACEFUNCTIONnbxv1_get_keypath(metadata jsonb, idx bigint) RETURNS text
0 commit comments