Skip to content

Commit e47cb12

Browse files
authored
refactor: make omni_estimateUserOpGas RPC method public (#3658)
* refactor: make omni_estimateUserOpGas RPC method public - Add omni_account and client_id to request parameters - Remove authentication middleware check - Remove from PROTECTED_METHODS array - Update tests with new required fields * fixing fmt issue
1 parent 0b18dd4 commit e47cb12

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

tee-worker/omni-executor/rpc-server/src/methods/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use pumpx::*;
77
mod omni;
88
use omni::*;
99

10-
pub const PROTECTED_METHODS: [&str; 9] = [
10+
pub const PROTECTED_METHODS: [&str; 8] = [
1111
"omni_testProtectedMethod",
1212
"omni_addWallet",
1313
"omni_notifyLimitOrderResult",
@@ -16,7 +16,6 @@ pub const PROTECTED_METHODS: [&str; 9] = [
1616
"omni_submitUserOp",
1717
"omni_transferWithdraw",
1818
"omni_exportWallet",
19-
"omni_estimateUserOpGas",
2019
];
2120

2221
pub fn register_methods(module: &mut RpcModule<RpcContext>) {

tee-worker/omni-executor/rpc-server/src/methods/omni/estimate_user_op_gas.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use super::common::handle_omni_native_task;
18-
use crate::error_code::AUTH_VERIFICATION_FAILED_CODE;
19-
use crate::methods::omni::common::check_auth;
2018
use crate::methods::omni::PumpxRpcError;
2119
use crate::server::RpcContext;
2220
use crate::ErrorCode;
@@ -37,6 +35,8 @@ pub struct EstimateUserOpGasParams {
3735
pub user_operation: SerializablePackedUserOperation,
3836
pub chain_id: ChainId,
3937
pub wallet_index: u32,
38+
pub omni_account: String,
39+
pub client_id: String,
4040
}
4141

4242
#[derive(Serialize, Clone)]
@@ -51,14 +51,7 @@ pub struct EstimateUserOpGasResponse {
5151

5252
pub fn register_estimate_user_op_gas(module: &mut RpcModule<RpcContext>) {
5353
module
54-
.register_async_method("omni_estimateUserOpGas", |params, ctx, ext| async move {
55-
let user = check_auth(&ext).map_err(|e| {
56-
error!("Authentication check failed: {:?}", e);
57-
PumpxRpcError::from_error_code(ErrorCode::ServerError(
58-
AUTH_VERIFICATION_FAILED_CODE,
59-
))
60-
})?;
61-
54+
.register_async_method("omni_estimateUserOpGas", |params, ctx, _ext| async move {
6255
let params = params.parse::<EstimateUserOpGasParams>().map_err(|e| {
6356
error!("Failed to parse params: {:?}", e);
6457
PumpxRpcError::from_error_code(ErrorCode::ParseError)
@@ -67,7 +60,7 @@ pub fn register_estimate_user_op_gas(module: &mut RpcModule<RpcContext>) {
6760
debug!("Received omni_estimateUserOpGas, params: {:?}", params);
6861

6962
let account_id =
70-
decode_account_id(&user.omni_account).map_err(PumpxRpcError::from_error_code)?;
63+
decode_account_id(&params.omni_account).map_err(PumpxRpcError::from_error_code)?;
7164

7265
validate_sender_address(&params.user_operation.sender)
7366
.map_err(PumpxRpcError::from_error_code)?;
@@ -81,7 +74,7 @@ pub fn register_estimate_user_op_gas(module: &mut RpcModule<RpcContext>) {
8174
),
8275
None,
8376
None,
84-
user.client_id,
77+
params.client_id,
8578
);
8679

8780
handle_omni_native_task(&ctx, wrapper, |task_ok| match task_ok {
@@ -264,12 +257,19 @@ mod tests {
264257
"signature": "0x1234"
265258
},
266259
"chain_id": 1,
267-
"wallet_index": 0
260+
"wallet_index": 0,
261+
"omni_account": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
262+
"client_id": "test-client-123"
268263
});
269264

270265
let params: EstimateUserOpGasParams = serde_json::from_value(json).unwrap();
271266
assert_eq!(params.chain_id, 1);
272267
assert_eq!(params.wallet_index, 0);
268+
assert_eq!(
269+
params.omni_account,
270+
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
271+
);
272+
assert_eq!(params.client_id, "test-client-123");
273273
assert_eq!(params.user_operation.sender, "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb9");
274274
assert_eq!(params.user_operation.nonce, 42);
275275
}
@@ -289,7 +289,9 @@ mod tests {
289289
"paymaster_and_data": "0x",
290290
"signature": null
291291
},
292-
"wallet_index": 0
292+
"wallet_index": 0,
293+
"omni_account": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
294+
"client_id": "test-client-123"
293295
// Missing chain_id
294296
});
295297

0 commit comments

Comments
 (0)