Skip to content

Commit b893462

Browse files
committed
Remove direct std usage
1 parent 9f03d77 commit b893462

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+124
-36
lines changed

packages/std/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ features = ["abort", "stargate", "staking", "cosmwasm_1_4"]
1414
[features]
1515
default = ["iterator", "abort", "std"]
1616
abort = []
17-
# This feature is currently unused, but might be used in the future to replace internal
18-
# implementation details with no_std compatible ones or feature-gate functionality
19-
# that is only available in std environments.
20-
# You probably want to keep this enabled for now to avoid breaking changes later.
21-
std = []
17+
# This feature can be used in the future to provide support for no_std environments,
18+
# but disabling it will not provide any benefit at the moment. Even with this feature disabled,
19+
# we currently require an std environment.
20+
# You probably want to keep this enabled for now to avoid possible breaking changes later.
21+
std = ["serde/std", "serde-json-wasm/std"]
2222
# iterator allows us to iterate over all DB items in a given range
2323
# optional as some merkle stores (like tries) don't support this
2424
# given Ethereum 1.0, 2.0, Substrate, and other major projects use Tries
@@ -50,13 +50,13 @@ cosmwasm_1_4 = ["cosmwasm_1_3"]
5050
[dependencies]
5151
base64 = "0.21.0"
5252
cosmwasm-derive = { path = "../derive", version = "1.5.0" }
53-
derivative = "2"
53+
derivative = { version = "2", features = ["use_core"] }
5454
forward_ref = "1"
5555
hex = "0.4"
5656
schemars = "0.8.3"
5757
sha2 = "0.10.3"
5858
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
59-
serde-json-wasm = { version = "1.0.0" }
59+
serde-json-wasm = { version = "1.0.0", default-features = false }
6060
thiserror = "1.0.26"
6161
bnum = "0.8.0"
6262
static_assertions = "1.1.0"

packages/std/src/addresses.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use sha2::{
99
};
1010
use thiserror::Error;
1111

12+
use crate::prelude::*;
1213
use crate::{binary::Binary, forward_ref_partial_eq, HexBinary};
1314

1415
/// A human readable address.

packages/std/src/binary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use schemars::JsonSchema;
66
use serde::{de, ser, Deserialize, Deserializer, Serialize};
77

88
use crate::errors::{StdError, StdResult};
9+
use crate::prelude::*;
910

1011
/// Binary is a wrapper around Vec<u8> to add base64 de/serialization
1112
/// with serde. It also adds some helper methods to help encode inline.

packages/std/src/checksum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use serde::{de, ser, Deserialize, Deserializer, Serialize};
55
use sha2::{Digest, Sha256};
66
use thiserror::Error;
77

8+
use crate::prelude::*;
89
use crate::{StdError, StdResult};
910

1011
/// A SHA-256 checksum of a Wasm blob, used to identify a Wasm code.

packages/std/src/coin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::{fmt, str::FromStr};
22
use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
44

5+
use crate::prelude::*;
56
use crate::{errors::CoinFromStrError, math::Uint128};
67

78
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)]

packages/std/src/coins.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use alloc::collections::BTreeMap;
22
use core::fmt;
33
use core::str::FromStr;
44

5+
use crate::prelude::*;
56
use crate::{
67
errors::CoinsError, Coin, OverflowError, OverflowOperation, StdError, StdResult, Uint128,
78
};

packages/std/src/errors/backtrace.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use core::fmt::{Debug, Display, Formatter, Result};
22

3+
use crate::prelude::*;
4+
35
/// This wraps an actual backtrace to achieve two things:
46
/// - being able to fill this with a stub implementation in `no_std` environments
57
/// - being able to use this in conjunction with [`thiserror::Error`]
@@ -9,10 +11,17 @@ impl BT {
911
#[track_caller]
1012
pub fn capture() -> Self {
1113
// in case of no_std, we can fill with a stub here
12-
#[cfg(target_arch = "wasm32")]
13-
return BT(Box::new(std::backtrace::Backtrace::disabled()));
14-
#[cfg(not(target_arch = "wasm32"))]
15-
return BT(Box::new(std::backtrace::Backtrace::capture()));
14+
#[cfg(feature = "std")]
15+
{
16+
#[cfg(target_arch = "wasm32")]
17+
return BT(Box::new(std::backtrace::Backtrace::disabled()));
18+
#[cfg(not(target_arch = "wasm32"))]
19+
return BT(Box::new(std::backtrace::Backtrace::capture()));
20+
}
21+
#[cfg(not(feature = "std"))]
22+
{
23+
BT(Box::new(Stub))
24+
}
1625
}
1726
}
1827

@@ -31,6 +40,23 @@ impl Display for BT {
3140
}
3241
}
3342

43+
#[cfg(not(feature = "std"))]
44+
struct Stub;
45+
46+
#[cfg(not(feature = "std"))]
47+
impl Debug for Stub {
48+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
49+
write!(f, "<disabled>")
50+
}
51+
}
52+
53+
#[cfg(not(feature = "std"))]
54+
impl Display for Stub {
55+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
56+
write!(f, "<disabled>")
57+
}
58+
}
59+
3460
/// This macro implements `From` for a given error type to a given error type where
3561
/// the target error has a `backtrace` field.
3662
/// This is meant as a replacement for `thiserror`'s `#[from]` attribute, which does not

packages/std/src/errors/std_error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::{impl_from_err, BT};
44
use thiserror::Error;
55

66
use crate::errors::{RecoverPubkeyError, VerificationError};
7+
use crate::prelude::*;
78

89
/// Structured error type for init, execute and query.
910
///

packages/std/src/errors/system_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
33

4+
use crate::prelude::*;
45
use crate::Binary;
56

67
/// SystemError is used for errors inside the VM and is API friendly (i.e. serializable).
@@ -39,6 +40,7 @@ pub enum SystemError {
3940
},
4041
}
4142

43+
#[cfg(feature = "std")]
4244
impl std::error::Error for SystemError {}
4345

4446
impl core::fmt::Display for SystemError {

packages/std/src/hex_binary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::ops::Deref;
44
use schemars::JsonSchema;
55
use serde::{de, ser, Deserialize, Deserializer, Serialize};
66

7+
use crate::prelude::*;
78
use crate::{Binary, StdError, StdResult};
89

910
/// This is a wrapper around Vec<u8> to add hex de/serialization

0 commit comments

Comments
 (0)