Skip to content

Commit fc439e7

Browse files
committed
wip
1 parent 5217e3d commit fc439e7

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

crates/pool/pool-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum PoolError {
2424
#[error("Invalid transaction: {0}")]
2525
InvalidTransaction(Box<InvalidTransactionError>),
2626
#[error("Internal error: {0}")]
27-
Internal(Box<dyn core::error::Error>),
27+
Internal(Box<dyn core::error::Error + Send + Sync + 'static>),
2828
}
2929

3030
pub type PoolResult<T> = Result<T, PoolError>;

crates/pool/pool-api/src/validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ pub struct Error {
153153
/// The hash of the transaction that failed validation.
154154
pub hash: TxHash,
155155
/// The actual error object.
156-
pub error: Box<dyn std::error::Error + Send>,
156+
pub error: Box<dyn std::error::Error + Send + Sync + 'static>,
157157
}
158158

159159
impl Error {
160-
pub fn new(hash: TxHash, error: Box<dyn std::error::Error + Send>) -> Self {
160+
pub fn new(hash: TxHash, error: Box<dyn std::error::Error + Send + Sync + 'static>) -> Self {
161161
Self { hash, error }
162162
}
163163
}

crates/pool/pool/src/validation/stateful.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn validate(
213213

214214
fn map_invalid_tx_err(
215215
err: StatefulValidatorError,
216-
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send>> {
216+
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send + Sync + 'static>> {
217217
match err {
218218
StatefulValidatorError::StateError(err) => Err(Box::new(err)),
219219
StatefulValidatorError::TransactionExecutorError(err) => map_executor_err(err),
@@ -224,7 +224,7 @@ fn map_invalid_tx_err(
224224

225225
fn map_fee_err(
226226
err: TransactionFeeError,
227-
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send>> {
227+
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send + Sync + 'static>> {
228228
match err {
229229
TransactionFeeError::GasBoundsExceedBalance {
230230
resource,
@@ -281,7 +281,7 @@ fn map_fee_err(
281281

282282
fn map_executor_err(
283283
err: TransactionExecutorError,
284-
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send>> {
284+
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send + Sync + 'static>> {
285285
match err {
286286
TransactionExecutorError::TransactionExecutionError(e) => match e {
287287
TransactionExecutionError::TransactionFeeError(e) => map_fee_err(*e),
@@ -298,7 +298,7 @@ fn map_executor_err(
298298

299299
fn map_execution_err(
300300
err: TransactionExecutionError,
301-
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send>> {
301+
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send + Sync + 'static>> {
302302
match err {
303303
e @ TransactionExecutionError::ValidateTransactionError {
304304
storage_address,
@@ -326,7 +326,7 @@ fn map_execution_err(
326326

327327
fn map_pre_validation_err(
328328
err: TransactionPreValidationError,
329-
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send>> {
329+
) -> Result<InvalidTransactionError, Box<dyn std::error::Error + Send + Sync + 'static>> {
330330
match err {
331331
TransactionPreValidationError::TransactionFeeError(err) => map_fee_err(*err),
332332
TransactionPreValidationError::StateError(err) => Err(Box::new(err)),

crates/rpc/rpc-server/src/middleware/cartridge.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ use tracing::{debug, trace};
3232
use crate::cartridge::{encode_calls, VrfService};
3333
use crate::starknet::{PendingBlockProvider, StarknetApi};
3434

35+
const STARKNET_ESTIMATE_FEE: &str = "starknet_estimateFee";
36+
const CARTRIDGE_ADD_EXECUTE_FROM_OUTSIDE: &str = "cartridge_addExecuteFromOutside";
37+
const CARTRIDGE_ADD_EXECUTE_FROM_OUTSIDE_TX: &str = "cartridge_addExecuteOutsideTransaction";
38+
3539
#[derive(Debug)]
3640
pub struct ControllerDeploymentLayer<Pool, PP, PF>
3741
where
@@ -66,8 +70,9 @@ where
6670

6771
impl<S, Pool, PoolTx, PP, PF> ControllerDeploymentService<S, Pool, PP, PF>
6872
where
73+
S: RpcServiceT + Send + Sync + Clone + 'static,
6974
S: RpcServiceT<MethodResponse = MethodResponse>,
70-
Pool: TransactionPool<Transaction = PoolTx> + Send + Sync + 'static,
75+
Pool: TransactionPool<Transaction = PoolTx> + 'static,
7176
PoolTx: From<BroadcastedTxWithChainId>,
7277
PP: PendingBlockProvider,
7378
PF: ProviderFactory,
@@ -78,18 +83,19 @@ where
7883
// extras results from estimate_fees to be
7984
// sure to return the same number of result than the number
8085
// of transactions in the request.
81-
async fn handle_estimate_fee<'a>(
86+
async fn starknet_estimate_fee<'a>(
8287
&self,
8388
params: EstimateFeeParams,
8489
request: Request<'a>,
8590
) -> S::MethodResponse {
91+
let request_id = request.id().clone();
8692
match self.handle_estimate_fee_inner(params, request).await {
8793
Ok(response) => response,
88-
Err(err) => MethodResponse::error(request.id().clone(), ErrorObjectOwned::from(err)),
94+
Err(err) => MethodResponse::error(request_id, ErrorObjectOwned::from(err)),
8995
}
9096
}
9197

92-
async fn handle_execute_outside<'a>(
98+
async fn cartridge_add_execute_from_outside<'a>(
9399
&self,
94100
params: AddExecuteOutsideParams,
95101
request: Request<'a>,
@@ -150,7 +156,7 @@ where
150156
let response = self.service.call(new_request).await;
151157

152158
let res = response.as_json().get();
153-
let mut res = serde_json::from_str::<Response<Vec<FeeEstimate>>>(res).unwrap();
159+
let res = serde_json::from_str::<Response<Vec<FeeEstimate>>>(res).unwrap();
154160

155161
match res.payload {
156162
ResponsePayload::Success(mut estimates) => {
@@ -295,7 +301,7 @@ impl<S, Pool, PoolTx, PP, PF> RpcServiceT for ControllerDeploymentService<S, Poo
295301
where
296302
S: RpcServiceT + Send + Sync + Clone + 'static,
297303
S: RpcServiceT<MethodResponse = MethodResponse>,
298-
Pool: TransactionPool<Transaction = PoolTx> + Send + Sync + 'static,
304+
Pool: TransactionPool<Transaction = PoolTx> + 'static,
299305
PoolTx: From<BroadcastedTxWithChainId>,
300306
PP: PendingBlockProvider,
301307
PF: ProviderFactory,
@@ -315,17 +321,17 @@ where
315321
let method = request.method_name();
316322

317323
match method {
318-
"starknet_estimateFee" => {
324+
STARKNET_ESTIMATE_FEE => {
319325
trace!(%method, "Intercepting JSON-RPC method.");
320326
if let Some(params) = parse_estimate_fee_params(&request) {
321-
return this.handle_estimate_fee(params, request).await;
327+
return this.starknet_estimate_fee(params, request).await;
322328
}
323329
}
324330

325-
"addExecuteOutsideTransaction" | "addExecuteFromOutside" => {
331+
CARTRIDGE_ADD_EXECUTE_FROM_OUTSIDE | CARTRIDGE_ADD_EXECUTE_FROM_OUTSIDE_TX => {
326332
trace!(%method, "Intercepting JSON-RPC method.");
327333
if let Some(params) = parse_execute_outside_params(&request) {
328-
return this.handle_execute_outside(params, request).await;
334+
return this.cartridge_add_execute_from_outside(params, request).await;
329335
}
330336
}
331337

0 commit comments

Comments
 (0)