Skip to content

Commit 6be7e20

Browse files
plaferFarhad-ShabaniDaviRain-Su
authored
Properly define and document our public interface (#656)
* some docstrings updated * Remove dynamic_typing module * move some utils to tendermint client * Make `crate::utils` private * docs * Remove unused struct * move events under core * move timestamp under core * Move tx_msg under core * Make naming convention comment not module-level * Make core::handler private * Re-export all core::context * make tx_msg private and re-export Msg * core module docs * many docs improvements * Release v0.39.0 (#657) * unclog release * bump version * Correct issue 621 description --------- Co-authored-by: Farhad Shabani <[email protected]> * fix doc test * `Validation/ExecutionContext` method docs * more docs improvements * remove unused function * client docs improvements * move trust_threshold to tendermint * connection * finish ics-20 docs * finish docs for the tendermint light client * core docs * move `ModuleExtras` out of channel * Make all `TYPE_URL` private * Move `Acknowledgement ` * remove superfluous channel message modules * finish channel docs * Remove `ics05_port` module * ValidationError -> IdentifierError * remove error module * cleanup ics24_host path * move host validate module under identifier * move RouterError * move msgs under core * remove tx_msg * router module * remove arbitrary restrictions on `ModuleId` * router * finish ics23 * mock * fmt * Add serialization for various structs and enums (#653) * Add serialization for various structs and enums * Create 652-codec-borsh-serde.md --------- Signed-off-by: Davirain <[email protected]> * changelog * remove `ClientTypePath` --------- Signed-off-by: Davirain <[email protected]> Co-authored-by: Farhad Shabani <[email protected]> Co-authored-by: Davirain <[email protected]>
1 parent 75c84c0 commit 6be7e20

File tree

131 files changed

+876
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+876
-892
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Reduce and consolidate the amount of public modules exposed
2+
([#235](https://github.com/cosmos/ibc-rs/issues/235))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Make `TYPE_URL`s private ([#597](https://github.com/cosmos/ibc-rs/issues/597))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Document every method of `ValidationContext` and `ExecutionContext`
2+
([#376](https://github.com/cosmos/ibc-rs/issues/376))

crates/ibc/src/applications/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Various packet encoding semantics which underpin the various types of transactions.
1+
//! Implementation of IBC applications
22
33
#[cfg(feature = "serde")]
44
pub mod transfer;

crates/ibc/src/applications/transfer/acknowledgement.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
//! Defines types used in token transfer acknowledgements
2+
13
use core::fmt::{Display, Error as FmtError, Formatter};
24

35
use super::error::TokenTransferError;
4-
use crate::core::ics04_channel::msgs::acknowledgement::Acknowledgement;
5-
use crate::prelude::*;
6+
use crate::{core::ics04_channel::packet::Acknowledgement, prelude::*};
67

78
/// A string constant included in error acknowledgements.
89
/// NOTE: Changing this const is state machine breaking as acknowledgements are written into state

crates/ibc/src/applications/transfer/amount.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Contains the `Amount` type, which represents amounts of tokens transferred.
2+
13
use core::str::FromStr;
24
use derive_more::{Display, From, Into};
35

crates/ibc/src/applications/transfer/coin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Defines coin types; the objects that are being transferred.
2+
13
use core::fmt::{Display, Error as FmtError, Formatter};
24
use core::str::{from_utf8, FromStr};
35
use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin;

crates/ibc/src/applications/transfer/context.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Defines the main context traits and IBC module callbacks
2+
3+
use crate::core::router::ModuleExtras;
14
use crate::core::ContextError;
25
use crate::prelude::*;
36

@@ -16,13 +19,12 @@ use crate::core::ics04_channel::channel::{Counterparty, Order};
1619
use crate::core::ics04_channel::context::{
1720
SendPacketExecutionContext, SendPacketValidationContext,
1821
};
19-
use crate::core::ics04_channel::handler::ModuleExtras;
20-
use crate::core::ics04_channel::msgs::acknowledgement::Acknowledgement;
21-
use crate::core::ics04_channel::packet::Packet;
22+
use crate::core::ics04_channel::packet::{Acknowledgement, Packet};
2223
use crate::core::ics04_channel::Version;
2324
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};
2425
use crate::signer::Signer;
2526

27+
/// Methods required in token transfer validation, to be implemented by the host
2628
pub trait TokenTransferValidationContext: SendPacketValidationContext {
2729
type AccountId: TryFrom<Signer>;
2830

@@ -71,6 +73,7 @@ pub trait TokenTransferValidationContext: SendPacketValidationContext {
7173
}
7274
}
7375

76+
/// Methods required in token transfer execution, to be implemented by the host
7477
pub trait TokenTransferExecutionContext:
7578
TokenTransferValidationContext + SendPacketExecutionContext
7679
{

crates/ibc/src/applications/transfer/denom.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Defines types to represent "denominations" [as defined in ICS-20](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md#data-structures)
2+
13
use core::fmt::{Display, Error as FmtError, Formatter};
24
use core::str::FromStr;
35

@@ -11,7 +13,10 @@ use crate::prelude::*;
1113
#[cfg(feature = "serde")]
1214
use crate::serializers::serde_string;
1315

14-
/// Base denomination type
16+
/// The "base" of a denomination.
17+
///
18+
/// For example, given the token `my_port-1/my_channel-1/my_port-2/my_channel-2/base_denom`,
19+
/// `base_denom` is the "base" of the denomination
1520
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1621
#[cfg_attr(feature = "serde", serde(transparent))]
1722
#[cfg_attr(
@@ -43,6 +48,11 @@ impl FromStr for BaseDenom {
4348
}
4449
}
4550

51+
/// One hop in a token's trace, which consists of the port and channel IDs of the sender
52+
///
53+
/// For example, given the token `my_port-1/my_channel-1/my_port-2/my_channel-2/base_denom`,
54+
/// `my_port-1/my_channel-1` is a trace prefix, and `my_port-2/my_channel-2` is another one.
55+
/// See [TracePath] which stitches trace prefixes together.
4656
#[cfg_attr(
4757
feature = "parity-scale-codec",
4858
derive(

crates/ibc/src/applications/transfer/error.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
//! Defines the token transfer error type
2+
13
use core::convert::Infallible;
24
use core::str::Utf8Error;
35
use displaydoc::Display;
46
use ibc_proto::protobuf::Error as TendermintProtoError;
57
use uint::FromDecStrErr;
68

79
use crate::core::ics04_channel::channel::Order;
8-
use crate::core::ics24_host::error::ValidationError;
9-
use crate::core::ics24_host::identifier::{ChannelId, PortId};
10+
use crate::core::ics24_host::identifier::{ChannelId, IdentifierError, PortId};
1011
use crate::core::ContextError;
1112
use crate::prelude::*;
1213

@@ -15,7 +16,7 @@ pub enum TokenTransferError {
1516
/// context error: `{0}`
1617
ContextError(ContextError),
1718
/// invalid identifier: `{0}`
18-
InvalidIdentifier(ValidationError),
19+
InvalidIdentifier(IdentifierError),
1920
/// destination channel not found in the counterparty of port_id `{port_id}` and channel_id `{channel_id}`
2021
DestinationChannelNotFound {
2122
port_id: PortId,
@@ -26,12 +27,12 @@ pub enum TokenTransferError {
2627
/// invalid prot id n trace at position: `{pos}`, validation error: `{validation_error}`
2728
InvalidTracePortId {
2829
pos: usize,
29-
validation_error: ValidationError,
30+
validation_error: IdentifierError,
3031
},
3132
/// invalid channel id in trace at position: `{pos}`, validation error: `{validation_error}`
3233
InvalidTraceChannelId {
3334
pos: usize,
34-
validation_error: ValidationError,
35+
validation_error: IdentifierError,
3536
},
3637
/// trace length must be even but got: `{len}`
3738
InvalidTraceLength { len: usize },
@@ -105,8 +106,8 @@ impl From<ContextError> for TokenTransferError {
105106
}
106107
}
107108

108-
impl From<ValidationError> for TokenTransferError {
109-
fn from(err: ValidationError) -> TokenTransferError {
109+
impl From<IdentifierError> for TokenTransferError {
110+
fn from(err: IdentifierError) -> TokenTransferError {
110111
Self::InvalidIdentifier(err)
111112
}
112113
}

crates/ibc/src/applications/transfer/events.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
//! Defines all token transfer event types
2+
13
use crate::applications::transfer::acknowledgement::TokenTransferAcknowledgement;
2-
use crate::applications::transfer::{Amount, Memo, PrefixedDenom, MODULE_ID_STR};
3-
use crate::events::ModuleEvent;
4+
use crate::applications::transfer::{Amount, PrefixedDenom, MODULE_ID_STR};
5+
use crate::core::events::ModuleEvent;
46
use crate::prelude::*;
57
use crate::signer::Signer;
68

9+
use super::Memo;
10+
711
const EVENT_TYPE_PACKET: &str = "fungible_token_packet";
812
const EVENT_TYPE_TIMEOUT: &str = "timeout";
913
const EVENT_TYPE_DENOM_TRACE: &str = "denomination_trace";
1014
const EVENT_TYPE_TRANSFER: &str = "ibc_transfer";
1115

16+
/// Contains all events variants that can be emitted from the token transfer application
1217
pub enum Event {
1318
Recv(RecvEvent),
1419
Ack(AckEvent),
@@ -18,6 +23,8 @@ pub enum Event {
1823
Transfer(TransferEvent),
1924
}
2025

26+
/// Event emitted in the [`onRecvPacket`][super::context::on_recv_packet_execute]
27+
/// module callback to indicate the that the `RecvPacket` message was processed
2128
pub struct RecvEvent {
2229
pub sender: Signer,
2330
pub receiver: Signer,
@@ -52,6 +59,8 @@ impl From<RecvEvent> for ModuleEvent {
5259
}
5360
}
5461

62+
/// Event emitted in the [`onAcknowledgePacket`][super::context::on_acknowledgement_packet_execute]
63+
/// module callback
5564
pub struct AckEvent {
5665
pub sender: Signer,
5766
pub receiver: Signer,
@@ -86,6 +95,8 @@ impl From<AckEvent> for ModuleEvent {
8695
}
8796
}
8897

98+
/// Event emitted in the [`onAcknowledgePacket`][super::context::on_acknowledgement_packet_execute]
99+
/// module callback to indicate whether the acknowledgement is a success or a failure
89100
pub struct AckStatusEvent {
90101
pub acknowledgement: TokenTransferAcknowledgement,
91102
}
@@ -105,6 +116,8 @@ impl From<AckStatusEvent> for ModuleEvent {
105116
}
106117
}
107118

119+
/// Event emitted in the [`onTimeoutPacket`][super::context::on_timeout_packet_execute]
120+
/// module callback
108121
pub struct TimeoutEvent {
109122
pub refund_receiver: Signer,
110123
pub refund_denom: PrefixedDenom,
@@ -133,6 +146,8 @@ impl From<TimeoutEvent> for ModuleEvent {
133146
}
134147
}
135148

149+
/// Event emitted in the [`onRecvPacket`][super::context::on_recv_packet_execute]
150+
/// module callback when new tokens are minted
136151
pub struct DenomTraceEvent {
137152
pub trace_hash: Option<String>,
138153
pub denom: PrefixedDenom,
@@ -152,6 +167,8 @@ impl From<DenomTraceEvent> for ModuleEvent {
152167
}
153168
}
154169

170+
/// Event emitted in [`sendTransfer`][super::send_transfer] after a successful
171+
/// transfer
155172
pub struct TransferEvent {
156173
pub sender: Signer,
157174
pub receiver: Signer,

crates/ibc/src/applications/transfer/memo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
//! Defines the memo type, which represents the string that users can include
2+
//! with a token transfer
3+
14
use core::convert::Infallible;
25
use core::fmt::{self, Display};
36
use core::str::FromStr;
47

58
use crate::prelude::*;
69

10+
/// Represents the token transfer memo
711
#[cfg_attr(
812
feature = "parity-scale-codec",
913
derive(

crates/ibc/src/applications/transfer/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//! ICS 20: Token Transfer implementation allows for multi-chain denomination handling, which
2-
//! constitutes a "fungible token transfer bridge module" between the IBC routing module and an
3-
//! asset tracking module.
1+
//! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20)
2+
43
pub mod acknowledgement;
54
pub mod amount;
65
pub mod coin;
@@ -11,7 +10,6 @@ pub mod events;
1110
pub mod memo;
1211
pub mod msgs;
1312
pub mod packet;
14-
pub mod relay;
1513

1614
pub use amount::*;
1715
pub use coin::*;
@@ -27,3 +25,7 @@ pub const PORT_ID_STR: &str = "transfer";
2725

2826
/// ICS20 application current version.
2927
pub const VERSION: &str = "ics20-1";
28+
29+
mod relay;
30+
31+
pub use relay::send_transfer::{send_transfer, send_transfer_execute, send_transfer_validate};
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
//! Defines the token transfer message type
2+
13
pub mod transfer;

crates/ibc/src/applications/transfer/msgs/transfer.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This is the definition of a transfer messages that an application submits to a chain.
1+
//! Defines the token transfer message type
22
33
use crate::prelude::*;
44

@@ -11,11 +11,10 @@ use crate::applications::transfer::packet::PacketData;
1111
use crate::core::ics04_channel::error::PacketError;
1212
use crate::core::ics04_channel::timeout::TimeoutHeight;
1313
use crate::core::ics24_host::identifier::{ChannelId, PortId};
14-
use crate::core::ContextError;
15-
use crate::timestamp::Timestamp;
16-
use crate::tx_msg::Msg;
14+
use crate::core::timestamp::Timestamp;
15+
use crate::core::{ContextError, Msg};
1716

18-
pub const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
17+
pub(crate) const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
1918

2019
/// Message used to build an ICS20 token transfer packet.
2120
///
@@ -119,7 +118,8 @@ impl TryFrom<Any> for MsgTransfer {
119118

120119
#[cfg(test)]
121120
pub mod test_util {
122-
use alloc::borrow::ToOwned;
121+
use super::*;
122+
123123
use core::ops::Add;
124124
use core::time::Duration;
125125
use primitive_types::U256;
@@ -134,7 +134,6 @@ pub mod test_util {
134134
applications::transfer::BaseCoin,
135135
core::ics24_host::identifier::{ChannelId, PortId},
136136
test_utils::get_dummy_bech32_account,
137-
timestamp::Timestamp,
138137
};
139138

140139
// Returns a dummy ICS20 `MsgTransfer`. If no `timeout_timestamp` is

crates/ibc/src/applications/transfer/packet.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Contains the `PacketData` type that defines the structure of token transfers' packet bytes
2+
13
use alloc::string::ToString;
24
use core::convert::TryFrom;
35
use core::str::FromStr;
@@ -8,6 +10,7 @@ use super::error::TokenTransferError;
810
use super::{Amount, Memo, PrefixedCoin, PrefixedDenom};
911
use crate::signer::Signer;
1012

13+
/// Defines the structure of token transfers' packet bytes
1114
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1215
#[cfg_attr(
1316
feature = "serde",

crates/ibc/src/applications/transfer/relay.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! This module implements the processing logic for ICS20 (token transfer) message.
1+
//! Implements the processing logic for ICS20 (token transfer) message.
2+
23
use crate::applications::transfer::error::TokenTransferError;
34
use crate::applications::transfer::is_sender_chain_source;
45
use crate::applications::transfer::packet::PacketData;

crates/ibc/src/applications/transfer/relay/on_recv_packet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::applications::transfer::error::TokenTransferError;
33
use crate::applications::transfer::events::DenomTraceEvent;
44
use crate::applications::transfer::packet::PacketData;
55
use crate::applications::transfer::{is_receiver_chain_source, TracePrefix};
6-
use crate::core::ics04_channel::handler::ModuleExtras;
76
use crate::core::ics04_channel::packet::Packet;
7+
use crate::core::router::ModuleExtras;
88
use crate::prelude::*;
99

1010
/// This function handles the transfer receiving logic.

crates/ibc/src/applications/transfer/relay/send_transfer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ use crate::applications::transfer::error::TokenTransferError;
55
use crate::applications::transfer::events::TransferEvent;
66
use crate::applications::transfer::msgs::transfer::MsgTransfer;
77
use crate::applications::transfer::{is_sender_chain_source, MODULE_ID_STR};
8+
use crate::core::events::{MessageEvent, ModuleEvent};
89
use crate::core::ics04_channel::handler::send_packet::{send_packet_execute, send_packet_validate};
910
use crate::core::ics04_channel::packet::Packet;
1011
use crate::core::ics24_host::path::{ChannelEndPath, SeqSendPath};
11-
use crate::events::{MessageEvent, ModuleEvent};
1212
use crate::prelude::*;
1313

14-
/// This function handles the transfer sending logic.
15-
/// If this method returns an error, the runtime is expected to rollback all state modifications to
16-
/// the `Ctx` caused by all messages from the transaction that this `msg` is a part of.
14+
/// Initiate a token transfer. Equivalent to calling [`send_transfer_validate`], followed by [`send_transfer_execute`].
1715
pub fn send_transfer<Ctx>(ctx_a: &mut Ctx, msg: MsgTransfer) -> Result<(), TokenTransferError>
1816
where
1917
Ctx: TokenTransferExecutionContext,
@@ -22,6 +20,7 @@ where
2220
send_transfer_execute(ctx_a, msg)
2321
}
2422

23+
/// Validates the token tranfer. If this succeeds, then it is legal to initiate the transfer with [`send_transfer_execute`].
2524
pub fn send_transfer_validate<Ctx>(ctx_a: &Ctx, msg: MsgTransfer) -> Result<(), TokenTransferError>
2625
where
2726
Ctx: TokenTransferValidationContext,
@@ -85,6 +84,7 @@ where
8584
Ok(())
8685
}
8786

87+
/// Executes the token transfer. A prior call to [`send_transfer_validate`] MUST have succeeded.
8888
pub fn send_transfer_execute<Ctx>(
8989
ctx_a: &mut Ctx,
9090
msg: MsgTransfer,

0 commit comments

Comments
 (0)