Skip to content

Commit d555365

Browse files
committed
solana: Fix style on err handling
1 parent 33295d6 commit d555365

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

solana/programs/ntt-quoter/src/error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::num::TryFromIntError;
2+
13
#[anchor_lang::prelude::error_code]
24
pub enum NttQuoterError {
35
#[msg("Relay fees exceeds specified max")]
@@ -30,3 +32,9 @@ pub enum NttQuoterError {
3032
#[msg("The price cannot be zero")]
3133
PriceCannotBeZero = 0x103,
3234
}
35+
36+
impl From<TryFromIntError> for NttQuoterError {
37+
fn from(_: TryFromIntError) -> Self {
38+
Self::ScalingOverflow
39+
}
40+
}

solana/programs/ntt-quoter/src/processor/request_relay.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,8 @@ fn mul_div(scalar: u64, numerator: u64, denominator: u64) -> StdResult<u64, NttQ
103103
if scalar == 0 || numerator == 0 {
104104
return Ok(0);
105105
}
106-
107106
u64::try_from(u128::from(scalar) * u128::from(numerator) / u128::from(denominator))
108-
.map_or(Err(NttQuoterError::ScalingOverflow), |quotient| {
109-
Ok(quotient)
110-
})
107+
.map_err(NttQuoterError::from)
111108
}
112109

113110
pub fn request_relay(ctx: Context<RequestRelay>, args: RequestRelayArgs) -> Result<()> {

0 commit comments

Comments
 (0)