Skip to content

Commit

Permalink
Make necessary changes in ics25 dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Sep 17, 2024
1 parent bc9fe71 commit 4d22bfe
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 124 deletions.
13 changes: 3 additions & 10 deletions ibc-apps/ics20-transfer/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ibc_core::channel::types::acknowledgement::{Acknowledgement, Acknowledgement
use ibc_core::channel::types::channel::{Counterparty, Order};
use ibc_core::channel::types::packet::Packet;
use ibc_core::channel::types::Version;
use ibc_core::handler::types::error::HandlerError;
use ibc_core::host::types::error::DecodingError;
use ibc_core::host::types::identifiers::{ChannelId, ConnectionId, PortId};
use ibc_core::primitives::prelude::*;
Expand Down Expand Up @@ -42,9 +41,7 @@ pub fn on_chan_open_init_validate(
}

if !version.is_empty() {
version
.verify_is_expected(Version::new(VERSION.to_string()))
.map_err(HandlerError::from)?;
version.verify_is_expected(Version::new(VERSION.to_string()))?;
}

Ok(())
Expand Down Expand Up @@ -78,9 +75,7 @@ pub fn on_chan_open_try_validate(
});
}

counterparty_version
.verify_is_expected(Version::new(VERSION.to_string()))
.map_err(HandlerError::from)?;
counterparty_version.verify_is_expected(Version::new(VERSION.to_string()))?;

Ok(())
}
Expand All @@ -103,9 +98,7 @@ pub fn on_chan_open_ack_validate(
_channel_id: &ChannelId,
counterparty_version: &Version,
) -> Result<(), TokenTransferError> {
counterparty_version
.verify_is_expected(Version::new(VERSION.to_string()))
.map_err(HandlerError::from)?;
counterparty_version.verify_is_expected(Version::new(VERSION.to_string()))?;

Ok(())
}
Expand Down
23 changes: 13 additions & 10 deletions ibc-apps/ics20-transfer/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
use displaydoc::Display;
use ibc_core::channel::types::acknowledgement::StatusValue;
use ibc_core::channel::types::channel::Order;
use ibc_core::handler::types::error::HandlerError;
use ibc_core::channel::types::error::ChannelError;
use ibc_core::host::types::error::{DecodingError, HostError};
use ibc_core::host::types::identifiers::{ChannelId, PortId};
use ibc_core::primitives::prelude::*;

#[derive(Display, Debug)]
pub enum TokenTransferError {
/// host error: `{0}`
Handler(HandlerError),
Host(HostError),
/// decoding error: `{0}`
Decoding(DecodingError),
/// channel error: `{0}`
Channel(ChannelError),
/// missing destination channel `{channel_id}` on port `{port_id}`
MissingDestinationChannel {
port_id: PortId,
Expand All @@ -36,22 +38,17 @@ pub enum TokenTransferError {
impl std::error::Error for TokenTransferError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
Self::Handler(e) => Some(e),
Self::Host(e) => Some(e),
Self::Decoding(e) => Some(e),
Self::Channel(e) => Some(e),
_ => None,
}
}
}

impl From<HandlerError> for TokenTransferError {
fn from(e: HandlerError) -> Self {
Self::Handler(e)
}
}

impl From<HostError> for TokenTransferError {
fn from(e: HostError) -> Self {
Self::Handler(HandlerError::Host(e))
Self::Host(e)
}
}

Expand All @@ -61,6 +58,12 @@ impl From<DecodingError> for TokenTransferError {
}
}

impl From<ChannelError> for TokenTransferError {
fn from(e: ChannelError) -> Self {
Self::Channel(e)
}
}

impl From<TokenTransferError> for StatusValue {
fn from(e: TokenTransferError) -> Self {
StatusValue::new(e.to_string()).expect("error message must not be empty")
Expand Down
14 changes: 3 additions & 11 deletions ibc-apps/ics721-nft-transfer/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use ibc_core::channel::types::acknowledgement::{Acknowledgement, Acknowledgement
use ibc_core::channel::types::channel::{Counterparty, Order};
use ibc_core::channel::types::packet::Packet;
use ibc_core::channel::types::Version;
use ibc_core::handler::types::error::HandlerError;
use ibc_core::host::types::identifiers::{ChannelId, ConnectionId, PortId};
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::Signer;
Expand Down Expand Up @@ -42,9 +41,7 @@ pub fn on_chan_open_init_validate(
}

if !version.is_empty() {
version
.verify_is_expected(Version::new(VERSION.to_string()))
.map_err(HandlerError::from)?;
version.verify_is_expected(Version::new(VERSION.to_string()))?;
}

Ok(())
Expand Down Expand Up @@ -78,9 +75,7 @@ pub fn on_chan_open_try_validate(
});
}

counterparty_version
.verify_is_expected(Version::new(VERSION.to_string()))
.map_err(HandlerError::from)?;
counterparty_version.verify_is_expected(Version::new(VERSION.to_string()))?;

Ok(())
}
Expand All @@ -103,10 +98,7 @@ pub fn on_chan_open_ack_validate(
_channel_id: &ChannelId,
counterparty_version: &Version,
) -> Result<(), NftTransferError> {
counterparty_version
.verify_is_expected(Version::new(VERSION.to_string()))
.map_err(HandlerError::from)?;

counterparty_version.verify_is_expected(Version::new(VERSION.to_string()))?;
Ok(())
}

Expand Down
17 changes: 7 additions & 10 deletions ibc-apps/ics721-nft-transfer/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ use derive_more::From;
use displaydoc::Display;
use ibc_core::channel::types::acknowledgement::StatusValue;
use ibc_core::channel::types::channel::Order;
use ibc_core::handler::types::error::HandlerError;
use ibc_core::channel::types::error::ChannelError;
use ibc_core::host::types::error::{DecodingError, HostError};
use ibc_core::host::types::identifiers::{ChannelId, PortId};
use ibc_core::primitives::prelude::*;

#[derive(Display, Debug, From)]
pub enum NftTransferError {
/// handler error: `{0}`
Handler(HandlerError),
/// host error: `{0}`
Host(HostError),
/// channel error: `{0}`
Channel(ChannelError),
/// decoding error: `{0}`
Decoding(DecodingError),
/// missing destination channel `{channel_id}` on port `{port_id}`
Expand Down Expand Up @@ -41,19 +43,14 @@ pub enum NftTransferError {
impl std::error::Error for NftTransferError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
Self::Handler(e) => Some(e),
Self::Channel(e) => Some(e),
Self::Host(e) => Some(e),
Self::Decoding(e) => Some(e),
_ => None,
}
}
}

impl From<HostError> for NftTransferError {
fn from(e: HostError) -> Self {
Self::Handler(HandlerError::Host(e))
}
}

impl From<NftTransferError> for StatusValue {
fn from(err: NftTransferError) -> Self {
StatusValue::new(err.to_string()).expect("error message must not be empty")
Expand Down
Loading

0 comments on commit 4d22bfe

Please sign in to comment.