Skip to content

Commit 00882e6

Browse files
committed
Move addresses
1 parent 08a6a2c commit 00882e6

File tree

12 files changed

+55
-44
lines changed

12 files changed

+55
-44
lines changed

Cargo.lock

Lines changed: 21 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ crc32fast = { version = "1.4.0", optional = true, default-features = false }
1414
derive_more = { version = "1.0.0-beta.6", default-features = false, features = ["display", "from"] }
1515
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
1616
schemars = { version = "0.8.16", optional = true }
17-
serde = { version = "1.0.197", default-features = false, features = ["derive"] }
18-
serde-json-wasm = { version = "1.0.1", default-features = false }
17+
serde = { version = "1.0.197", default-features = false, features = ["alloc", "derive"] }
18+
sha2 = { version = "0.10.8", default-features = false }
1919
static_assertions = "1.1.0"
2020

2121
[features]
@@ -29,3 +29,5 @@ testing = ["dep:crc32fast"]
2929
# I love cyclic dependencies. They are good for your health.
3030
cosmwasm-std = { path = "../std", version = "2.0.0" }
3131
crc32fast = { version = "1.4.0", default-features = false }
32+
hex-literal = "0.4.1"
33+
serde_json = { version = "1.0.114", default-features = false }

packages/std/src/addresses.rs renamed to packages/core/src/addresses.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
use alloc::borrow::Cow;
1+
use alloc::{borrow::Cow, string::String, vec::Vec};
22
use core::fmt;
33
use core::ops::Deref;
4-
use cosmwasm_core::Binary;
5-
use schemars::JsonSchema;
64
use serde::{Deserialize, Serialize};
75
use sha2::{
86
digest::{Digest, Update},
97
Sha256,
108
};
11-
use thiserror::Error;
129

13-
use crate::prelude::*;
10+
use crate::Binary;
1411
use crate::{forward_ref_partial_eq, HexBinary};
1512

1613
/// A human readable address.
@@ -29,9 +26,8 @@ use crate::{forward_ref_partial_eq, HexBinary};
2926
/// This type is immutable. If you really need to mutate it (Really? Are you sure?), create
3027
/// a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String`
3128
/// instance.
32-
#[derive(
33-
Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, JsonSchema,
34-
)]
29+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
30+
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
3531
pub struct Addr(String);
3632

3733
forward_ref_partial_eq!(Addr, Addr);
@@ -131,7 +127,8 @@ impl<'a> From<&'a Addr> for Cow<'a, Addr> {
131127
/// addition to that there are many unsafe ways to convert any binary data into an instance.
132128
/// So the type should be treated as a marker to express the intended data type, not as
133129
/// a validity guarantee of any sort.
134-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash, JsonSchema)]
130+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
131+
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
135132
pub struct CanonicalAddr(Binary);
136133

137134
/// Implement `CanonicalAddr == Binary`
@@ -252,7 +249,7 @@ impl fmt::Display for CanonicalAddr {
252249
}
253250
}
254251

255-
#[derive(Error, Debug, PartialEq, Eq)]
252+
#[derive(Debug, PartialEq, Eq)]
256253
pub enum Instantiate2AddressError {
257254
/// Checksum must be 32 bytes
258255
InvalidChecksumLength,
@@ -269,6 +266,9 @@ impl fmt::Display for Instantiate2AddressError {
269266
}
270267
}
271268

269+
#[cfg(feature = "std")]
270+
impl std::error::Error for Instantiate2AddressError {}
271+
272272
/// Creates a contract address using the predictable address format introduced with
273273
/// wasmd 0.29. When using instantiate2, this is a way to precompute the address.
274274
/// When using instantiate, the contract address will use a different algorithm and
@@ -361,8 +361,9 @@ fn hash(ty: &str, key: &[u8]) -> Vec<u8> {
361361
#[cfg(test)]
362362
mod tests {
363363
use super::*;
364+
use crate::assert_hash_works;
364365
use crate::HexBinary;
365-
use cosmwasm_core::assert_hash_works;
366+
366367
use hex_literal::hex;
367368

368369
#[test]

packages/core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#[macro_use]
88
extern crate alloc;
99

10+
mod addresses;
1011
mod binary;
1112
mod errors;
1213
mod forward_ref;
@@ -16,6 +17,7 @@ mod math;
1617
#[doc(hidden)]
1718
pub mod __internal;
1819

20+
pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr, Instantiate2AddressError};
1921
pub use crate::binary::Binary;
2022
pub use crate::errors::{
2123
CheckedFromRatioError, CheckedMultiplyFractionError, CheckedMultiplyRatioError,

packages/core/src/math/signed_decimal.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,26 +3052,26 @@ mod tests {
30523052
#[test]
30533053
fn signed_decimal_can_be_serialized_and_deserialized() {
30543054
// properly deserialized
3055-
let value: SignedDecimal = serde_json_wasm::from_str(r#""123""#).unwrap();
3055+
let value: SignedDecimal = serde_json::from_str(r#""123""#).unwrap();
30563056
assert_eq!(SignedDecimal::from_str("123").unwrap(), value);
30573057

30583058
// properly serialized
30593059
let value = SignedDecimal::from_str("456").unwrap();
3060-
assert_eq!(r#""456""#, serde_json_wasm::to_string(&value).unwrap());
3060+
assert_eq!(r#""456""#, serde_json::to_string(&value).unwrap());
30613061

30623062
// invalid: not a string encoded decimal
30633063
assert_eq!(
3064-
"Invalid type",
3065-
serde_json_wasm::from_str::<SignedDecimal>("123")
3064+
"invalid type: integer `123`, expected string-encoded decimal at line 1 column 3",
3065+
serde_json::from_str::<SignedDecimal>("123")
30663066
.err()
30673067
.unwrap()
30683068
.to_string()
30693069
);
30703070

30713071
// invalid: not properly defined signed decimal value
30723072
assert_eq!(
3073-
"Error parsing decimal '1.e': Generic error: Error parsing fractional",
3074-
serde_json_wasm::from_str::<SignedDecimal>(r#""1.e""#)
3073+
"Error parsing decimal '1.e': Generic error: Error parsing fractional at line 1 column 5",
3074+
serde_json::from_str::<SignedDecimal>(r#""1.e""#)
30753075
.err()
30763076
.unwrap()
30773077
.to_string()

packages/core/src/math/signed_decimal_256.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,26 +3225,26 @@ mod tests {
32253225
#[test]
32263226
fn signed_decimal_256_can_be_serialized_and_deserialized() {
32273227
// properly deserialized
3228-
let value: SignedDecimal256 = serde_json_wasm::from_str(r#""123""#).unwrap();
3228+
let value: SignedDecimal256 = serde_json::from_str(r#""123""#).unwrap();
32293229
assert_eq!(SignedDecimal256::from_str("123").unwrap(), value);
32303230

32313231
// properly serialized
32323232
let value = SignedDecimal256::from_str("456").unwrap();
3233-
assert_eq!(r#""456""#, serde_json_wasm::to_string(&value).unwrap());
3233+
assert_eq!(r#""456""#, serde_json::to_string(&value).unwrap());
32343234

32353235
// invalid: not a string encoded decimal
32363236
assert_eq!(
3237-
"Invalid type",
3238-
serde_json_wasm::from_str::<SignedDecimal256>("123")
3237+
"invalid type: integer `123`, expected string-encoded decimal at line 1 column 3",
3238+
serde_json::from_str::<SignedDecimal256>("123")
32393239
.err()
32403240
.unwrap()
32413241
.to_string()
32423242
);
32433243

32443244
// invalid: not properly defined signed decimal value
32453245
assert_eq!(
3246-
"Error parsing decimal '1.e': Generic error: Error parsing fractional",
3247-
serde_json_wasm::from_str::<SignedDecimal256>(r#""1.e""#)
3246+
"Error parsing decimal '1.e': Generic error: Error parsing fractional at line 1 column 5",
3247+
serde_json::from_str::<SignedDecimal256>(r#""1.e""#)
32483248
.err()
32493249
.unwrap()
32503250
.to_string()

packages/std/src/ibc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use core::cmp::{Ord, Ordering, PartialOrd};
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
7+
use cosmwasm_core::Addr;
78

8-
use crate::addresses::Addr;
99
use crate::coin::Coin;
1010
use crate::errors::StdResult;
1111
use crate::prelude::*;

packages/std/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Builds without the std feature are currently not expected to work. If you need n
99

1010
// Exposed on all platforms
1111

12-
mod addresses;
1312
mod assertions;
1413
mod checksum;
1514
mod coin;
@@ -43,7 +42,6 @@ pub(crate) mod prelude;
4342
/// contract devs to use it directly.
4443
pub mod storage_keys;
4544

46-
pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr, Instantiate2AddressError};
4745
pub use crate::checksum::{Checksum, ChecksumError};
4846
pub use crate::coin::{coin, coins, has_coins, Coin};
4947
pub use crate::coins::Coins;

packages/std/src/testing/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use serde::de::DeserializeOwned;
1010
#[cfg(feature = "stargate")]
1111
use serde::Serialize;
1212
use sha2::{Digest, Sha256};
13+
use cosmwasm_core::{Addr, CanonicalAddr};
1314

14-
use crate::addresses::{Addr, CanonicalAddr};
1515
use crate::coin::Coin;
1616
use crate::deps::OwnedDeps;
1717
use crate::errors::{RecoverPubkeyError, StdError, StdResult, SystemError, VerificationError};

packages/std/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core::marker::PhantomData;
22
use core::ops::Deref;
33
use serde::{de::DeserializeOwned, Serialize};
4+
use cosmwasm_core::{Addr, CanonicalAddr};
45

5-
use crate::addresses::{Addr, CanonicalAddr};
66
use crate::coin::Coin;
77
use crate::errors::{RecoverPubkeyError, StdError, StdResult, VerificationError};
88
#[cfg(feature = "iterator")]

packages/std/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
3+
use cosmwasm_core::Addr;
34

4-
use crate::addresses::Addr;
55
use crate::coin::Coin;
66
use crate::prelude::*;
77
use crate::timestamp::Timestamp;

0 commit comments

Comments
 (0)