Skip to content

Commit 2448a75

Browse files
author
wli-pro
committed
fix: P-1485 remove Option for ApiResponse.data
1 parent b9a73be commit 2448a75

File tree

7 files changed

+37
-100
lines changed

7 files changed

+37
-100
lines changed

tee-worker/omni-executor/intent/executors/cross-chain/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,7 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest> + Send + Sy
972972
})?;
973973
debug!("Response get_gas_info: {:?}", res);
974974

975-
let Some(gas_info_data) = res.data else {
976-
log::error!("Response data of call get gas info is none");
977-
return Err(());
978-
};
979-
let Some(gas_info_vec) = gas_info_data.gas_info else {
975+
let Some(gas_info_vec) = res.data.gas_info else {
980976
log::error!("Response data.gas_info of call get gas info is none");
981977
return Err(());
982978
};

tee-worker/omni-executor/native-task-handler/src/lib.rs

+8-34
Original file line numberDiff line numberDiff line change
@@ -598,16 +598,7 @@ async fn handle_native_task<
598598
};
599599
log::debug!("Response pumpx get_account_user_id: {:?}", res);
600600

601-
let Some(res_data) = res.data else {
602-
send_error(
603-
"Response data of call get_account_user_id is none".to_string(),
604-
response_sender,
605-
NativeTaskError::PumpxApiError(PumpxApiError::GetAccountUserIdFailed),
606-
);
607-
return;
608-
};
609-
610-
let Some(user_id) = res_data.user_id else {
601+
let Some(user_id) = res.data.user_id else {
611602
send_error(
612603
"Response data.user_id of call get_account_user_id is none".to_string(),
613604
response_sender,
@@ -658,20 +649,11 @@ async fn handle_native_task<
658649
log::debug!("Response pumpx user_connect: {:?}", backend_response);
659650

660651
// check google auth value
661-
if let Some(ref user_connect_res) = backend_response.data {
662-
if !user_connect_res.google_auth_check.unwrap_or(false) {
663-
send_error(
664-
"Google code verification failed from user_connect".to_string(),
665-
response_sender,
666-
NativeTaskError::PumpxApiError(PumpxApiError::GoogleCodeVerificationFailed),
667-
);
668-
return;
669-
}
670-
} else {
652+
if !backend_response.data.google_auth_check.unwrap_or(false) {
671653
send_error(
672-
"Invalid response data field of user_connect".to_string(),
654+
"Google code verification failed from user_connect".to_string(),
673655
response_sender,
674-
NativeTaskError::PumpxApiError(PumpxApiError::UserConnectionFailed),
656+
NativeTaskError::PumpxApiError(PumpxApiError::GoogleCodeVerificationFailed),
675657
);
676658
return;
677659
}
@@ -1100,27 +1082,19 @@ async fn verify_google_code(
11001082
language: Option<String>,
11011083
) -> bool {
11021084
log::debug!("Calling pumpx verify_google_code, code: {}", google_code);
1103-
let verify_result = pumpx_api.verify_google_code(&access_token, google_code, language).await;
1085+
let verify_result = pumpx_api.verify_google_code(access_token, google_code, language).await;
11041086
verify_result.map_or_else(
11051087
|e| {
11061088
log::error!("Google code verification request failed: {:?}", e);
11071089
false
11081090
},
11091091
|res| {
1110-
res.data.map_or_else(
1092+
res.data.result.map_or_else(
11111093
|| {
1112-
log::error!("Google code verification response data is none");
1094+
log::error!("Google code verification response result is none");
11131095
false
11141096
},
1115-
|data| {
1116-
data.result.map_or_else(
1117-
|| {
1118-
log::error!("Google code verification response result is none");
1119-
false
1120-
},
1121-
|success| success,
1122-
)
1123-
},
1097+
|success| success,
11241098
)
11251099
},
11261100
)

tee-worker/omni-executor/pumpx/src/pumpx_api/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ impl GasType {
6767
pub struct ApiResponse<T: Codec> {
6868
pub code: u32,
6969
pub message: String,
70-
pub data: Option<T>,
70+
pub data: T,
7171
}
7272

7373
impl<T: Codec> ApiResponse<T> {
74-
pub fn data(&self) -> &Option<T> {
74+
pub fn data(&self) -> &T {
7575
&self.data
7676
}
7777
}

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

+18-48
Original file line numberDiff line numberDiff line change
@@ -171,54 +171,12 @@ pub fn register_submit_swap_order(module: &mut RpcModule<RpcContext>) {
171171

172172
log::debug!("Response pumpx get_user_trade_info: {:?}", user_trade_info);
173173

174-
let Some(user_trade_info_data) = user_trade_info.data else {
175-
log::error!("Response data of call get_user_trade_info is none");
176-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
177-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
178-
)));
179-
};
180-
181-
let Some(gas_type_base) = user_trade_info_data.gas_type_base else {
182-
log::error!("Response data.gas_type_base of call get_user_trade_info is none");
183-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
184-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
185-
)));
186-
};
187-
188-
let Some(gas_type_bsc) = user_trade_info_data.gas_type_bsc else {
189-
log::error!("Response data.gas_type_bsc of call get_user_trade_info is none");
190-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
191-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
192-
)));
193-
};
194-
195-
let Some(gas_type_eth) = user_trade_info_data.gas_type_eth else {
196-
log::error!("Response data.gas_type_eth of call get_user_trade_info is none");
197-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
198-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
199-
)));
200-
};
201-
202-
let Some(is_anti_mev) = user_trade_info_data.is_anti_mev else {
203-
log::error!("Response data.is_anti_mev of call get_user_trade_info is none");
204-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
205-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
206-
)));
207-
};
208-
209-
let Some(is_auto_slippage) = user_trade_info_data.is_auto_slippage else {
210-
log::error!("Response data.is_auto_slippage of call get_user_trade_info is none");
211-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
212-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
213-
)));
214-
};
215-
216-
let Some(slippage) = user_trade_info_data.slippage else {
217-
log::error!("Response data.slippage of call get_user_trade_info is none");
218-
return Err(PumpxRpcError::from_error_code(ErrorCode::ServerError(
219-
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
220-
)));
221-
};
174+
let gas_type_base = check_and_get_option_user_trade_info_field(user_trade_info.data.gas_type_base, "gas_type_base")?;
175+
let gas_type_bsc = check_and_get_option_user_trade_info_field(user_trade_info.data.gas_type_bsc, "gas_type_bsc")?;
176+
let gas_type_eth = check_and_get_option_user_trade_info_field(user_trade_info.data.gas_type_eth, "gas_type_eth")?;
177+
let is_anti_mev = check_and_get_option_user_trade_info_field(user_trade_info.data.is_anti_mev, "is_anti_mev")?;
178+
let is_auto_slippage = check_and_get_option_user_trade_info_field(user_trade_info.data.is_auto_slippage, "is_auto_slippage")?;
179+
let slippage = check_and_get_option_user_trade_info_field(user_trade_info.data.slippage, "slippage")?;
222180

223181
let gas_type = match params.to_chain_id {
224182
BASE_CHAIN_ID => gas_type_base.to_number() as u32,
@@ -353,3 +311,15 @@ pub fn register_submit_swap_order(module: &mut RpcModule<RpcContext>) {
353311
})
354312
.expect("Failed to register omni_submitSwapOrder method");
355313
}
314+
315+
fn check_and_get_option_user_trade_info_field<T>(
316+
field_value: Option<T>,
317+
field_name: &str,
318+
) -> Result<T, PumpxRpcError> {
319+
field_value.ok_or_else(|| {
320+
log::error!("Response data.{} of call get_user_trade_info is none", field_name);
321+
PumpxRpcError::from_error_code(ErrorCode::ServerError(
322+
PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
323+
))
324+
})
325+
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ pub fn register_export_wallet(module: &mut RpcModule<RpcContext>) {
8484
};
8585
log::debug!("Response pumpx get_account_user_id: {:?}", res);
8686

87-
let res_data = check_and_get_option_response_data(res.data, PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE, "Response data of call get_account_user_id is none")?;
88-
let user_id = check_and_get_option_response_data(res_data.user_id, PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE, "Response data.user_id of call get_account_user_id is none")?;
87+
let user_id = check_and_get_option_response_data(res.data.user_id, PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE, "Response data.user_id of call get_account_user_id is none")?;
8988

9089
if user_id != params.user_id {
9190
log::error!(

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ pub fn register_submit_swap_order(module: &mut RpcModule<RpcContext>) {
173173

174174
log::debug!("Response pumpx get_user_trade_info: {:?}", user_trade_info);
175175

176-
let user_trade_info_data = check_and_get_option_response_data(user_trade_info.data, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data of call get_user_trade_info is none")?;
177-
let gas_type_base = check_and_get_option_response_data(user_trade_info_data.gas_type_base, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.gas_type_base of call get_user_trade_info is none")?;
178-
let gas_type_bsc = check_and_get_option_response_data(user_trade_info_data.gas_type_bsc, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.gas_type_bsc of call get_user_trade_info is none")?;
179-
let gas_type_eth = check_and_get_option_response_data(user_trade_info_data.gas_type_eth, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.gas_type_eth of call get_user_trade_info is none")?;
176+
let gas_type_base = check_and_get_option_response_data(user_trade_info.data.gas_type_base, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.gas_type_base of call get_user_trade_info is none")?;
177+
let gas_type_bsc = check_and_get_option_response_data(user_trade_info.data.gas_type_bsc, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.gas_type_bsc of call get_user_trade_info is none")?;
178+
let gas_type_eth = check_and_get_option_response_data(user_trade_info.data.gas_type_eth, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.gas_type_eth of call get_user_trade_info is none")?;
180179

181180
let gas_type = match params.to_chain_id {
182181
BASE_CHAIN_ID => gas_type_base.to_number() as u32,
@@ -212,9 +211,9 @@ pub fn register_submit_swap_order(module: &mut RpcModule<RpcContext>) {
212211
PumpxRpcError::from_error_code(ErrorCode::InvalidParams)
213212
})?;
214213

215-
let is_anti_mev = check_and_get_option_response_data(user_trade_info_data.is_anti_mev, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.is_anti_mev of call get_user_trade_info is none")?;
216-
let is_auto_slippage = check_and_get_option_response_data(user_trade_info_data.is_auto_slippage, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.is_auto_slippage of call get_user_trade_info is none")?;
217-
let slippage = check_and_get_option_response_data(user_trade_info_data.slippage, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.slippage of call get_user_trade_info is none")?;
214+
let is_anti_mev = check_and_get_option_response_data(user_trade_info.data.is_anti_mev, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.is_anti_mev of call get_user_trade_info is none")?;
215+
let is_auto_slippage = check_and_get_option_response_data(user_trade_info.data.is_auto_slippage, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.is_auto_slippage of call get_user_trade_info is none")?;
216+
let slippage = check_and_get_option_response_data(user_trade_info.data.slippage, PUMPX_API_GET_USER_TRADE_INFO_FAILED_CODE, "Response data.slippage of call get_user_trade_info is none")?;
218217

219218
let pumpx_config = PumpxConfig {
220219
order_type: params.order_type.clone(),

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ pub fn register_transfer_withdraw(module: &mut RpcModule<RpcContext>) {
7676
};
7777
log::debug!("Response pumpx get_account_user_id: {:?}", res);
7878

79-
let res_data = check_and_get_option_response_data(res.data, PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE, "Response data of call get_account_user_id is none")?;
80-
let user_id = check_and_get_option_response_data(res_data.user_id, PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE, "Response data.user_id of call get_account_user_id is none")?;
79+
let user_id = check_and_get_option_response_data(res.data.user_id, PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE, "Response data.user_id of call get_account_user_id is none")?;
8180

8281
if user_id != params.user_id {
8382
log::error!(

0 commit comments

Comments
 (0)