Skip to content

Commit

Permalink
convertation using try into
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Feb 28, 2024
1 parent 33739fb commit 75b7f39
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/neutron-sdk/src/interchain_queries/v045/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,10 @@ impl KVReconstruct for Delegations {
}

fn uint256_to_u128(value: Uint256) -> Result<u128, StdError> {
// Convert Uint256 to string
let value_str = value.to_string();

// Attempt to parse the string as u128
match value_str.parse::<u128>() {
Ok(parsed_value) => Ok(parsed_value),
Err(_) => Err(StdError::generic_err("Uint256 value exceeds u128 limits")),
}
let converted: Uint128 = value
.try_into()
.map_err(|_| StdError::generic_err("Uint256 value exceeds u128 limits"))?;
Ok(converted.u128())
}

/// Represents a single unbonding delegation from some validator to some delegator on remote chain
Expand Down

0 comments on commit 75b7f39

Please # to comment.