From db7828ebe96d08f4b467d3f13921119eb394dc53 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Tue, 4 Jul 2023 22:55:39 +0100 Subject: [PATCH] Use address to string if substrate or bech32 to string if not --- .../frame/pallet-multihop-xcm-ibc/src/lib.rs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/code/parachain/frame/pallet-multihop-xcm-ibc/src/lib.rs b/code/parachain/frame/pallet-multihop-xcm-ibc/src/lib.rs index 43187d0d8c8..e23772707ef 100644 --- a/code/parachain/frame/pallet-multihop-xcm-ibc/src/lib.rs +++ b/code/parachain/frame/pallet-multihop-xcm-ibc/src/lib.rs @@ -157,27 +157,32 @@ pub mod pallet { let mut last_memo_data: Option = None; for (i, name, address) in vec { - let mut forward = if i.is_substrate_ibc { // TODO is_substrate_ibc!!! + let mut forward = if i.is_substrate_xcm { // let str = "0x" + hex::encode(&bytes); let memo_receiver = scale_info::prelude::format!("0x{}", hex::encode(&address)); Forward::new_xcm_memo(memo_receiver, i.para_id) } else { - let result: core::result::Result, bech32_no_std::Error> = + let memo_receiver = if i.is_substrate_ibc{ + scale_info::prelude::format!("0x{}", hex::encode(&address)) + } + else{ + let result: core::result::Result, bech32_no_std::Error> = address.into_iter().map(bech32_no_std::u5::try_from_u8).collect(); - let data = - // result.map_err(|_| Error::::IncorrectAddress { chain_id: i.chain_id as u8 })?; - result.map_err(|_| DispatchError::Other("()"))?; - - let name = String::from_utf8(name.into()) - // .map_err(|_| Error::::IncorrectChainName { chain_id: i.chain_id as u8 - // })?; - .map_err(|_| DispatchError::Other("()"))?; - let memo_receiver = - bech32_no_std::encode(&name, data.clone()).map_err(|_| { - // Error::::FailedToEncodeBech32Address { chain_id: i.chain_id as u8 - // } - DispatchError::Other("()") - })?; + let data = + // result.map_err(|_| Error::::IncorrectAddress { chain_id: i.chain_id as u8 })?; + result.map_err(|_| DispatchError::Other("()"))?; + + let name = String::from_utf8(name.into()) + // .map_err(|_| Error::::IncorrectChainName { chain_id: i.chain_id as u8 + // })?; + .map_err(|_| DispatchError::Other("()"))?; + bech32_no_std::encode(&name, data.clone()).map_err(|_| { + // Error::::FailedToEncodeBech32Address { chain_id: i.chain_id as u8 + // } + DispatchError::Other("()") + })? + }; + Forward::new_ibc_memo( memo_receiver, String::from("transfer"),