Skip to content

Commit a9aadf7

Browse files
committed
Deprecate {Decimal,Decimal256,SignedDecimal,SignedDecimal256}::raw
1 parent 0978e4c commit a9aadf7

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ and this project adheres to
4646
- cosmwasm-std: `Uint256::new`/`Uint512::new` now take an `u128` argument
4747
instead of bytes. Use `::from_be_bytes` if you need the old behaviour.
4848
([#2367])
49+
- cosmwasm-std: Deprecate `{Decimal,Decimal256}::raw` and
50+
`{SignedDecimal,SignedDecimal256}::raw` in favour of e.g.
51+
`Decimal::new(Uint128::new(value))`. ([#2399])
4952

5053
## Fixed
5154

@@ -68,6 +71,7 @@ and this project adheres to
6871
[#2378]: https://github.com/CosmWasm/cosmwasm/issues/2378
6972
[#2383]: https://github.com/CosmWasm/cosmwasm/issues/2383
7073
[#2390]: https://github.com/CosmWasm/cosmwasm/issues/2390
74+
[#2399]: https://github.com/CosmWasm/cosmwasm/pull/2399
7175

7276
## [2.2.0] - 2024-12-17
7377

packages/std/src/math/decimal.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ impl Decimal {
5959

6060
/// Creates a Decimal(Uint128(value))
6161
/// This is equivalent to `Decimal::from_atomics(value, 18)` but usable in a const context.
62+
#[deprecated(
63+
since = "3.0.0",
64+
note = "Use Decimal::new(Uint128::new(value)) instead"
65+
)]
6266
pub const fn raw(value: u128) -> Self {
6367
Self(Uint128::new(value))
6468
}
@@ -805,6 +809,7 @@ mod tests {
805809
}
806810

807811
#[test]
812+
#[allow(deprecated)]
808813
fn decimal_raw() {
809814
let value = 300u128;
810815
assert_eq!(Decimal::raw(value).0.u128(), value);
@@ -867,7 +872,7 @@ mod tests {
867872
fn decimal_try_from_signed_works() {
868873
assert_eq!(
869874
Decimal::try_from(SignedDecimal::MAX).unwrap(),
870-
Decimal::raw(SignedDecimal::MAX.atomics().i128() as u128)
875+
Decimal::new(Uint128::new(SignedDecimal::MAX.atomics().i128() as u128))
871876
);
872877
assert_eq!(
873878
Decimal::try_from(SignedDecimal::zero()).unwrap(),

packages/std/src/math/decimal256.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ impl Decimal256 {
6464

6565
/// Creates a Decimal256 from u128
6666
/// This is equivalent to `Decimal256::from_atomics(value, 18)` but usable in a const context.
67+
#[deprecated(
68+
since = "3.0.0",
69+
note = "Use Decimal256::new(Uint256::new(value)) instead"
70+
)]
6771
pub const fn raw(value: u128) -> Self {
6872
Self(Uint256::from_u128(value))
6973
}
@@ -808,6 +812,7 @@ mod tests {
808812
}
809813

810814
#[test]
815+
#[allow(deprecated)]
811816
fn decimal256_raw() {
812817
let value = 300u128;
813818
let expected = Uint256::from(value);

packages/std/src/math/signed_decimal.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl SignedDecimal {
8686
/// # use cosmwasm_std::SignedDecimal;
8787
/// assert_eq!(SignedDecimal::raw(1234i128).to_string(), "0.000000000000001234");
8888
/// ```
89+
#[deprecated(
90+
since = "3.0.0",
91+
note = "Use SignedDecimal::new(Int128::new(value)) instead"
92+
)]
8993
pub const fn raw(value: i128) -> Self {
9094
Self(Int128::new(value))
9195
}
@@ -910,6 +914,8 @@ impl de::Visitor<'_> for SignedDecimalVisitor {
910914

911915
#[cfg(test)]
912916
mod tests {
917+
use crate::Uint128;
918+
913919
use super::*;
914920

915921
use alloc::vec::Vec;
@@ -928,6 +934,7 @@ mod tests {
928934
}
929935

930936
#[test]
937+
#[allow(deprecated)]
931938
fn signed_decimal_raw() {
932939
let value = 300i128;
933940
assert_eq!(SignedDecimal::raw(value).0.i128(), value);
@@ -1461,8 +1468,8 @@ mod tests {
14611468
SignedDecimal::try_from(Decimal::MAX).unwrap_err(),
14621469
SignedDecimalRangeExceeded
14631470
);
1464-
let max = Decimal::raw(SignedDecimal::MAX.atomics().i128() as u128);
1465-
let too_big = max + Decimal::raw(1);
1471+
let max = Decimal::new(Uint128::new(SignedDecimal::MAX.atomics().i128() as u128));
1472+
let too_big = max + Decimal::new(Uint128::one());
14661473
assert_eq!(
14671474
SignedDecimal::try_from(too_big).unwrap_err(),
14681475
SignedDecimalRangeExceeded

packages/std/src/math/signed_decimal_256.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ impl SignedDecimal256 {
9898
/// # use cosmwasm_std::SignedDecimal256;
9999
/// assert_eq!(SignedDecimal256::raw(1234i128).to_string(), "0.000000000000001234");
100100
/// ```
101+
#[deprecated(
102+
since = "3.0.0",
103+
note = "Use SignedDecimal256::new(Int256::new(value)) instead"
104+
)]
101105
pub const fn raw(value: i128) -> Self {
102106
Self(Int256::from_i128(value))
103107
}
@@ -936,6 +940,7 @@ mod tests {
936940
}
937941

938942
#[test]
943+
#[allow(deprecated)]
939944
fn signed_decimal_256_raw() {
940945
let value = 300i128;
941946
assert_eq!(SignedDecimal256::raw(value).0, Int256::from(value));

0 commit comments

Comments
 (0)