Skip to content

Commit

Permalink
Remove Infallible and implement Into for Height directly
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen committed Jun 11, 2021
1 parent 1fbe10e commit 6b397f1
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 43 deletions.
12 changes: 5 additions & 7 deletions modules/src/ics02_client/height.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cmp::Ordering;
use std::convert::{Infallible, TryFrom};
use std::convert::TryFrom;
use std::str::FromStr;

use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -101,14 +101,12 @@ impl Ord for Height {

impl Protobuf<RawHeight> for Height {}

impl TryFrom<RawHeight> for Height {
type Error = Infallible;

fn try_from(raw: RawHeight) -> Result<Self, Self::Error> {
Ok(Height {
impl From<RawHeight> for Height {
fn from(raw: RawHeight) -> Self {
Height {
revision_number: raw.revision_number,
revision_height: raw.revision_height,
})
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions modules/src/ics03_connection/msgs/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@ impl TryFrom<RawMsgConnectionOpenAck> for MsgConnectionOpenAck {
let consensus_height = msg
.consensus_height
.ok_or_else(error::missing_consensus_height_error)?
.try_into() // Cast from the raw height type into the domain type.
.map_err(|e| match e {})?;
.into();
let consensus_proof_obj = ConsensusProof::new(msg.proof_consensus.into(), consensus_height)
.map_err(error::invalid_proof_error)?;

let proof_height = msg
.proof_height
.ok_or_else(error::missing_proof_height_error)?
.try_into()
.map_err(|e| match e {})?;
.into();

let client_proof = Some(msg.proof_client)
.filter(|x| !x.is_empty())
Expand Down
6 changes: 3 additions & 3 deletions modules/src/ics03_connection/msgs/conn_open_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;

use tendermint_proto::Protobuf;

Expand Down Expand Up @@ -56,8 +56,8 @@ impl TryFrom<RawMsgConnectionOpenConfirm> for MsgConnectionOpenConfirm {
let proof_height = msg
.proof_height
.ok_or_else(error::missing_proof_height_error)?
.try_into() // Cast from the raw height type into the domain type.
.map_err(|e| match e {})?;
.into();

Ok(Self {
connection_id: msg
.connection_id
Expand Down
6 changes: 2 additions & 4 deletions modules/src/ics03_connection/msgs/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,15 @@ impl TryFrom<RawMsgConnectionOpenTry> for MsgConnectionOpenTry {
let consensus_height = msg
.consensus_height
.ok_or_else(error::missing_consensus_height_error)?
.try_into() // Cast from the raw height type into the domain type.
.map_err(|e| match e {})?;
.into();

let consensus_proof_obj = ConsensusProof::new(msg.proof_consensus.into(), consensus_height)
.map_err(error::invalid_proof_error)?;

let proof_height = msg
.proof_height
.ok_or_else(error::missing_proof_height_error)?
.try_into()
.map_err(|e| match e {})?;
.into();

let client_proof = Some(msg.proof_client)
.filter(|x| !x.is_empty())
Expand Down
3 changes: 1 addition & 2 deletions modules/src/ics04_channel/msgs/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl TryFrom<RawMsgAcknowledgement> for MsgAcknowledgement {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
5 changes: 2 additions & 3 deletions modules/src/ics04_channel/msgs/chan_close_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;

use tendermint_proto::Protobuf;

Expand Down Expand Up @@ -73,8 +73,7 @@ impl TryFrom<RawMsgChannelCloseConfirm> for MsgChannelCloseConfirm {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
5 changes: 2 additions & 3 deletions modules/src/ics04_channel/msgs/chan_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::tx_msg::Msg;
use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck;
use tendermint_proto::Protobuf;

use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;

pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck";

Expand Down Expand Up @@ -92,8 +92,7 @@ impl TryFrom<RawMsgChannelOpenAck> for MsgChannelOpenAck {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
5 changes: 2 additions & 3 deletions modules/src/ics04_channel/msgs/chan_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::tx_msg::Msg;
use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm;
use tendermint_proto::Protobuf;

use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;

pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm";

Expand Down Expand Up @@ -74,8 +74,7 @@ impl TryFrom<RawMsgChannelOpenConfirm> for MsgChannelOpenConfirm {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
3 changes: 1 addition & 2 deletions modules/src/ics04_channel/msgs/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ impl TryFrom<RawMsgChannelOpenTry> for MsgChannelOpenTry {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
3 changes: 1 addition & 2 deletions modules/src/ics04_channel/msgs/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ impl TryFrom<RawMsgRecvPacket> for MsgRecvPacket {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
3 changes: 1 addition & 2 deletions modules/src/ics04_channel/msgs/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl TryFrom<RawMsgTimeout> for MsgTimeout {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
3 changes: 1 addition & 2 deletions modules/src/ics04_channel/msgs/timeout_on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl TryFrom<RawMsgTimeoutOnClose> for MsgTimeoutOnClose {
raw_msg
.proof_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),
)
.map_err(error::invalid_proof_error)?;

Expand Down
5 changes: 2 additions & 3 deletions modules/src/ics04_channel/packet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;
use std::str::FromStr;

use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -172,8 +172,7 @@ impl TryFrom<RawPacket> for Packet {
let packet_timeout_height: Height = raw_pkt
.timeout_height
.ok_or_else(error::missing_height_error)?
.try_into()
.map_err(|e| match e {})?;
.into();

if packet_timeout_height.is_zero() && raw_pkt.timeout_timestamp == 0 {
return Err(error::zero_packet_timeout_error());
Expand Down
5 changes: 2 additions & 3 deletions modules/src/mock/header.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;

use serde_derive::{Deserialize, Serialize};
use tendermint_proto::Protobuf;
Expand Down Expand Up @@ -30,8 +30,7 @@ impl TryFrom<RawMockHeader> for MockHeader {
height: raw
.height
.ok_or_else(error::missing_raw_header_error)?
.try_into()
.map_err(|e| match e {})?,
.into(),

timestamp: Timestamp::from_nanoseconds(raw.timestamp)
.map_err(error::invalid_packet_timestamp_error)?,
Expand Down

0 comments on commit 6b397f1

Please sign in to comment.