Skip to content

imp(types): refactor Default implementations with concrete names #1099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4f68431
use concrete channel order enum
catconcat Feb 24, 2024
59df516
Merge branch 'main' into tuan/refactor-default
catconcat Feb 24, 2024
f194383
refactor(ics04): remove Version::default()
catconcat Feb 26, 2024
de47605
refactor(ics04): remove TimeoutHeight::default()
catconcat Feb 26, 2024
e384dca
refactor: remove channelId::default()
catconcat Feb 26, 2024
526acde
fix: Version::default() to Version::empty()
catconcat Feb 26, 2024
f4f0dae
remove derive default from Timestamp
catconcat Feb 26, 2024
000959e
refactor default builder
catconcat Feb 26, 2024
2cb0808
remove Sequence::default()
catconcat Feb 26, 2024
6a31d85
remove Memo::default()
catconcat Feb 26, 2024
bab6785
refactor: add ChannelId::zero()
catconcat Feb 29, 2024
332e9e6
Merge branch 'main' into tuan/refactor-default
catconcat Feb 29, 2024
e800ea8
add From<&str> implmentation
catconcat Feb 29, 2024
c957bd9
refactor(ibccore): remove ClientId::default()
catconcat Mar 8, 2024
36fba96
refactor(ibccore): remove version::Default()
catconcat Mar 8, 2024
48656b7
refactor(ibccore): remove ConnectionEnd::default()
catconcat Mar 8, 2024
f1c1f13
refactor(ibc-apps): remove TracePath::default()
catconcat Mar 8, 2024
436703f
refactor(ibc-core): remove ProofSpecs::default()
catconcat Mar 8, 2024
6d41e93
fix(ibc-app): remove upgrade path default
catconcat Mar 8, 2024
04ae141
remove trust threshold default
catconcat Mar 8, 2024
d0562e0
refactor(ibc-testkit): remove Default from client_state initialization
catconcat Mar 8, 2024
8aea66d
refactor(ibc-testkit): remove Default() of ClientId, ConnectionId,...
catconcat Mar 8, 2024
37ce288
chore: add unclog
catconcat Mar 9, 2024
3572e3b
Merge branch 'main' into tuan/refactor-default
catconcat Mar 9, 2024
cd2addd
refactor: add Connection::zero()
catconcat Mar 11, 2024
ec84de5
use into() instead of ::from()
catconcat Mar 11, 2024
7750afd
refactor: add Version::compatibles()
catconcat Mar 11, 2024
f279965
Merge branch 'tuan/refactor-default' of github.com:notional-labs/ibc-…
catconcat Mar 11, 2024
a860979
refactor(ics24-host): make 07-tendermint-0 a constant in tests
catconcat Mar 12, 2024
a206527
chore: remove commented out impl Default
catconcat Mar 12, 2024
596eccb
add dummy ClientId
catconcat Mar 12, 2024
6aba54f
refactor(ics24-host): remove From<&str> to avoid panic on host
catconcat Mar 12, 2024
9f4bd71
remove get_compatible_versions
catconcat Mar 12, 2024
91dedf1
fix syntax error when import Version
catconcat Mar 12, 2024
c7e86e8
chore: run cargo fmt
catconcat Mar 12, 2024
4fd5dca
revert markdown format
catconcat Mar 12, 2024
cd22fb2
Merge branch 'main' into tuan/refactor-default
catconcat Mar 12, 2024
fabc36c
Merge branch 'tuan/refactor-default' of github.com:notional-labs/ibc-…
catconcat Mar 12, 2024
fdf2a7c
various refactor
catconcat Mar 12, 2024
46910f3
chore: update unclog
catconcat Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ibc_app_nft_transfer_types::Memo;
use ibc_core::channel::context::{SendPacketExecutionContext, SendPacketValidationContext};
use ibc_core::channel::handler::{send_packet_execute, send_packet_validate};
use ibc_core::channel::types::packet::Packet;
Expand Down Expand Up @@ -81,14 +82,20 @@ where
&msg.chan_id_on_a,
class_id,
token_id,
&packet_data.memo.clone().unwrap_or_default(),
&packet_data
.memo
.clone()
.unwrap_or(Memo::from("".to_string())),
)?;
} else {
transfer_ctx.burn_nft_validate(
&sender,
class_id,
token_id,
&packet_data.memo.clone().unwrap_or_default(),
&packet_data
.memo
.clone()
.unwrap_or(Memo::from("".to_string())),
)?;
}
let nft = transfer_ctx.get_nft(class_id, token_id)?;
Expand Down Expand Up @@ -184,14 +191,20 @@ where
&msg.chan_id_on_a,
class_id,
token_id,
&packet_data.memo.clone().unwrap_or_default(),
&packet_data
.memo
.clone()
.unwrap_or(Memo::from("".to_string())),
)?;
} else {
transfer_ctx.burn_nft_execute(
&sender,
class_id,
token_id,
&packet_data.memo.clone().unwrap_or_default(),
&packet_data
.memo
.clone()
.unwrap_or(Memo::from("".to_string())),
)?;
}
let nft = transfer_ctx.get_nft(class_id, token_id)?;
Expand Down Expand Up @@ -242,7 +255,7 @@ where
receiver: packet_data.receiver,
class: packet_data.class_id,
tokens: packet_data.token_ids,
memo: packet_data.memo.unwrap_or_default(),
memo: packet_data.memo.unwrap_or(Memo::from("".to_string())),
};
send_packet_ctx_a.emit_ibc_event(ModuleEvent::from(transfer_event).into())?;

Expand Down
7 changes: 4 additions & 3 deletions ibc-apps/ics721-nft-transfer/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Provides IBC module callbacks implementation for the ICS-721 transfer.

use ibc_app_nft_transfer_types::Memo;
use ibc_core::channel::types::acknowledgement::{Acknowledgement, AcknowledgementStatus};
use ibc_core::channel::types::channel::{Counterparty, Order};
use ibc_core::channel::types::packet::Packet;
Expand Down Expand Up @@ -194,7 +195,7 @@ pub fn on_recv_packet_execute(
receiver: data.receiver,
class: data.class_id,
tokens: data.token_ids,
memo: data.memo.unwrap_or_default(),
memo: data.memo.unwrap_or(Memo::from("".to_string())),
success: ack.is_successful(),
};
extras.events.push(recv_event.into());
Expand Down Expand Up @@ -259,7 +260,7 @@ pub fn on_acknowledgement_packet_execute(
receiver: data.receiver,
class: data.class_id,
tokens: data.token_ids,
memo: data.memo.unwrap_or_default(),
memo: data.memo.unwrap_or(Memo::from("".to_string())),
acknowledgement: acknowledgement.clone(),
};

Expand Down Expand Up @@ -307,7 +308,7 @@ pub fn on_timeout_packet_execute(
refund_receiver: data.sender,
refund_class: data.class_id,
refund_tokens: data.token_ids,
memo: data.memo.unwrap_or_default(),
memo: data.memo.unwrap_or(Memo::from("".to_string())),
};

let extras = ModuleExtras {
Expand Down
2 changes: 1 addition & 1 deletion ibc-apps/ics721-nft-transfer/types/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ibc_core::primitives::prelude::*;
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Memo(String);

impl AsRef<str> for Memo {
Expand Down
3 changes: 1 addition & 2 deletions ibc-core/ics04-channel/types/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,9 @@ impl From<Counterparty> for RawCounterparty {
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Order {
None = 0isize,
#[default]
Unordered = 1isize,
Ordered = 2isize,
}
Expand Down
6 changes: 0 additions & 6 deletions ibc-core/ics04-channel/types/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ impl TimeoutHeight {
}
}

impl Default for TimeoutHeight {
fn default() -> Self {
Self::Never
}
}

impl TryFrom<RawHeight> for TimeoutHeight {
type Error = ClientError;

Expand Down
7 changes: 0 additions & 7 deletions ibc-core/ics04-channel/types/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ impl FromStr for Version {
}
}

/// The default version is empty (unspecified).
impl Default for Version {
fn default() -> Self {
Version::empty()
}
}

impl Display for Version {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
write!(f, "{}", self.0)
Expand Down
6 changes: 0 additions & 6 deletions ibc-core/ics24-host/types/src/identifiers/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ impl AsRef<str> for ChannelId {
}
}

impl Default for ChannelId {
fn default() -> Self {
Self::new(0)
}
}

/// Equality check against string literal (satisfies &ChannelId == &str).
/// ```
/// use core::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion ibc-core/ics24-host/types/src/identifiers/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::error::IdentifierError;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
/// The sequence number of a packet enforces ordering among packets from the same source.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Sequence(u64);

impl core::str::FromStr for Sequence {
Expand Down
44 changes: 22 additions & 22 deletions ibc-core/ics24-host/types/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,42 +1219,42 @@ mod tests {
#[case("ports/transfer", Path::Ports(PortPath(PortId::transfer())))]
#[case(
"channelEnds/ports/transfer/channels/channel-0",
Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::default()))
Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::new(0)))
)]
#[case(
"nextSequenceSend/ports/transfer/channels/channel-0",
Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::default()))
Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::new(0)))
)]
#[case(
"nextSequenceRecv/ports/transfer/channels/channel-0",
Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::default()))
Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::new(0)))
)]
#[case(
"nextSequenceAck/ports/transfer/channels/channel-0",
Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::default()))
Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::new(0)))
)]
#[case(
"commitments/ports/transfer/channels/channel-0/sequences/0",
Path::Commitment(CommitmentPath {
port_id: PortId::transfer(),
channel_id: ChannelId::default(),
sequence: Sequence::default(),
channel_id: ChannelId::new(0),
sequence: Sequence::from(0),
})
)]
#[case(
"acks/ports/transfer/channels/channel-0/sequences/0",
Path::Ack(AckPath {
port_id: PortId::transfer(),
channel_id: ChannelId::default(),
sequence: Sequence::default(),
channel_id: ChannelId::new(0),
sequence: Sequence::from(0),
})
)]
#[case(
"receipts/ports/transfer/channels/channel-0/sequences/0",
Path::Receipt(ReceiptPath {
port_id: PortId::transfer(),
channel_id: ChannelId::default(),
sequence: Sequence::default(),
channel_id: ChannelId::new(0),
sequence: Sequence::from(0),
})
)]
#[case(
Expand Down Expand Up @@ -1360,7 +1360,7 @@ mod tests {

assert_eq!(
parse_channels(&components),
Some(SubPath::Channels(ChannelId::default())),
Some(SubPath::Channels(ChannelId::new(0))),
);
}

Expand All @@ -1371,7 +1371,7 @@ mod tests {

assert_eq!(
parse_sequences(&components),
Some(SubPath::Sequences(Sequence::default()))
Some(SubPath::Sequences(Sequence::from(0)))
);
}

Expand All @@ -1384,7 +1384,7 @@ mod tests {
parse_channel_ends(&components),
Some(Path::ChannelEnd(ChannelEndPath(
PortId::transfer(),
ChannelId::default()
ChannelId::new(0)
))),
);
}
Expand All @@ -1398,7 +1398,7 @@ mod tests {
parse_seqs(&components),
Some(Path::SeqSend(SeqSendPath(
PortId::transfer(),
ChannelId::default()
ChannelId::new(0)
))),
);

Expand All @@ -1409,7 +1409,7 @@ mod tests {
parse_seqs(&components),
Some(Path::SeqRecv(SeqRecvPath(
PortId::transfer(),
ChannelId::default()
ChannelId::new(0)
))),
);

Expand All @@ -1420,7 +1420,7 @@ mod tests {
parse_seqs(&components),
Some(Path::SeqAck(SeqAckPath(
PortId::transfer(),
ChannelId::default()
ChannelId::new(0)
))),
);
}
Expand All @@ -1434,8 +1434,8 @@ mod tests {
parse_commitments(&components),
Some(Path::Commitment(CommitmentPath {
port_id: PortId::transfer(),
channel_id: ChannelId::default(),
sequence: Sequence::default(),
channel_id: ChannelId::new(0),
sequence: Sequence::from(0),
})),
);
}
Expand All @@ -1449,8 +1449,8 @@ mod tests {
parse_acks(&components),
Some(Path::Ack(AckPath {
port_id: PortId::transfer(),
channel_id: ChannelId::default(),
sequence: Sequence::default(),
channel_id: ChannelId::new(0),
sequence: Sequence::from(0),
})),
);
}
Expand All @@ -1464,8 +1464,8 @@ mod tests {
parse_receipts(&components),
Some(Path::Receipt(ReceiptPath {
port_id: PortId::transfer(),
channel_id: ChannelId::default(),
sequence: Sequence::default(),
channel_id: ChannelId::new(0),
sequence: Sequence::from(0),
})),
);
}
Expand Down
4 changes: 2 additions & 2 deletions ibc-primitives/src/types/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0);
/// of timestamp.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, PartialOrd, Ord, Hash)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, PartialOrd, Ord, Hash)]
pub struct Timestamp {
// Note: The schema representation is the timestamp in nanoseconds (as we do with borsh).
#[cfg_attr(feature = "schema", schemars(with = "u64"))]
Expand Down Expand Up @@ -170,7 +170,7 @@ impl Timestamp {
/// let ti = Timestamp::from_nanoseconds(min).unwrap();
/// let uti = ti.nanoseconds();
/// assert_eq!(uti, min);
/// let tz = Timestamp::default();
/// let tz = Timestamp::none();
/// let utz = tz.nanoseconds();
/// assert_eq!(utz, 0);
/// ```
Expand Down
8 changes: 4 additions & 4 deletions ibc-testkit/src/fixtures/applications/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use crate::fixtures::core::signer::dummy_account_id;
pub struct MsgTransferConfig {
#[builder(default = PortId::transfer())]
pub port_id_on_a: PortId,
#[builder(default)]
#[builder(default = ChannelId::new(0))]
pub chan_id_on_a: ChannelId,
pub packet_data: PacketData,
#[builder(default)]
#[builder(default = TimeoutHeight::Never)]
pub timeout_height_on_b: TimeoutHeight,
#[builder(default)]
#[builder(default = Timestamp::none())]
pub timeout_timestamp_on_b: Timestamp,
}

Expand All @@ -47,7 +47,7 @@ pub fn extract_transfer_packet(msg: &MsgTransfer, sequence: Sequence) -> Packet
port_id_on_a: msg.port_id_on_a.clone(),
chan_id_on_a: msg.chan_id_on_a.clone(),
port_id_on_b: PortId::transfer(),
chan_id_on_b: ChannelId::default(),
chan_id_on_b: ChannelId::new(0),
data,
timeout_height_on_b: msg.timeout_height_on_b,
timeout_timestamp_on_b: msg.timeout_timestamp_on_b,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account;
pub fn dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelCloseConfirm {
RawMsgChannelCloseConfirm {
port_id: PortId::transfer().to_string(),
channel_id: ChannelId::default().to_string(),
channel_id: ChannelId::new(0).to_string(),
proof_init: dummy_proof(),
proof_height: Some(Height {
revision_number: 0,
Expand Down
2 changes: 1 addition & 1 deletion ibc-testkit/src/fixtures/core/channel/chan_close_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::fixtures::core::signer::dummy_bech32_account;
pub fn dummy_raw_msg_chan_close_init() -> RawMsgChannelCloseInit {
RawMsgChannelCloseInit {
port_id: PortId::transfer().to_string(),
channel_id: ChannelId::default().to_string(),
channel_id: ChannelId::new(0).to_string(),
signer: dummy_bech32_account(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::fixtures::core::signer::dummy_bech32_account;
pub fn dummy_raw_msg_chan_open_ack(proof_height: u64) -> RawMsgChannelOpenAck {
RawMsgChannelOpenAck {
port_id: PortId::transfer().to_string(),
channel_id: ChannelId::default().to_string(),
counterparty_channel_id: ChannelId::default().to_string(),
channel_id: ChannelId::new(0).to_string(),
counterparty_channel_id: ChannelId::new(0).to_string(),
counterparty_version: "".to_string(),
proof_try: dummy_proof(),
proof_height: Some(Height {
Expand Down
2 changes: 1 addition & 1 deletion ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account;
pub fn dummy_raw_msg_chan_open_confirm(proof_height: u64) -> RawMsgChannelOpenConfirm {
RawMsgChannelOpenConfirm {
port_id: PortId::transfer().to_string(),
channel_id: ChannelId::default().to_string(),
channel_id: ChannelId::new(0).to_string(),
proof_ack: dummy_proof(),
proof_height: Some(Height {
revision_number: 0,
Expand Down
Loading