@@ -49,7 +49,7 @@ use katana_primitives::{ContractAddress, Felt};
4949use katana_provider:: api:: state:: { StateFactoryProvider , StateProvider } ;
5050use katana_provider:: { ProviderFactory , ProviderRO , ProviderRW } ;
5151use katana_rpc_api:: cartridge:: CartridgeApiServer ;
52- use katana_rpc_api:: error:: starknet :: StarknetApiError ;
52+ use katana_rpc_api:: error:: cartridge :: CartridgeApiError ;
5353use katana_rpc_api:: paymaster:: PaymasterApiClient ;
5454use katana_rpc_types:: broadcasted:: AddInvokeTransactionResponse ;
5555use katana_rpc_types:: cartridge:: FeeSource ;
@@ -163,14 +163,14 @@ where
163163 } )
164164 }
165165
166- fn nonce ( & self , address : ContractAddress ) -> Result < Option < Nonce > , StarknetApiError > {
166+ fn nonce ( & self , address : ContractAddress ) -> Result < Option < Nonce > , CartridgeApiError > {
167167 match self . pool . get_nonce ( address) {
168168 pending_nonce @ Some ( ..) => Ok ( pending_nonce) ,
169169 None => Ok ( self . state ( ) ?. nonce ( address) ?) ,
170170 }
171171 }
172172
173- fn state ( & self ) -> Result < Box < dyn StateProvider > , StarknetApiError > {
173+ fn state ( & self ) -> Result < Box < dyn StateProvider > , CartridgeApiError > {
174174 match & * self . block_producer . producer . read ( ) {
175175 BlockProducerMode :: Instant ( _) => Ok ( self . backend . storage . provider ( ) . latest ( ) ?) ,
176176 BlockProducerMode :: Interval ( producer) => Ok ( producer. executor ( ) . read ( ) . state ( ) ) ,
@@ -183,7 +183,7 @@ where
183183 outside_execution : OutsideExecution ,
184184 signature : Vec < Felt > ,
185185 fee_source : Option < FeeSource > ,
186- ) -> Result < AddInvokeTransactionResponse , StarknetApiError > {
186+ ) -> Result < AddInvokeTransactionResponse , CartridgeApiError > {
187187 debug ! ( %contract_address, ?outside_execution, "Adding execute outside transaction." ) ;
188188 self . on_cpu_blocking_task ( move |this| async move {
189189 let pm_address = this. controller_deployer_address ;
@@ -228,15 +228,11 @@ where
228228 get_request_random_call ( & outside_execution)
229229 {
230230 if position + 1 >= outside_execution. len ( ) {
231- return Err ( StarknetApiError :: unexpected (
232- "request_random call must be followed by another call" ,
233- ) ) ;
231+ return Err ( CartridgeApiError :: VrfMissingFollowUpCall ) ;
234232 }
235233
236234 if request_random_call. to != vrf_service. account_address ( ) {
237- return Err ( StarknetApiError :: unexpected (
238- "request_random call must target the vrf account" ,
239- ) ) ;
235+ return Err ( CartridgeApiError :: VrfInvalidTarget ) ;
240236 }
241237
242238 // Delegate VRF computation to the VRF server
@@ -284,7 +280,9 @@ where
284280 . paymaster_client
285281 . execute_raw_transaction ( request)
286282 . await
287- . map_err ( StarknetApiError :: unexpected) ?;
283+ . map_err ( |e| CartridgeApiError :: PaymasterExecutionFailed {
284+ reason : e. to_string ( ) ,
285+ } ) ?;
288286
289287 Ok ( AddInvokeTransactionResponse { transaction_hash : response. transaction_hash } )
290288 } )
@@ -293,7 +291,7 @@ where
293291
294292 /// Spawns an async function that is mostly CPU-bound blocking task onto the manager's blocking
295293 /// pool.
296- async fn on_cpu_blocking_task < T , F > ( & self , func : T ) -> Result < F :: Output , StarknetApiError >
294+ async fn on_cpu_blocking_task < T , F > ( & self , func : T ) -> Result < F :: Output , CartridgeApiError >
297295 where
298296 T : FnOnce ( Self ) -> F ,
299297 F : Future + Send + ' static ,
@@ -315,9 +313,9 @@ where
315313
316314 match self . task_spawner . cpu_bound ( ) . spawn ( task) . await {
317315 TaskResult :: Ok ( result) => Ok ( result) ,
318- TaskResult :: Err ( err) => {
319- Err ( StarknetApiError :: unexpected ( format ! ( "internal task execution failed: {err}" ) ) )
320- }
316+ TaskResult :: Err ( err) => Err ( CartridgeApiError :: InternalError {
317+ reason : format ! ( "task execution failed: {err}" ) ,
318+ } ) ,
321319 }
322320 }
323321}
0 commit comments