use ibc_core_client_types::Height;
use ibc_core_commitment_types::commitment::CommitmentProofBytes;
use ibc_core_host_types::identifiers::{ChannelId, PortId};
use ibc_primitives::prelude::*;
use ibc_primitives::Signer;
use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm;
use ibc_proto::Protobuf;
use crate::error::ChannelError;
pub const CHAN_CLOSE_CONFIRM_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseConfirm";
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MsgChannelCloseConfirm {
pub port_id_on_b: PortId,
pub chan_id_on_b: ChannelId,
pub proof_chan_end_on_a: CommitmentProofBytes,
pub proof_height_on_a: Height,
pub signer: Signer,
}
impl Protobuf<RawMsgChannelCloseConfirm> for MsgChannelCloseConfirm {}
impl TryFrom<RawMsgChannelCloseConfirm> for MsgChannelCloseConfirm {
type Error = ChannelError;
fn try_from(raw_msg: RawMsgChannelCloseConfirm) -> Result<Self, Self::Error> {
if raw_msg.counterparty_upgrade_sequence != 0 {
return Err(ChannelError::UnsupportedChannelUpgradeSequence);
}
Ok(MsgChannelCloseConfirm {
port_id_on_b: raw_msg.port_id.parse()?,
chan_id_on_b: raw_msg.channel_id.parse()?,
proof_chan_end_on_a: raw_msg
.proof_init
.try_into()
.map_err(|_| ChannelError::InvalidProof)?,
proof_height_on_a: raw_msg
.proof_height
.and_then(|raw_height| raw_height.try_into().ok())
.ok_or(ChannelError::MissingHeight)?,
signer: raw_msg.signer.into(),
})
}
}
impl From<MsgChannelCloseConfirm> for RawMsgChannelCloseConfirm {
fn from(domain_msg: MsgChannelCloseConfirm) -> Self {
RawMsgChannelCloseConfirm {
port_id: domain_msg.port_id_on_b.to_string(),
channel_id: domain_msg.chan_id_on_b.to_string(),
proof_init: domain_msg.proof_chan_end_on_a.clone().into(),
proof_height: Some(domain_msg.proof_height_on_a.into()),
signer: domain_msg.signer.to_string(),
counterparty_upgrade_sequence: 0,
}
}
}