@@ -18,7 +18,7 @@ use katana_primitives::execution::Call;
1818use katana_primitives:: fee:: { AllResourceBoundsMapping , ResourceBoundsMapping } ;
1919use katana_primitives:: ContractAddress ;
2020use katana_provider:: { ProviderFactory , ProviderRO } ;
21- use katana_rpc_client :: starknet:: StarknetApiError ;
21+ use katana_rpc_api :: error :: starknet:: StarknetApiError ;
2222use katana_rpc_types:: broadcasted:: { BroadcastedTx , BroadcastedTxWithChainId } ;
2323use katana_rpc_types:: { BroadcastedInvokeTx , FeeEstimate } ;
2424use serde:: Deserialize ;
9999 vrf_service : Option < VrfService > ,
100100}
101101
102- impl < Pool , PP , PF > ControllerDeployment < Pool , PP , PF >
102+ impl < Pool , PoolTx , PP , PF > ControllerDeployment < Pool , PP , PF >
103103where
104- Pool : TransactionPool ,
104+ Pool : TransactionPool < Transaction = PoolTx > + Send + Sync + ' static ,
105+ PoolTx : From < BroadcastedTxWithChainId > ,
105106 PP : PendingBlockProvider ,
106107 PF : ProviderFactory ,
107108 <PF as ProviderFactory >:: Provider : ProviderRO ,
@@ -110,9 +111,18 @@ where
110111 starknet : StarknetApi < Pool , PP , PF > ,
111112 cartridge_api : CartridgeApiClient ,
112113 paymaster_client : HttpClient ,
114+ deployer_address : ContractAddress ,
115+ deployer_private_key : SigningKey ,
113116 vrf_service : Option < VrfService > ,
114117 ) -> Self {
115- Self { starknet, cartridge_api, paymaster_client, vrf_service }
118+ Self {
119+ starknet,
120+ cartridge_api,
121+ paymaster_client,
122+ deployer_address,
123+ deployer_private_key,
124+ vrf_service,
125+ }
116126 }
117127
118128 pub async fn handle_estimate_fee_inner (
@@ -170,6 +180,31 @@ where
170180 }
171181 }
172182
183+ pub async fn handle_execute_outside_inner (
184+ & self ,
185+ address : ContractAddress ,
186+ ) -> Result < ( ) , Error > {
187+ // check if the address has already been deployed.
188+ match self . starknet . class_hash_at_address ( block_id, address) . await {
189+ // attempt to deploy if the address belongs to a Controller account
190+ Err ( StarknetApiError :: ContractNotFound ) => {
191+ let mut deployer_nonce =
192+ self . starknet . nonce_at ( block_id, self . deployer_address ) . await . unwrap ( ) ;
193+
194+ let result = self . get_controller_deployment_tx ( address, deployer_nonce) . await ?;
195+
196+ // none means the address is not a Controller
197+ if let Some ( tx) = result {
198+ let _ = self . starknet . add_invoke_tx ( tx) . await . unwrap ( ) ;
199+ }
200+ }
201+ Err ( e) => panic ! ( "{}" , e. to_string( ) ) ,
202+ Ok ( ..) => { }
203+ }
204+
205+ Ok ( ( ) )
206+ }
207+
173208 async fn get_controller_deployment_tx (
174209 & self ,
175210 address : ContractAddress ,
@@ -241,18 +276,19 @@ where
241276 return self . service . call ( request) . await ;
242277 } ;
243278
244- let updated_txs = self
245- . inner
246- . handle_estimate_fee_inner ( params. block_id , params. txs )
247- . await
248- . unwrap_or_default ( ) ;
249-
250279 // if `handle_estimate_fees` has added some new transactions at the
251280 // beginning of updated_txs, we have to remove
252281 // extras results from estimate_fees to be
253282 // sure to return the same number of result than the number
254283 // of transactions in the request.
255284 let nb_of_txs = params. txs . len ( ) ;
285+
286+ let updated_txs = self
287+ . inner
288+ . handle_estimate_fee_inner ( params. block_id , params. txs )
289+ . await
290+ . unwrap_or_default ( ) ;
291+
256292 let nb_of_extra_txs = updated_txs. len ( ) - nb_of_txs;
257293
258294 let new_request = build_new_estimate_fee_request ( & request, & params, updated_txs) ;
@@ -274,7 +310,7 @@ where
274310 ) ;
275311
276312 // TODO: restore the real response
277- return Self :: build_no_fee_response ( & request, nb_of_txs) ;
313+ return build_no_fee_response ( & request, nb_of_txs) ;
278314 }
279315 }
280316
@@ -305,10 +341,10 @@ where
305341 request : Request < ' a > ,
306342 ) -> impl Future < Output = Self :: MethodResponse > + Send + ' a {
307343 async move {
308- if request. method_name ( ) == "starknet_estimateFee" {
309- self . handle_estimate_fee ( request) . await
310- } else {
311- self . service . call ( request) . await
344+ match request. method_name ( ) {
345+ "starknet_estimateFee" => self . handle_estimate_fee ( request) . await ,
346+ "addExecuteOutsideTransaction" | "addExecuteFromOutside" => todo ! ( ) ,
347+ _ => self . service . call ( request) . await ,
312348 }
313349 }
314350 }
0 commit comments