-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
refactor: introduce new Message type that can be deserialized safely (#…
…106)
- voting-verifier-v1.1.0
- voting-verifier-v1.0.0
- voting-verifier-v0.5.0
- voting-verifier-v0.4.0
- voting-verifier-v0.3.1
- voting-verifier-v0.3.0
- voting-verifier-v0.2.0
- voting-verifier-v0.1.0
- signature-verifier-api-v0.1.0
- service-registry-v1.1.0
- service-registry-v1.0.0
- service-registry-v0.4.1
- service-registry-v0.3.0
- service-registry-v0.2.2
- service-registry-v0.2.1
- service-registry-v0.2.0
- service-registry-v0.1.0
- router-v1.2.0
- router-v1.1.0
- router-v1.0.1
- router-v1.0.0
- router-v0.4.0
- router-v0.3.3
- router-v0.3.2
- router-v0.3.1
- router-v0.3.0
- router-v0.2.0
- router-v0.1.0
- rewards-v1.2.0
- rewards-v1.1.0
- rewards-v1.0.0
- rewards-v0.4.0
- rewards-v0.3.0
- rewards-v0.2.1
- rewards-v0.2.0
- rewards-v0.1.0
- nexus-gateway-v1.0.0
- nexus-gateway-v0.3.0
- nexus-gateway-v0.2.3
- nexus-gateway-v0.2.2
- nexus-gateway-v0.2.1
- nexus-gateway-v0.2.0
- nexus-gateway-v0.1.0
- multisig-v1.1.1
- multisig-v1.1.0
- multisig-v1.0.0
- multisig-v0.4.1
- multisig-v0.3.0
- multisig-v0.2.1
- multisig-v0.2.0
- multisig-v0.1.1
- multisig-v0.1.0
- multisig-prover-v1.1.1
- multisig-prover-v1.1.0
- multisig-prover-v1.0.1
- multisig-prover-v1.0.0
- multisig-prover-v0.6.1
- multisig-prover-v0.6.0
- multisig-prover-v0.5.0
- multisig-prover-v0.4.0
- multisig-prover-v0.3.0
- multisig-prover-v0.2.0
- multisig-prover-v0.1.0
- interchain-token-service-v1.0.0
- interchain-token-service-v0.1.0
- gateway-v1.1.1
- gateway-v1.1.0
- gateway-v1.0.0
- gateway-v0.2.3
- gateway-v0.2.2
- gateway-v0.2.1
- gateway-v0.2.0
- gateway-v0.1.1
- gateway-v0.1.0
- coordinator-v1.1.0
- coordinator-v1.0.0
- coordinator-v0.2.0
- coordinator-v0.1.2
- coordinator-v0.1.1
- coordinator-v0.1.0
- connection-router-v0.1.0
- axelarnet-gateway-v1.0.0
- axelar-gateway-v0.1.0
- ampd-v1.4.0
- ampd-v1.3.1
- ampd-v1.3.0
- ampd-v1.2.0
- ampd-v1.1.0
- ampd-v1.0.0
- ampd-v0.6.0
- ampd-v0.5.0
- ampd-v0.4.0
- ampd-v0.3.0
- ampd-v0.2.0
- ampd-v0.1.0
- aggregate-verifier-v0.1.1
- aggregate-verifier-v0.1.0
Showing
8 changed files
with
182 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod error; | ||
mod string; | ||
mod timestamp; | ||
mod uint; | ||
mod vec; | ||
|
||
pub use error::Error; | ||
pub use string::String; | ||
pub use timestamp::Timestamp; | ||
pub use uint::{Uint256, Uint64}; | ||
pub use vec::Vec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::nonempty::Error; | ||
use cosmwasm_schema::cw_serde; | ||
use std::ops::Deref; | ||
use std::str::FromStr; | ||
|
||
#[cw_serde] | ||
#[serde(try_from = "std::string::String")] | ||
pub struct String(std::string::String); | ||
|
||
impl TryFrom<std::string::String> for String { | ||
type Error = Error; | ||
|
||
fn try_from(value: std::string::String) -> Result<Self, Self::Error> { | ||
if value.is_empty() { | ||
Err(Error::InvalidValue("empty".to_string())) | ||
} else { | ||
Ok(String(value)) | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<&str> for String { | ||
type Error = Error; | ||
|
||
fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
String::try_from(value.to_string()) | ||
} | ||
} | ||
|
||
impl FromStr for String { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
s.try_into() | ||
} | ||
} | ||
|
||
impl From<String> for std::string::String { | ||
fn from(d: String) -> Self { | ||
d.0 | ||
} | ||
} | ||
|
||
impl Deref for String { | ||
type Target = std::string::String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::nonempty; | ||
|
||
#[test] | ||
fn cannot_convert_from_empty_string() { | ||
assert!(nonempty::String::try_from("").is_err()); | ||
assert!(serde_json::from_str::<nonempty::String>("\"\"").is_err()); | ||
|
||
assert!(nonempty::String::try_from("some string").is_ok()); | ||
assert!(serde_json::from_str::<nonempty::String>("\"some string\"").is_ok()); | ||
} | ||
} |