Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
101c9e6
Init loanState impl
Kailai-Wang Oct 29, 2025
d007c7a
try to add close_position_test
Kailai-Wang Oct 29, 2025
7f780d3
rename
Kailai-Wang Oct 29, 2025
8f2fdef
update
Kailai-Wang Oct 29, 2025
b9c79b0
update
Kailai-Wang Oct 29, 2025
8b83ee1
improve nonce handling
Kailai-Wang Oct 29, 2025
820f02f
renames
Kailai-Wang Oct 30, 2025
d240cfc
error out
Kailai-Wang Oct 30, 2025
adcf853
refactor the fields in loanRecord
Kailai-Wang Oct 30, 2025
11bdcfb
fix state
Kailai-Wang Oct 31, 2025
c86e09d
Merge branch 'dev' into add-more-loan-record-status
Kailai-Wang Oct 31, 2025
8639e08
add notional validation
Kailai-Wang Oct 31, 2025
5d436f4
fix rounding issue
Kailai-Wang Oct 31, 2025
db6c0ab
try to fix the transfer amount
Kailai-Wang Oct 31, 2025
0ea3e59
more fix
Kailai-Wang Oct 31, 2025
beb343a
replace error types
Kailai-Wang Nov 2, 2025
5673ca9
update
Kailai-Wang Nov 3, 2025
09c8b41
Merge branch 'dev' into simplify-rpc-response
Kailai-Wang Nov 3, 2025
3d1a672
compile works
Kailai-Wang Nov 3, 2025
94004b8
fix warning
Kailai-Wang Nov 3, 2025
2a6c20a
update
Kailai-Wang Nov 3, 2025
226bc2d
fix invalid chain id
Kailai-Wang Nov 3, 2025
2afa245
update
Kailai-Wang Nov 3, 2025
05ff585
update
Kailai-Wang Nov 3, 2025
db72a3b
update
Kailai-Wang Nov 3, 2025
2c79c1a
simplify
Kailai-Wang Nov 4, 2025
ec11e9b
update
Kailai-Wang Nov 4, 2025
a587721
Merge branch 'dev' into simplify-rpc-response
Kailai-Wang Nov 4, 2025
18f90d4
update
Kailai-Wang Nov 4, 2025
3d92328
update
Kailai-Wang Nov 4, 2025
19dc19d
try to fix ci
Kailai-Wang Nov 4, 2025
d1ce7fd
fix reviews
Kailai-Wang Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 0 additions & 144 deletions tee-worker/omni-executor/rpc-server/src/auth_utils.rs

This file was deleted.

137 changes: 57 additions & 80 deletions tee-worker/omni-executor/rpc-server/src/detailed_error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::error_code::{
ACCOUNT_PARSE_ERROR_CODE, EMAIL_SERVICE_ERROR_CODE, GAS_ESTIMATION_FAILED_CODE,
INVALID_ADDRESS_FORMAT_CODE, INVALID_AMOUNT_CODE, INVALID_CHAIN_ID_CODE,
INVALID_HEX_FORMAT_CODE, INVALID_USER_OPERATION_CODE, INVALID_WALLET_INDEX_CODE,
SIGNATURE_SERVICE_UNAVAILABLE_CODE, SIGNER_SERVICE_ERROR_CODE, STORAGE_SERVICE_ERROR_CODE,
UNEXPECTED_RESPONSE_TYPE_CODE,
EMAIL_SERVICE_ERROR_CODE, GAS_ESTIMATION_FAILED_CODE, INVALID_BACKEND_RESPONSE_CODE,
INVALID_USEROP_CODE, PUMPX_SERVICE_ERROR_CODE, SIGNER_SERVICE_ERROR_CODE,
STORAGE_SERVICE_ERROR_CODE, WILDMETA_SERVICE_ERROR_CODE,
};
use jsonrpsee::types::ErrorObject;
use jsonrpsee::types::{ErrorCode, ErrorObject, ErrorObjectOwned};
use parity_scale_codec::Codec;
use pumpx::methods::common::ApiResponse;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -17,6 +17,8 @@ pub struct DetailedError {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorDetails {
#[serde(skip_serializing_if = "Option::is_none")]
pub backend_response: Option<BackendResponse>,
#[serde(skip_serializing_if = "Option::is_none")]
pub field: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -29,12 +31,19 @@ pub struct ErrorDetails {
pub suggestion: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackendResponse {
pub code: i32,
pub message: String,
}

impl DetailedError {
pub fn new(code: i32, message: impl Into<String>) -> Self {
Self {
code,
message: message.into(),
details: ErrorDetails {
backend_response: None,
field: None,
expected: None,
received: None,
Expand Down Expand Up @@ -69,76 +78,49 @@ impl DetailedError {
self
}

pub fn to_error_object(&self) -> ErrorObject<'static> {
pub fn with_backend_response(mut self, code: i32, message: impl Into<String>) -> Self {
self.details.backend_response = Some(BackendResponse { code, message: message.into() });
self
}

pub fn to_rpc_error(&self) -> ErrorObjectOwned {
ErrorObject::owned(self.code, self.message.clone(), Some(self.details.clone()))
}
}

impl DetailedError {
pub fn invalid_chain_id(chain_id: u64, supported_chains: &[u64]) -> Self {
Self::new(INVALID_CHAIN_ID_CODE, "Invalid or unsupported chain ID")
.with_field("chain_id")
.with_received(chain_id.to_string())
.with_expected(format!("One of: {:?}", supported_chains))
.with_suggestion("Use a supported chain ID from the list")
pub fn internal_error(reason: &str) -> Self {
Self::new(ErrorCode::InternalError.code(), ErrorCode::InternalError.message())
.with_reason(reason)
}

pub fn invalid_wallet_index(index: u32, max_index: u32) -> Self {
Self::new(INVALID_WALLET_INDEX_CODE, "Wallet index out of bounds")
.with_field("wallet_index")
.with_received(index.to_string())
.with_expected(format!("0 to {}", max_index))
.with_suggestion(format!("Use a wallet index between 0 and {}", max_index))
pub fn parse_error(reason: &str) -> Self {
Self::new(ErrorCode::ParseError.code(), ErrorCode::ParseError.message()).with_reason(reason)
}

pub fn invalid_address_format(field: &str, address: &str, expected_format: &str) -> Self {
Self::new(INVALID_ADDRESS_FORMAT_CODE, "Invalid address format")
pub fn invalid_params(field: &str, reason: &str) -> Self {
Self::new(ErrorCode::InvalidParams.code(), ErrorCode::InvalidParams.message())
.with_field(field)
.with_received(address.to_string())
.with_expected(expected_format)
.with_suggestion("Ensure the address follows the correct format")
.with_reason(reason)
}

pub fn invalid_amount(field: &str, amount: &str, reason: &str) -> Self {
Self::new(INVALID_AMOUNT_CODE, "Invalid amount value")
.with_field(field)
.with_received(amount.to_string())
.with_expected("Positive number within valid range")
.with_suggestion(reason)
}

pub fn invalid_hex_format(field: &str, value: &str, expected_length: Option<usize>) -> Self {
let expected = if let Some(len) = expected_length {
format!("0x-prefixed hex string of {} bytes", len)
} else {
"Valid hexadecimal string".to_string()
};

Self::new(INVALID_HEX_FORMAT_CODE, "Invalid hexadecimal format")
.with_field(field)
.with_received(value.to_string())
.with_expected(expected)
.with_suggestion("Check that the value is properly hex-encoded")
pub fn invalid_backend_response<T: Codec>(response: &ApiResponse<T>, op: &str) -> Self {
Self::new(INVALID_BACKEND_RESPONSE_CODE, "Invalid backend response")
.with_field(op)
.with_backend_response(response.code as i32, response.message.to_owned())
}

pub fn account_parse_error(account: &str, error: &str) -> Self {
Self::new(ACCOUNT_PARSE_ERROR_CODE, "Failed to parse account identifier")
.with_field("omni_account")
.with_received(account.to_string())
.with_expected("Valid 32-byte account identifier")
.with_suggestion(format!("Error: {}", error))
pub fn invalid_chain_id(chain_id: u64) -> Self {
let supported: Vec<u64> =
crate::config::SUPPORTED_EVM_CHAINS.iter().map(|&c| c as u64).collect();
Self::invalid_params(
"chain_id",
&format!("invalid chain_id: {}, expected one of {:?}", chain_id, supported),
)
}

pub fn unexpected_response_type(expected: &str, received: &str) -> Self {
Self::new(UNEXPECTED_RESPONSE_TYPE_CODE, "Unexpected response type from service")
.with_expected(expected)
.with_received(received)
.with_suggestion("This is likely an internal error. Please contact support.")
}

pub fn signer_service_error(operation: &str, error: &str) -> Self {
Self::new(SIGNER_SERVICE_ERROR_CODE, format!("Signer service error during {}", operation))
.with_suggestion(format!("Signer error: {}", error))
pub fn signer_service_error() -> Self {
Self::new(SIGNER_SERVICE_ERROR_CODE, "Signer service error")
}

pub fn email_service_error(email: &str) -> Self {
Expand All @@ -148,35 +130,30 @@ impl DetailedError {
.with_suggestion("Failed to send verification email. Please try again later.")
}

pub fn storage_error(operation: &str) -> Self {
Self::new(STORAGE_SERVICE_ERROR_CODE, format!("Storage service error during {}", operation))
.with_suggestion("Storage operation failed. Please try again later.")
pub fn storage_service_error(op: &str) -> Self {
Self::new(STORAGE_SERVICE_ERROR_CODE, format!("Storage service error in {}", op))
}

// Native task error factory methods
pub fn chain_not_supported(chain_id: u64) -> Self {
// Get supported chains from config
use crate::config::SUPPORTED_EVM_CHAINS;
let supported: Vec<u64> = SUPPORTED_EVM_CHAINS.iter().map(|&c| c as u64).collect();
pub fn pumpx_service_error(op: &str, reason: impl Into<String>) -> Self {
Self::new(PUMPX_SERVICE_ERROR_CODE, format!("Pumpx service error in {}", op))
.with_reason(reason)
}

Self::new(INVALID_CHAIN_ID_CODE, "Chain not supported")
.with_field("chain_id")
.with_received(chain_id.to_string())
.with_expected(format!("One of: {:?}", supported))
.with_suggestion("Please use a supported chain ID")
pub fn wildmeta_service_error(op: &str) -> Self {
Self::new(WILDMETA_SERVICE_ERROR_CODE, format!("Wildmeta service error in {}", op))
}

pub fn invalid_user_operation_error(description: &str) -> Self {
Self::new(INVALID_USER_OPERATION_CODE, description)
pub fn invalid_user_op(reason: &str) -> Self {
Self::new(INVALID_USEROP_CODE, "Invalid UserOp").with_received(reason)
}

pub fn gas_estimation_failed() -> Self {
Self::new(GAS_ESTIMATION_FAILED_CODE, "Unable to estimate gas for operation")
.with_suggestion("Please check the user operation parameters and try again")
Self::new(GAS_ESTIMATION_FAILED_CODE, "Gas estimaton failed")
}
}

pub fn signature_service_unavailable() -> Self {
Self::new(SIGNATURE_SERVICE_UNAVAILABLE_CODE, "Signature service temporarily unavailable")
.with_suggestion("Please try again in a few moments")
impl From<DetailedError> for ErrorObjectOwned {
fn from(error: DetailedError) -> Self {
error.to_rpc_error()
}
}
Loading