Skip to content

Commit

Permalink
Upgrade no_std to 1.3
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <[email protected]>
  • Loading branch information
aeryz committed Jan 31, 2023
1 parent f19bf0f commit 34af482
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
13 changes: 3 additions & 10 deletions packages/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,16 @@ cosmwasm_1_1 = []
cosmwasm_1_2 = ["cosmwasm_1_1"]
std = ["forward_ref", "schemars", "serde-json-wasm", "thiserror", "cosmwasm-crypto"]

[dependencies]
base64 = "0.13.0"
cosmwasm-derive = { path = "../derive", version = "1.2.0" }
derivative = { version = "2", optional = true }
forward_ref = "1"
hex = "0.4"

[dependencies]
base64 = { version = "0.13.0", default-features = false, features = ["alloc"] }
cosmwasm-derive = { path = "../derive", version = "1.1.6" }
cosmwasm-derive = { path = "../derive", version = "1.2.0" }
derivative = { version = "2", features = ["use_core"] }
forward_ref = { version = "1", optional = true }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
schemars = { version = "0.8.3", optional = true }
sha2 = "0.10.3"
sha2 = { version = "0.10.3", default-features = false }
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
serde-json-wasm = { version = "0.5.0" }
serde-json-wasm = { version = "0.5.0", optional = true }
thiserror = { version = "1.0.26", optional = true }
uint = { version = "0.9.3", default-features = false }

Expand Down
5 changes: 1 addition & 4 deletions packages/std/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,11 @@ fn hash(ty: &str, key: &[u8]) -> Vec<u8> {
#[cfg(test)]
mod tests {
use super::*;
<<<<<<< HEAD
use crate::HexBinary;
use hex_literal::hex;
=======
use alloc::string::ToString;
use alloc::vec::Vec;
use hex_literal::hex;
#[cfg(feature = "std")]
>>>>>>> 059adae7 (feat(std): no_std)
use std::collections::hash_map::DefaultHasher;
#[cfg(feature = "std")]
use std::collections::HashSet;
Expand Down
36 changes: 32 additions & 4 deletions packages/std/src/errors/std_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,43 @@ impl DivideByZeroError {

#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[derive(Debug, PartialEq, Eq)]
pub enum CheckedMultiplyRatioError {
pub enum CheckedMultiplyFractionError {
#[cfg_attr(feature = "std", error("{0}"))]
DivideByZero(#[from] DivideByZeroError),
DivideByZero(DivideByZeroError),

#[cfg_attr(feature = "std", error("{0}"))]
ConversionOverflow(#[from] ConversionOverflowError),
ConversionOverflow(ConversionOverflowError),

#[cfg_attr(feature = "std", error("{0}"))]
Overflow(#[from] OverflowError),
Overflow(OverflowError),
}

impl From<DivideByZeroError> for CheckedMultiplyFractionError {
fn from(e: DivideByZeroError) -> Self {
Self::DivideByZero(e)
}
}

impl From<ConversionOverflowError> for CheckedMultiplyFractionError {
fn from(e: ConversionOverflowError) -> Self {
Self::ConversionOverflow(e)
}
}

impl From<OverflowError> for CheckedMultiplyFractionError {
fn from(e: OverflowError) -> Self {
Self::Overflow(e)
}
}

#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[derive(Debug, PartialEq, Eq)]
pub enum CheckedMultiplyRatioError {
#[cfg_attr(feature = "std", error("Denominator must not be zero"))]
DivideByZero,

#[cfg_attr(feature = "std", error("Multiplication overflow"))]
Overflow,
}

#[cfg_attr(feature = "std", derive(thiserror::Error))]
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/errors/verification_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "backtraces")]
#[cfg(all(feature = "backtraces", feature = "std"))]
use std::backtrace::Backtrace;

#[cfg(all(not(target_arch = "wasm32"), feature = "std"))]
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "backtraces", feature(backtrace))]
#![cfg_attr(all(feature = "backtraces", feature = "std"), feature(backtrace))]
#![cfg_attr(not(feature = "std"), no_std)]

// Exposed on all platforms
Expand Down
7 changes: 2 additions & 5 deletions packages/std/src/math/uint128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ use core::str::FromStr;
use forward_ref::{forward_ref_binop, forward_ref_op_assign};
use serde::{de, ser, Deserialize, Deserializer, Serialize};

use forward_ref::{forward_ref_binop, forward_ref_op_assign};
use schemars::JsonSchema;
use serde::{de, ser, Deserialize, Deserializer, Serialize};

use crate::errors::{
CheckedMultiplyFractionError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
OverflowOperation, StdError,
};
use crate::{impl_mul_fraction, ConversionOverflowError, Fraction, Uint256, Uint64};
use crate::{impl_mul_fraction, Fraction};
use crate::{ConversionOverflowError, Uint256, Uint64};

/// A thin wrapper around u128 that is using strings for JSON encoding/decoding,
/// such that the full u128 range can be used for clients that convert JSON numbers to floats,
Expand Down
4 changes: 2 additions & 2 deletions packages/std/src/query/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub enum WasmQuery {
}

#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq)]
pub struct ContractInfoResponse {
Expand Down Expand Up @@ -78,7 +77,8 @@ impl ContractInfoResponse {
/// [CodeInfo]: https://github.com/CosmWasm/wasmd/blob/v0.30.0/proto/cosmwasm/wasm/v1/types.proto#L62-L72
/// [CodeInfoResponse]: https://github.com/CosmWasm/wasmd/blob/v0.30.0/proto/cosmwasm/wasm/v1/query.proto#L184-L199
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[cfg(feature = "cosmwasm_1_2")]
pub struct CodeInfoResponse {
pub code_id: u64,
Expand Down
3 changes: 2 additions & 1 deletion packages/std/src/results/cosmos_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ pub enum VoteOption {
}

#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct WeightedVoteOption {
pub option: VoteOption,
pub weight: Decimal,
Expand Down

0 comments on commit 34af482

Please sign in to comment.