@@ -2,6 +2,7 @@ use axum::extract::{Query, State};
22use axum:: http:: StatusCode ;
33use axum:: response:: { IntoResponse , Json , Response } ;
44use katana_executor:: implementation:: blockifier:: BlockifierFactory ;
5+ use katana_pool_api:: TransactionPool ;
56use katana_primitives:: block:: { BlockHash , BlockIdOrTag , BlockNumber } ;
67use katana_primitives:: class:: { ClassHash , CompiledClass , ContractClassCompilationError } ;
78use katana_provider_api:: block:: { BlockIdReader , BlockProvider , BlockStatusProvider } ;
@@ -19,11 +20,14 @@ use crate::types::{
1920
2021/// Shared application state containing the backend
2122#[ derive( Clone ) ]
22- pub struct AppState {
23- pub api : StarknetApi ,
23+ pub struct AppState < P : TransactionPool > {
24+ pub api : StarknetApi < P > ,
2425}
2526
26- impl AppState {
27+ impl < P > AppState < P >
28+ where
29+ P : TransactionPool + Send + Sync + ' static ,
30+ {
2731 // TODO(kariy): support preconfirmed blocks
2832 async fn get_block ( & self , id : BlockIdOrTag ) -> Result < Option < Block > , ApiError > {
2933 self . api
@@ -153,10 +157,13 @@ pub async fn health() -> Json<serde_json::Value> {
153157/// Handler for `/feeder_gateway/get_block` endpoint
154158///
155159/// Returns block information for the specified block.
156- pub async fn get_block (
157- State ( state) : State < AppState > ,
160+ pub async fn get_block < P > (
161+ State ( state) : State < AppState < P > > ,
158162 Query ( params) : Query < BlockIdQuery > ,
159- ) -> Result < Json < Block > , ApiError > {
163+ ) -> Result < Json < Block > , ApiError >
164+ where
165+ P : TransactionPool + Send + Sync + ' static ,
166+ {
160167 let block_id = params. block_id ( ) ?;
161168 let block = state. get_block ( block_id) . await ?. unwrap ( ) ;
162169 Ok ( Json ( block) )
@@ -174,10 +181,13 @@ pub enum GetStateUpdateResponse {
174181/// Handler for `/feeder_gateway/get_state_update` endpoint
175182///
176183/// Returns state update information for the specified block.
177- pub async fn get_state_update (
178- State ( state) : State < AppState > ,
184+ pub async fn get_state_update < P > (
185+ State ( state) : State < AppState < P > > ,
179186 Query ( params) : Query < StateUpdateQuery > ,
180- ) -> Result < Json < GetStateUpdateResponse > , ApiError > {
187+ ) -> Result < Json < GetStateUpdateResponse > , ApiError >
188+ where
189+ P : TransactionPool + Send + Sync + ' static ,
190+ {
181191 let include_block = params. include_block ;
182192 let block_id = params. block_query . block_id ( ) ?;
183193
@@ -196,10 +206,13 @@ pub async fn get_state_update(
196206/// Handler for `/feeder_gateway/get_class_by_hash` endpoint
197207///
198208/// Returns the contract class definition for a given class hash.
199- pub async fn get_class_by_hash (
200- State ( state) : State < AppState > ,
209+ pub async fn get_class_by_hash < P > (
210+ State ( state) : State < AppState < P > > ,
201211 Query ( params) : Query < ClassQuery > ,
202- ) -> Result < Json < ContractClass > , ApiError > {
212+ ) -> Result < Json < ContractClass > , ApiError >
213+ where
214+ P : TransactionPool + Send + Sync + ' static ,
215+ {
203216 let class_hash = params. class_hash ;
204217 let block_id = params. block_query . block_id ( ) ?;
205218 let class = state. api . class_at_hash ( block_id, class_hash) . await ?;
@@ -209,10 +222,13 @@ pub async fn get_class_by_hash(
209222/// Handler for `/feeder_gateway/get_compiled_class_by_class_hash` endpoint
210223///
211224/// Returns the compiled (CASM) contract class for a given class hash.
212- pub async fn get_compiled_class_by_class_hash (
213- State ( state) : State < AppState > ,
225+ pub async fn get_compiled_class_by_class_hash < P > (
226+ State ( state) : State < AppState < P > > ,
214227 Query ( params) : Query < ClassQuery > ,
215- ) -> Result < Json < CompiledClass > , ApiError > {
228+ ) -> Result < Json < CompiledClass > , ApiError >
229+ where
230+ P : TransactionPool + Send + Sync + ' static ,
231+ {
216232 let class_hash = params. class_hash ;
217233 let block_id = params. block_query . block_id ( ) ?;
218234
0 commit comments