Skip to content

Commit 5b85952

Browse files
authored
Merge pull request #85 from Lay3rLabs/more-from-into
small api change
2 parents b7c2317 + 051eb62 commit 5b85952

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ members = ["packages/*", "examples/*", "faucet", "integration-test"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.8.1"
6+
version = "0.8.2"
77
edition = "2021"
88
license = "Apache-2.0"
99
repository = "https://github.com/Lay3rLabs/climb"
1010

1111
[workspace.dependencies]
1212
# Local
13-
layer-climb = { path = "packages/layer-climb", version = "0.8.1" }
14-
layer-climb-address = { path = "packages/layer-climb-address", version = "0.8.1" }
15-
layer-climb-cli = { path = "packages/layer-climb-cli", version = "0.8.1" }
16-
layer-climb-config = { path = "packages/layer-climb-config", version = "0.8.1" }
17-
layer-climb-core = { path = "packages/layer-climb-core", version = "0.8.1" }
18-
layer-climb-proto = { path = "packages/layer-climb-proto", version = "0.8.1" }
19-
layer-climb-signer = { path = "packages/layer-climb-signer", version = "0.8.1" }
13+
layer-climb = { path = "packages/layer-climb", version = "0.8.2" }
14+
layer-climb-address = { path = "packages/layer-climb-address", version = "0.8.2" }
15+
layer-climb-cli = { path = "packages/layer-climb-cli", version = "0.8.2" }
16+
layer-climb-config = { path = "packages/layer-climb-config", version = "0.8.2" }
17+
layer-climb-core = { path = "packages/layer-climb-core", version = "0.8.2" }
18+
layer-climb-proto = { path = "packages/layer-climb-proto", version = "0.8.2" }
19+
layer-climb-signer = { path = "packages/layer-climb-signer", version = "0.8.2" }
2020

2121
# General
2222
cfg-if = "1.0.1"

packages/layer-climb-address/src/address.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ impl Address {
3030
pub fn try_from_str(value: &str, addr_kind: &AddrKind) -> Result<Self> {
3131
match addr_kind {
3232
AddrKind::Cosmos { prefix } => {
33-
CosmosAddr::new_string(value, Some(prefix)).map(Self::Cosmos)
33+
CosmosAddr::new_str(value, Some(prefix)).map(Self::Cosmos)
3434
}
35-
AddrKind::Evm => EvmAddr::new_string(value).map(Self::Evm),
35+
AddrKind::Evm => EvmAddr::new_str(value).map(Self::Evm),
3636
}
3737
}
3838

@@ -135,6 +135,14 @@ impl TryFrom<cosmwasm_std::Addr> for Address {
135135
}
136136
}
137137

138+
impl TryFrom<&cosmwasm_std::Addr> for Address {
139+
type Error = anyhow::Error;
140+
141+
fn try_from(addr: &cosmwasm_std::Addr) -> Result<Self> {
142+
Ok(Self::Cosmos(addr.try_into()?))
143+
}
144+
}
145+
138146
#[cw_serde]
139147
#[derive(Eq, Hash)]
140148
pub enum AddrKind {
@@ -186,7 +194,7 @@ mod test {
186194

187195
#[test]
188196
fn test_basic_roundtrip_cosmos() {
189-
let cosmos_addr = CosmosAddr::new_string(TEST_COSMOS_STR, None).unwrap();
197+
let cosmos_addr = CosmosAddr::new_str(TEST_COSMOS_STR, None).unwrap();
190198
let addr: Address = cosmos_addr.clone().into();
191199

192200
assert_eq!(addr.to_string(), TEST_COSMOS_STR);

packages/layer-climb-address/src/address/cosmos.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl CosmosAddr {
6161

6262
// if the prefix is supplied, this will attempt to validate the address against the prefix to ensure they match
6363
// if you just have a public key, use new_cosmos_pub_key instead
64-
pub fn new_string(value: &str, prefix: Option<&str>) -> Result<Self> {
64+
pub fn new_str(value: &str, prefix: Option<&str>) -> Result<Self> {
6565
let (decoded_prefix, decoded_bytes) = if value.starts_with(|c: char| c.is_uppercase()) {
6666
bech32::decode_upper(value)
6767
} else {
@@ -95,7 +95,7 @@ impl CosmosAddr {
9595
if self.prefix() == new_prefix {
9696
Ok(self.clone())
9797
} else {
98-
Self::new_string(&self.bech32_addr, Some(new_prefix))
98+
Self::new_str(&self.bech32_addr, Some(new_prefix))
9999
}
100100
}
101101
}
@@ -111,7 +111,7 @@ impl FromStr for CosmosAddr {
111111
type Err = anyhow::Error;
112112

113113
fn from_str(s: &str) -> Result<Self> {
114-
Self::new_string(s, None)
114+
Self::new_str(s, None)
115115
}
116116
}
117117

@@ -172,7 +172,7 @@ impl TryFrom<cosmwasm_std::Addr> for CosmosAddr {
172172
type Error = anyhow::Error;
173173

174174
fn try_from(addr: cosmwasm_std::Addr) -> Result<Self> {
175-
Self::new_string(addr.as_str(), None)
175+
Self::new_str(addr.as_str(), None)
176176
}
177177
}
178178

@@ -181,3 +181,11 @@ impl From<CosmosAddr> for cosmwasm_std::Addr {
181181
cosmwasm_std::Addr::unchecked(addr.to_string())
182182
}
183183
}
184+
185+
impl TryFrom<&cosmwasm_std::Addr> for CosmosAddr {
186+
type Error = anyhow::Error;
187+
188+
fn try_from(addr: &cosmwasm_std::Addr) -> Result<Self> {
189+
Self::new_str(addr.as_str(), None)
190+
}
191+
}

packages/layer-climb-address/src/address/evm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl EvmAddr {
2929
Err(anyhow!("TODO - support EVM pub key"))
3030
}
3131

32-
pub fn new_string(s: &str) -> Result<Self> {
32+
pub fn new_str(s: &str) -> Result<Self> {
3333
Self::new_vec(const_hex::decode(s.trim())?)
3434
}
3535

@@ -80,7 +80,7 @@ impl FromStr for EvmAddr {
8080
type Err = anyhow::Error;
8181

8282
fn from_str(s: &str) -> Result<Self> {
83-
Self::new_string(s)
83+
Self::new_str(s)
8484
}
8585
}
8686

0 commit comments

Comments
 (0)