Skip to content

Commit

Permalink
fixed back bech32
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 9, 2024
1 parent efbdc8f commit abbc927
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 45 deletions.
34 changes: 26 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ env_logger = { version = "0.11.3", default-features = false, features = [
hex = { version = "^0.4.3", default-features = false }
enumn = { version = "0.1.13", default-features = false }
prost-build = { version = "^0.12.2" }
bech32 = { version = "^0.11.0", default-features = false }
cosmwasm-std = { version = "^1.5.3", features = [
bech32 = { version = "^0.9.0", default-features = false }
cosmwasm-std = { version = "^1.5.0", features = [
"iterator",
], default-features = false }

Expand All @@ -79,7 +79,7 @@ cw20 = { version = "^1.1.2", default-features = false }
cw-controllers = { version = "^1.1.1", default-features = false }
sylvia = { version = "^0.9.1", default-features = false }
schemars = { version = "^0.8.16", default-features = false }
cosmwasm-schema = { version = "^1.5.3", default-features = false }
cosmwasm-schema = { version = "^1.5.0", default-features = false }
serde = { version = "1.0.192", default-features = false }
cw-storage-plus = { version = "^1.2.0", features = [
"iterator",
Expand Down Expand Up @@ -135,7 +135,8 @@ thiserror = { version = "^1.0.50", default-features = false, package = "thiserro
# xcm = { version = "^5.0.0", default-features = false, package = "staging-xcm" }
cw-utils = { version = "^1.0.3", default-features = false }
cw2 = { version = "^1.1.2", default-features = false }
ibc-apps-more = { git = "https://github.com/ComposableFi/ibc-apps-more-rs.git", rev = "3d24972f89426d1ce06d3189c43ab128a4ff3644", default-features = false }

ibc-apps-more = { git = "https://github.com/ComposableFi/ibc-apps-more-rs.git", rev = "2e665779e1abe316e263633b5470104807605b17", default-features = false }
ibc-app-transfer-types = { git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.git", branch = "dz/14", default-features = false, features = [
"serde",
] }
Expand Down
3 changes: 1 addition & 2 deletions contracts/cosmwasm/outpost/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
use cosmwasm_std::{Deps, Env, MessageInfo};
use cvm::NetworkId;
use cvm_route::transport::*;
use ibc_apps_more::types::hook::derive_intermediate_sender;

/// Authorisation token indicating call is authorised according to policy
/// `T`.
Expand Down Expand Up @@ -99,7 +98,7 @@ impl Auth<policy::WasmHook> {
.ics_20
.ok_or(ContractError::ICS20NotFound)?
.source;
let hash_of_channel_and_sender = derive_intermediate_sender(&channel, &sender, &prefix)?;
let hash_of_channel_and_sender = ibc_apps_more::hook::derive_intermediate_sender(&channel, &sender, &prefix)?;
deps.api.debug(&format!(
"cvm::outpost:auth:: {0} {1}",
&hash_of_channel_and_sender, &info.sender
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/outpost/src/contract/sudo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{error::ContractError, state};
use cosmwasm_std::{entry_point, wasm_execute, Coin, DepsMut, Env, Event, Response};

use ibc_apps_more::types::hook::{IBCLifecycleComplete, SudoMsg};
use ibc_apps_more::hook::{IBCLifecycleComplete, SudoMsg};

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> crate::error::Result {
Expand Down
28 changes: 18 additions & 10 deletions contracts/cosmwasm/outpost/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub enum ContractError {
AlreadyRegistered,
#[error("Route not found.")]
RouteNotFound,
#[error("{0}")]
Bech32(bech32::EncodeError),
// #[error("{0}")]
// Bech32(bech32::EncodeError),
#[error("{0}")]
Serde(#[from] serde_json_wasm::ser::Error),
#[error("Assets non transferrable")]
Expand Down Expand Up @@ -88,11 +88,19 @@ pub enum ContractError {
AccountInProgramIsNotMappableToThisChain,
#[error("Hook error: {0}")]
HookError(String),
#[error("bech32")]
Bech32
}

impl From<ibc_apps_more::types::error::HookError> for ContractError {
fn from(value: ibc_apps_more::types::error::HookError) -> Self {
Self::HookError("value".to_string())
// impl From<ibc_apps_more::types::error::HookError> for ContractError {
// fn from(value: ibc_apps_more::types::error::HookError) -> Self {
// Self::HookError("value".to_string())
// }
// }

impl From<bech32::Error> for ContractError {
fn from(_value: bech32::Error) -> Self {
Self::Bech32
}
}

Expand All @@ -102,11 +110,11 @@ impl From<cvm_runtime::proto::DecodeError> for ContractError {
}
}

impl From<bech32::EncodeError> for ContractError {
fn from(value: bech32::EncodeError) -> Self {
Self::Bech32(value)
}
}
// impl From<bech32::EncodeError> for ContractError {
// fn from(value: bech32::EncodeError) -> Self {
// Self::Bech32(value)
// }
// }

impl From<IdentifierError> for ContractError {
fn from(value: IdentifierError) -> Self {
Expand Down
8 changes: 4 additions & 4 deletions crates/cvm-runtime/src/outpost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cvm_route::{
asset::{AssetItem, AssetReference},
exchange::ExchangeItem,
};
use ibc_apps_more::types::hook::{Callback, LazyHookMemo};
pub use query::*;

use crate::{
Expand Down Expand Up @@ -92,10 +91,11 @@ impl ExecutePacketICS20Msg {

pub fn into_wasm_hook(self, contract: ibc_primitives::Signer) -> Result<ExecuteMsg, StdError> {
let ics20 = self.into_packet()?;
let memo: LazyHookMemo = serde_json_wasm::from_str(ics20.memo.as_ref())
// use ibc_apps_more::types::hook::{Callback, LazyHookMemo};

let memo: ibc_apps_more::memo::Memo = serde_json_wasm::from_str(ics20.memo.as_ref())
.map_err(|x| StdError::generic_err(format!("{:?}", x)))?;
let wasm: Callback<serde_cw_value::Value> = memo
.base
let wasm: ibc_apps_more::hook::Callback = memo
.wasm
.ok_or(StdError::generic_err("no wasm in memo".to_string()))?;
ensure!(
Expand Down
14 changes: 7 additions & 7 deletions crates/cvm-runtime/src/transport/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, StdResult};
use cvm_route::transport::RelativeTimeout;
use ibc_core_host_types::identifiers::{ChannelId, PortId};

use ibc_apps_more::types::hook::Callback;
//, HookMemo};
// use ibc_apps_more::types::memo::Memo;

/// This message should be send as part of wasm termination memo.
/// So that can match it to sender hash and know what channel and origin was used to send message.
Expand Down Expand Up @@ -71,14 +68,17 @@ pub fn to_cosmwasm_message<T>(
block: BlockInfo,
to_outpost: Addr,
) -> StdResult<CosmosMsg<T>> {
use ibc_apps_more::types::{hook::LazyHookMemo, memo::Memo};

// use ibc_apps_more::types::{hook::LazyHookMemo, memo::Memo};
use ibc_apps_more::{
hook::{Callback, SendMemo},
memo::Memo,
};
let msg = outpost::ExecuteMsg::MessageHook(XcMessageData {
from_network_id: route.from_network,
packet,
});
let memo = LazyHookMemo {
base: Memo {
let memo = SendMemo {
inner: Memo {
wasm: Some(Callback::new_cosmwasm(
to_outpost.clone(),
serde_cw_value::to_value(msg).expect("can always serde"),
Expand Down
31 changes: 22 additions & 9 deletions crates/cvm/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,28 @@ impl XcAddr {

#[cfg(feature = "cosmwasm")]
pub fn parse(&self) -> Result<Binary, StdError> {
use bech32::{primitives::decode::CheckedHrpstring, Bech32};
let addr = if let Ok(addr) = CheckedHrpstring::new::<Bech32>(&self.0) {
Binary(addr.byte_iter().collect())
} else if let Ok(addr) = Binary::from_base64(&self.0) {
addr
} else {
return Err(StdError::generic_err("Failed to ensure XcAddr encoding"));
};
Ok(addr)
if let Ok(addr) = Binary::from_base64(&self.0) {
return Ok(addr);
}
else if let Ok((_, addr, _)) = bech32::decode(&self.0) {
use bech32::FromBase32;
if let Ok(addr) = Vec::from_base32(&addr) {
return Ok(Binary(addr));
}
}

// here we will do CW on Substrate if that will be needed, but not prio
Err(StdError::generic_err("Failed to ensure XcAddr encoding"))

// use bech32::{primitives::decode::CheckedHrpstring, Bech32};
// let addr = if let Ok(addr) = CheckedHrpstring::new::<Bech32>(&self.0) {
// Binary(addr.byte_iter().collect())
// } else if let Ok(addr) = Binary::from_base64(&self.0) {
// addr
// } else {
// return Err(StdError::generic_err("Failed to ensure XcAddr encoding"));
// };
// Ok(addr)
}
}

Expand Down

0 comments on commit abbc927

Please sign in to comment.