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
CREATE OR REPLACEFUNCTIONprivate.filter_send_token_transfers_with_no_send_account_created()
4
+
RETURNS trigger
5
+
LANGUAGE plpgsql
6
+
SECURITY DEFINER
7
+
AS $function$
8
+
begin
9
+
if exists ( select1from send_account_created where account =new.f )
10
+
or exists ( select1from send_account_created where account =new.t )
11
+
then
12
+
return new;
13
+
else
14
+
return null;
15
+
end if;
16
+
end;
17
+
$function$
18
+
;
19
+
20
+
CREATE OR REPLACEFUNCTIONprivate.filter_send_token_v0_transfers_with_no_send_account_created()
21
+
RETURNS trigger
22
+
LANGUAGE plpgsql
23
+
SECURITY DEFINER
24
+
AS $function$
25
+
begin
26
+
if exists ( select1from send_account_created where account =new.f )
27
+
or exists ( select1from send_account_created where account =new.t )
28
+
then
29
+
return new;
30
+
else
31
+
return null;
32
+
end if;
33
+
end;
34
+
$function$
35
+
;
36
+
37
+
38
+
drop policy "Users can see their own token transfers"on"public"."send_token_transfers";
39
+
40
+
drop policy "Users can see their own token transfers"on"public"."send_token_v0_transfers";
41
+
42
+
CREATEINDEXidx_send_token_transfers_f_t_block_timeONpublic.send_token_transfers USING btree (f, t, block_time);
43
+
44
+
create policy "users can see their own transfers"
45
+
on"public"."send_token_transfers"
46
+
as permissive
47
+
for select
48
+
to public
49
+
using ((EXISTS ( SELECT1
50
+
FROM send_accounts
51
+
WHERE ((send_accounts.user_id= ( SELECTauth.uid() AS uid)) AND ((send_accounts.address= (lower(concat('0x', encode(send_token_transfers.f, 'hex'::text))))::citext) OR (send_accounts.address= (lower(concat('0x', encode(send_token_transfers.t, 'hex'::text))))::citext))))));
52
+
53
+
54
+
create policy "users can see their own transfers"
55
+
on"public"."send_token_v0_transfers"
56
+
as permissive
57
+
for select
58
+
to public
59
+
using ((EXISTS ( SELECT1
60
+
FROM send_accounts
61
+
WHERE ((send_accounts.user_id= ( SELECTauth.uid() AS uid)) AND ((send_accounts.address= (lower(concat('0x', encode(send_token_v0_transfers.f, 'hex'::text))))::citext) OR (send_accounts.address= (lower(concat('0x', encode(send_token_v0_transfers.t, 'hex'::text))))::citext))))));
62
+
63
+
64
+
65
+
CREATETRIGGERfilter_send_token_transfers_with_no_send_account_created BEFORE INSERT ONpublic.send_token_transfers FOR EACH ROW EXECUTE FUNCTION private.filter_send_token_transfers_with_no_send_account_created();
66
+
67
+
CREATETRIGGERfilter_send_token_v0_transfers_with_no_send_account_created BEFORE INSERT ONpublic.send_token_v0_transfers FOR EACH ROW EXECUTE FUNCTION private.filter_send_token_v0_transfers_with_no_send_account_created();
68
+
69
+
70
+
-- Delete from send_token_transfers where neither account exists
71
+
DELETEFROM send_token_transfers
72
+
WHERE NOT EXISTS (SELECT1FROM send_account_created WHERE account = f)
73
+
AND NOT EXISTS (SELECT1FROM send_account_created WHERE account = t);
74
+
75
+
-- Delete from send_token_v0_transfers where neither account exists
76
+
DELETEFROM send_token_v0_transfers
77
+
WHERE NOT EXISTS (SELECT1FROM send_account_created WHERE account = f)
78
+
AND NOT EXISTS (SELECT1FROM send_account_created WHERE account = t);
CREATE POLICY "Users can see their own token transfers"ON"public"."send_token_transfers" FOR SELECT USING (("auth"."uid"() IN ( SELECT"chain_addresses"."user_id"
50
-
FROM"public"."chain_addresses"
51
-
WHERE (("chain_addresses"."address" OPERATOR("public".=) ("lower"("concat"('0x', "encode"("send_token_transfers"."f", 'hex'::"text"))))::"public"."citext") OR ("chain_addresses"."address" OPERATOR("public".=) ("lower"("concat"('0x', "encode"("send_token_transfers"."t", 'hex'::"text"))))::"public"."citext")))));
76
+
create policy "users can see their own transfers"
77
+
on"public"."send_token_transfers"
78
+
as permissive
79
+
for select
80
+
to public
81
+
using ((EXISTS ( SELECT1
82
+
FROM send_accounts
83
+
WHERE ((send_accounts.user_id= ( SELECTauth.uid() AS uid)) AND ((send_accounts.address= (lower(concat('0x', encode(send_token_transfers.f, 'hex'::text))))::citext) OR (send_accounts.address= (lower(concat('0x', encode(send_token_transfers.t, 'hex'::text))))::citext))))));
84
+
85
+
52
86
53
87
-- Grants
54
88
GRANT ALL ON TABLE "public"."send_token_transfers" TO "anon";
@@ -63,3 +97,4 @@ GRANT ALL ON SEQUENCE "public"."send_token_transfers_id_seq" TO "service_role";
63
97
CREATE OR REPLACETRIGGER "insert_verification_send_ceiling_trigger" AFTER INSERT ON"public"."send_token_transfers" FOR EACH ROW EXECUTE FUNCTION "public"."insert_verification_send_ceiling"();
64
98
CREATE OR REPLACETRIGGER "insert_verification_sends" AFTER INSERT ON"public"."send_token_transfers" FOR EACH ROW EXECUTE FUNCTION "public"."insert_verification_sends"();
65
99
CREATE OR REPLACETRIGGER "insert_send_streak_verification" AFTER INSERT ON"public"."send_token_transfers" FOR EACH ROW EXECUTE FUNCTION "public"."insert_send_streak_verification"();
100
+
CREATE OR REPLACETRIGGER "filter_send_token_transfers_with_no_send_account_created" BEFORE INSERT ON"public"."send_token_transfers" FOR EACH ROW EXECUTE FUNCTION "private"."filter_send_token_transfers_with_no_send_account_created"();
CREATE POLICY "Users can see their own token transfers"ON"public"."send_token_v0_transfers" FOR SELECT USING (("auth"."uid"() IN ( SELECT"chain_addresses"."user_id"
50
-
FROM"public"."chain_addresses"
51
-
WHERE (("chain_addresses"."address" OPERATOR("public".=) ("lower"("concat"('0x', "encode"("send_token_v0_transfers"."f", 'hex'::"text"))))::"public"."citext") OR ("chain_addresses"."address" OPERATOR("public".=) ("lower"("concat"('0x', "encode"("send_token_v0_transfers"."t", 'hex'::"text"))))::"public"."citext")))));
75
+
76
+
create policy "users can see their own transfers"
77
+
on"public"."send_token_v0_transfers"
78
+
as permissive
79
+
for select
80
+
to public
81
+
using ((EXISTS ( SELECT1
82
+
FROM send_accounts
83
+
WHERE ((send_accounts.user_id= ( SELECTauth.uid() AS uid)) AND ((send_accounts.address= (lower(concat('0x', encode(send_token_v0_transfers.f, 'hex'::text))))::citext) OR (send_accounts.address= (lower(concat('0x', encode(send_token_v0_transfers.t, 'hex'::text))))::citext))))));
84
+
85
+
52
86
53
87
-- Grants
54
88
GRANT ALL ON TABLE "public"."send_token_v0_transfers" TO "anon";
@@ -62,3 +96,4 @@ GRANT ALL ON SEQUENCE "public"."send_token_v0_transfers_id_seq" TO "service_role
62
96
-- Triggers
63
97
CREATE OR REPLACETRIGGER "insert_verification_sends" AFTER INSERT ON"public"."send_token_v0_transfers" FOR EACH ROW EXECUTE FUNCTION "public"."insert_verification_sends"();
64
98
CREATE OR REPLACETRIGGER "insert_verification_send_ceiling" AFTER INSERT ON"public"."send_token_v0_transfers" FOR EACH ROW EXECUTE FUNCTION "public"."insert_verification_send_ceiling"();
99
+
CREATE OR REPLACETRIGGER "filter_send_token_v0_transfers_with_no_send_account_created" BEFORE INSERT ON"public"."send_token_v0_transfers" FOR EACH ROW EXECUTE FUNCTION "private"."filter_send_token_v0_transfers_with_no_send_account_created"();
0 commit comments