Skip to content

Commit

Permalink
update channel finding logic
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Dec 18, 2024
1 parent 8696db6 commit a8ce167
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
7 changes: 2 additions & 5 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, MmError<WithdrawError>> {
todo!()
let id = self
.ibc_channels
.get(target_address.prefix())
.ok_or(WithdrawError::IBCChannelCouldNotFound(target_address.to_string()))?;

Ok(format!("channel-{id}"))
}

#[inline(always)]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/tendermint/tendermint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8ce167

Please sign in to comment.