File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,6 +96,21 @@ impl Db {
9696 . await
9797 }
9898
99+ pub async fn get_daily_tasks_by_address (
100+ & self ,
101+ address : & str ,
102+ ) -> Result < Vec < Receipt > , sqlx:: Error > {
103+ sqlx:: query_as :: < _ , Receipt > (
104+ "SELECT status,merkle_path,nonce,address
105+ FROM tasks
106+ WHERE address = $1
107+ AND inserted_at::date = CURRENT_DATE" ,
108+ )
109+ . bind ( address. to_lowercase ( ) )
110+ . fetch_all ( & self . pool )
111+ . await
112+ }
113+
99114 pub async fn insert_task (
100115 & self ,
101116 address : & str ,
Original file line number Diff line number Diff line change @@ -101,6 +101,30 @@ impl BatcherServer {
101101 } ;
102102 let state = state. get_ref ( ) ;
103103
104+ // Checking if this address has submited more proofs than the ones allowed per day
105+ const MAX_PROOFS_PER_DAY : usize = 4 ;
106+
107+ let daily_tasks_by_address = match state
108+ . db
109+ . get_daily_tasks_by_address ( & recovered_address)
110+ . await
111+ {
112+ Ok ( receipts) => receipts. len ( ) ,
113+ Err ( _) => {
114+ return HttpResponse :: InternalServerError ( ) . json ( AppResponse :: new_unsucessfull (
115+ format ! ( "Internal server error" ) . as_str ( ) ,
116+ 500 ,
117+ ) )
118+ }
119+ } ;
120+
121+ if daily_tasks_by_address >= MAX_PROOFS_PER_DAY {
122+ return HttpResponse :: InternalServerError ( ) . json ( AppResponse :: new_unsucessfull (
123+ format ! ( "Request denied: Query limit exceeded." ) . as_str ( ) ,
124+ 400 ,
125+ ) ) ;
126+ }
127+
104128 let Ok ( count) = state. db . count_tasks_by_address ( & recovered_address) . await else {
105129 return HttpResponse :: InternalServerError ( )
106130 . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ CREATE TABLE tasks (
88 program_commitment BYTEA ,
99 merkle_path BYTEA ,
1010 status task_status DEFAULT ' pending' ,
11- nonce BIGINT NOT NULL
11+ nonce BIGINT NOT NULL ,
12+ inserted_at TIMESTAMPTZ NOT NULL DEFAULT now()
1213);
1314
1415CREATE TABLE payment_events (
@@ -17,5 +18,6 @@ CREATE TABLE payment_events (
1718 amount BIGINT ,
1819 started_at BIGINT ,
1920 valid_until BIGINT ,
20- tx_hash CHAR (66 ) UNIQUE
21+ tx_hash CHAR (66 ) UNIQUE,
22+ inserted_at TIMESTAMPTZ NOT NULL DEFAULT now()
2123);
You can’t perform that action at this time.
0 commit comments