From a8ce1677b9b6079754c22209548cac1f2e7a8657 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 18 Dec 2024 06:17:11 +0000 Subject: [PATCH] update channel finding logic Signed-off-by: onur-ozkan --- mm2src/coins/lp_coins.rs | 7 ++----- mm2src/coins/tendermint/tendermint_coin.rs | 17 ++++++++++------- mm2src/coins/tendermint/tendermint_token.rs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 16ade17a6b..7a4bd0c35c 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -3016,12 +3016,10 @@ pub enum WithdrawError { }, #[display(fmt = "Signing error {}", _0)] SigningError(String), - #[display(fmt = "Eth transaction type not supported")] + #[display(fmt = "Transaction type not supported")] TxTypeNotSupported, - #[display(fmt = "'chain_registry_name' was not found in coins configuration for '{}'", _0)] - RegistryNameIsMissing(String), #[display( - fmt = "IBC channel could not found for '{}' address. Consider providing it manually with 'ibc_source_channel' in the request.", + fmt = "IBC channel could not found for '{}' address. Provide it manually by including `ibc_source_channel` in the request. See https://ibc.iobscan.io/channels for reference.", _0 )] IBCChannelCouldNotFound(String), @@ -3053,7 +3051,6 @@ impl HttpStatusCode for WithdrawError { | WithdrawError::NoChainIdSet { .. } | WithdrawError::TxTypeNotSupported | WithdrawError::SigningError(_) - | WithdrawError::RegistryNameIsMissing(_) | WithdrawError::IBCChannelCouldNotFound(_) | WithdrawError::MyAddressNotNftOwner { .. } => StatusCode::BAD_REQUEST, WithdrawError::HwError(_) => StatusCode::GONE, diff --git a/mm2src/coins/tendermint/tendermint_coin.rs b/mm2src/coins/tendermint/tendermint_coin.rs index 80ee6c3d5d..1f82ad9f64 100644 --- a/mm2src/coins/tendermint/tendermint_coin.rs +++ b/mm2src/coins/tendermint/tendermint_coin.rs @@ -3,10 +3,9 @@ use super::htlc::{ClaimHtlcMsg, ClaimHtlcProto, CreateHtlcMsg, CreateHtlcProto, QueryHtlcResponse, TendermintHtlc, HTLC_STATE_COMPLETED, HTLC_STATE_OPEN, HTLC_STATE_REFUNDED}; use super::ibc::transfer_v1::MsgTransfer; use super::ibc::IBC_GAS_LIMIT_DEFAULT; -use super::{rpc::*, TENDERMINT_COIN_PROTOCOL_TYPE}; +use super::rpc::*; use crate::coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentResult}; use crate::hd_wallet::{HDPathAccountToAddressId, WithdrawFrom}; -use crate::tendermint::ibc::IBC_OUT_SOURCE_PORT; use crate::utxo::sat_from_big_decimal; use crate::utxo::utxo_common::big_decimal_from_sat; use crate::{big_decimal_from_sat_unsigned, BalanceError, BalanceFut, BigDecimal, CheckIfMyPaymentSentArgs, @@ -703,12 +702,16 @@ impl TendermintCoin { }))) } - /// TODO - pub(crate) async fn detect_channel_id_for_ibc_transfer( + pub(crate) async fn get_ibc_channel_for_target_address( &self, - to_address: &AccountId, + target_address: &AccountId, ) -> Result> { - todo!() + let id = self + .ibc_channels + .get(target_address.prefix()) + .ok_or(WithdrawError::IBCChannelCouldNotFound(target_address.to_string()))?; + + Ok(format!("channel-{id}")) } #[inline(always)] @@ -2148,7 +2151,7 @@ impl MmCoin for TendermintCoin { let channel_id = if is_ibc_transfer { match &req.ibc_source_channel { Some(_) => req.ibc_source_channel, - None => Some(coin.detect_channel_id_for_ibc_transfer(&to_address).await?), + None => Some(coin.get_ibc_channel_for_target_address(&to_address).await?), } } else { None diff --git a/mm2src/coins/tendermint/tendermint_token.rs b/mm2src/coins/tendermint/tendermint_token.rs index e5cc90f895..3e564cdf49 100644 --- a/mm2src/coins/tendermint/tendermint_token.rs +++ b/mm2src/coins/tendermint/tendermint_token.rs @@ -559,7 +559,7 @@ impl MmCoin for TendermintToken { let channel_id = if is_ibc_transfer { match &req.ibc_source_channel { Some(_) => req.ibc_source_channel, - None => Some(platform.detect_channel_id_for_ibc_transfer(&to_address).await?), + None => Some(platform.get_ibc_channel_for_target_address(&to_address).await?), } } else { None