Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to
- cosmwasm-std: Implement `pow`/`checked_pow` for `Uint64`/`Uint128`/`Uint512`.
- cosmwasm-std: Implement `SubAssign`/`AddAssign` for `Decimal`/`Decimal256`.
- cosmwasm-std: Implement `MulAssign` for `Decimal`/`Decimal256`.
- cosmwasm-std: Implement `is_zero`/`atomics`/`decimal_places` as const for Uint
and Decimal types.
- cosmwasm-crypto: Upgrade ed25519-zebra to version 3.

### Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/std/src/math/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Decimal {
)
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0.is_zero()
}

Expand All @@ -141,15 +141,15 @@ impl Decimal {
/// assert_eq!(b.decimal_places(), 18);
/// assert_eq!(b.atomics(), Uint128::new(1));
/// ```
pub fn atomics(&self) -> Uint128 {
pub const fn atomics(&self) -> Uint128 {
self.0
}

/// The number of decimal places. This is a constant value for now
/// but this could potentially change as the type evolves.
///
/// See also [`Decimal::atomics()`].
pub fn decimal_places(&self) -> u32 {
pub const fn decimal_places(&self) -> u32 {
Self::DECIMAL_PLACES as u32
}

Expand Down
6 changes: 3 additions & 3 deletions packages/std/src/math/decimal256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Decimal256 {
)
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0.is_zero()
}

Expand All @@ -153,15 +153,15 @@ impl Decimal256 {
/// assert_eq!(b.decimal_places(), 18);
/// assert_eq!(b.atomics(), Uint256::from(1u128));
/// ```
pub fn atomics(&self) -> Uint256 {
pub const fn atomics(&self) -> Uint256 {
self.0
}

/// The number of decimal places. This is a constant value for now
/// but this could potentially change as the type evolves.
///
/// See also [`Decimal256::atomics()`].
pub fn decimal_places(&self) -> u32 {
pub const fn decimal_places(&self) -> u32 {
Self::DECIMAL_PLACES as u32
}

Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/math/uint128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Uint128 {
self.0.to_le_bytes()
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0 == 0
}

Expand Down
5 changes: 3 additions & 2 deletions packages/std/src/math/uint256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ impl Uint256 {
]
}

pub fn is_zero(&self) -> bool {
self.0.is_zero()
pub const fn is_zero(&self) -> bool {
let words = (self.0).0;
words[0] == 0 && words[1] == 0 && words[2] == 0 && words[3] == 0
}

pub fn pow(self, exp: u32) -> Self {
Expand Down
14 changes: 11 additions & 3 deletions packages/std/src/math/uint512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Uint512 {

/// Creates a Uint512(value) from a big endian representation. It's just an alias for
/// `from_big_endian`.
pub fn new(value: [u8; 64]) -> Self {
pub const fn new(value: [u8; 64]) -> Self {
Self::from_be_bytes(value)
}

Expand Down Expand Up @@ -305,8 +305,16 @@ impl Uint512 {
]
}

pub fn is_zero(&self) -> bool {
self.0.is_zero()
pub const fn is_zero(&self) -> bool {
let words = (self.0).0;
words[0] == 0
&& words[1] == 0
&& words[2] == 0
&& words[3] == 0
&& words[4] == 0
&& words[5] == 0
&& words[6] == 0
&& words[7] == 0
}

pub fn pow(self, exp: u32) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/math/uint64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Uint64 {
self.0.to_le_bytes()
}

pub fn is_zero(&self) -> bool {
pub const fn is_zero(&self) -> bool {
self.0 == 0
}

Expand Down