Skip to content

Commit

Permalink
Convert Uint to Amount with 0 denom
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Sep 7, 2023
1 parent b5f4caf commit f42f6dd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ impl Amount {
denom: impl Into<u8>,
) -> Result<Self, AmountParseError> {
let denom = denom.into();
let uint = uint.into();
if denom == 0 {
return Ok(Self { raw: uint });
}
match Uint::from(10)
.checked_pow(Uint::from(denom))
.and_then(|scaling| scaling.checked_mul(uint.into()))
.and_then(|scaling| scaling.checked_mul(uint))
{
Some(amount) => Ok(Self { raw: amount }),
None => Err(AmountParseError::ConvertToDecimal),
Expand Down

0 comments on commit f42f6dd

Please sign in to comment.