Skip to content
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

Properly define and document our public interface #656

Merged
merged 52 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
afa0f76
some docstrings updated
plafer May 1, 2023
81d6a6d
Remove dynamic_typing module
plafer May 1, 2023
84b690e
move some utils to tendermint client
plafer May 2, 2023
0b3b59c
Make `crate::utils` private
plafer May 2, 2023
ce06ed8
docs
plafer May 2, 2023
68de994
Remove unused struct
plafer May 2, 2023
d018354
move events under core
plafer May 2, 2023
74c1f93
move timestamp under core
plafer May 2, 2023
5a51f62
Move tx_msg under core
plafer May 2, 2023
9c4e261
Make naming convention comment not module-level
plafer May 2, 2023
080fd56
Make core::handler private
plafer May 2, 2023
73b66a9
Re-export all core::context
plafer May 2, 2023
97abb44
make tx_msg private and re-export Msg
plafer May 2, 2023
048578c
core module docs
plafer May 2, 2023
7c23242
Merge branch 'main' into plafer/376-docstrings
plafer May 2, 2023
c7e49fc
many docs improvements
plafer May 3, 2023
45e733c
Release v0.39.0 (#657)
plafer May 2, 2023
590a92d
fix doc test
plafer May 3, 2023
6dd08b1
`Validation/ExecutionContext` method docs
plafer May 3, 2023
98c5c81
more docs improvements
plafer May 3, 2023
459c459
remove unused function
plafer May 3, 2023
1c0ad93
client docs improvements
plafer May 3, 2023
4779436
move trust_threshold to tendermint
plafer May 3, 2023
906d577
connection
plafer May 3, 2023
47f2766
finish ics-20 docs
plafer May 4, 2023
56631ee
finish docs for the tendermint light client
plafer May 4, 2023
0a5b968
core docs
plafer May 4, 2023
8796b7c
move `ModuleExtras` out of channel
plafer May 4, 2023
f434322
Make all `TYPE_URL` private
plafer May 4, 2023
6cec88e
Move `Acknowledgement `
plafer May 4, 2023
399a3b4
remove superfluous channel message modules
plafer May 4, 2023
e9cce06
finish channel docs
plafer May 4, 2023
1fe5522
Remove `ics05_port` module
plafer May 4, 2023
41d0148
ValidationError -> IdentifierError
plafer May 4, 2023
da63d2d
remove error module
plafer May 4, 2023
5585395
cleanup ics24_host path
plafer May 4, 2023
9574a09
move host validate module under identifier
plafer May 4, 2023
921b014
move RouterError
plafer May 4, 2023
a4bad4f
move msgs under core
plafer May 4, 2023
75107a6
remove tx_msg
plafer May 4, 2023
3e6bde4
router module
plafer May 4, 2023
f852a3e
remove arbitrary restrictions on `ModuleId`
plafer May 4, 2023
1d7462f
router
plafer May 4, 2023
3963212
finish ics23
plafer May 4, 2023
58a5da6
mock
plafer May 4, 2023
50628e3
fmt
plafer May 4, 2023
b59e9a0
Merge branch 'main' into plafer/376-docstrings
plafer May 4, 2023
953738b
Add serialization for various structs and enums (#653)
DaviRain-Su May 5, 2023
513d61a
changelog
plafer May 5, 2023
405434d
remove `ClientTypePath`
plafer May 5, 2023
0d5cd8f
Merge remote-tracking branch 'origin/main' into plafer/376-docstrings
plafer May 5, 2023
57b9468
Merge remote-tracking branch 'origin/main' into plafer/376-docstrings
plafer May 5, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Reduce and consolidate the amount of public modules exposed
([#235](https://github.com/cosmos/ibc-rs/issues/235))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Make `TYPE_URL`s private ([#597](https://github.com/cosmos/ibc-rs/issues/597))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/376-docstrings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Document every method of `ValidationContext` and `ExecutionContext`
([#376](https://github.com/cosmos/ibc-rs/issues/376))
2 changes: 1 addition & 1 deletion crates/ibc/src/applications/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Various packet encoding semantics which underpin the various types of transactions.
//! Implementation of IBC applications

#[cfg(feature = "serde")]
pub mod transfer;
5 changes: 3 additions & 2 deletions crates/ibc/src/applications/transfer/acknowledgement.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Defines types used in token transfer acknowledgements

use core::fmt::{Display, Error as FmtError, Formatter};

use super::error::TokenTransferError;
use crate::core::ics04_channel::msgs::acknowledgement::Acknowledgement;
use crate::prelude::*;
use crate::{core::ics04_channel::packet::Acknowledgement, prelude::*};

/// A string constant included in error acknowledgements.
/// NOTE: Changing this const is state machine breaking as acknowledgements are written into state
Expand Down
2 changes: 2 additions & 0 deletions crates/ibc/src/applications/transfer/amount.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Contains the `Amount` type, which represents amounts of tokens transferred.

use core::str::FromStr;
use derive_more::{Display, From, Into};

Expand Down
2 changes: 2 additions & 0 deletions crates/ibc/src/applications/transfer/coin.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Defines coin types; the objects that are being transferred.

use core::fmt::{Display, Error as FmtError, Formatter};
use core::str::{from_utf8, FromStr};
use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin;
Expand Down
9 changes: 6 additions & 3 deletions crates/ibc/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines the main context traits and IBC module callbacks

use crate::core::router::ModuleExtras;
use crate::core::ContextError;
use crate::prelude::*;

Expand All @@ -16,13 +19,12 @@ use crate::core::ics04_channel::channel::{Counterparty, Order};
use crate::core::ics04_channel::context::{
SendPacketExecutionContext, SendPacketValidationContext,
};
use crate::core::ics04_channel::handler::ModuleExtras;
use crate::core::ics04_channel::msgs::acknowledgement::Acknowledgement;
use crate::core::ics04_channel::packet::Packet;
use crate::core::ics04_channel::packet::{Acknowledgement, Packet};
use crate::core::ics04_channel::Version;
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};
use crate::signer::Signer;

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

Expand Down Expand Up @@ -71,6 +73,7 @@ pub trait TokenTransferValidationContext: SendPacketValidationContext {
}
}

/// Methods required in token transfer execution, to be implemented by the host
pub trait TokenTransferExecutionContext:
TokenTransferValidationContext + SendPacketExecutionContext
{
Expand Down
12 changes: 11 additions & 1 deletion crates/ibc/src/applications/transfer/denom.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! 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)

use core::fmt::{Display, Error as FmtError, Formatter};
use core::str::FromStr;

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

/// Base denomination type
/// The "base" of a denomination.
///
/// For example, given the token `my_port-1/my_channel-1/my_port-2/my_channel-2/base_denom`,
/// `base_denom` is the "base" of the denomination
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[cfg_attr(
Expand Down Expand Up @@ -43,6 +48,11 @@ impl FromStr for BaseDenom {
}
}

/// One hop in a token's trace, which consists of the port and channel IDs of the sender
///
/// For example, given the token `my_port-1/my_channel-1/my_port-2/my_channel-2/base_denom`,
/// `my_port-1/my_channel-1` is a trace prefix, and `my_port-2/my_channel-2` is another one.
/// See [TracePath] which stitches trace prefixes together.
#[cfg_attr(
feature = "parity-scale-codec",
derive(
Expand Down
15 changes: 8 additions & 7 deletions crates/ibc/src/applications/transfer/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Defines the token transfer error type

use core::convert::Infallible;
use core::str::Utf8Error;
use displaydoc::Display;
use ibc_proto::protobuf::Error as TendermintProtoError;
use uint::FromDecStrErr;

use crate::core::ics04_channel::channel::Order;
use crate::core::ics24_host::error::ValidationError;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::core::ics24_host::identifier::{ChannelId, IdentifierError, PortId};
use crate::core::ContextError;
use crate::prelude::*;

Expand All @@ -15,7 +16,7 @@ pub enum TokenTransferError {
/// context error: `{0}`
ContextError(ContextError),
/// invalid identifier: `{0}`
InvalidIdentifier(ValidationError),
InvalidIdentifier(IdentifierError),
/// destination channel not found in the counterparty of port_id `{port_id}` and channel_id `{channel_id}`
DestinationChannelNotFound {
port_id: PortId,
Expand All @@ -26,12 +27,12 @@ pub enum TokenTransferError {
/// invalid prot id n trace at position: `{pos}`, validation error: `{validation_error}`
InvalidTracePortId {
pos: usize,
validation_error: ValidationError,
validation_error: IdentifierError,
},
/// invalid channel id in trace at position: `{pos}`, validation error: `{validation_error}`
InvalidTraceChannelId {
pos: usize,
validation_error: ValidationError,
validation_error: IdentifierError,
},
/// trace length must be even but got: `{len}`
InvalidTraceLength { len: usize },
Expand Down Expand Up @@ -105,8 +106,8 @@ impl From<ContextError> for TokenTransferError {
}
}

impl From<ValidationError> for TokenTransferError {
fn from(err: ValidationError) -> TokenTransferError {
impl From<IdentifierError> for TokenTransferError {
fn from(err: IdentifierError) -> TokenTransferError {
Self::InvalidIdentifier(err)
}
}
21 changes: 19 additions & 2 deletions crates/ibc/src/applications/transfer/events.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
//! Defines all token transfer event types

use crate::applications::transfer::acknowledgement::TokenTransferAcknowledgement;
use crate::applications::transfer::{Amount, Memo, PrefixedDenom, MODULE_ID_STR};
use crate::events::ModuleEvent;
use crate::applications::transfer::{Amount, PrefixedDenom, MODULE_ID_STR};
use crate::core::events::ModuleEvent;
use crate::prelude::*;
use crate::signer::Signer;

use super::Memo;

const EVENT_TYPE_PACKET: &str = "fungible_token_packet";
const EVENT_TYPE_TIMEOUT: &str = "timeout";
const EVENT_TYPE_DENOM_TRACE: &str = "denomination_trace";
const EVENT_TYPE_TRANSFER: &str = "ibc_transfer";

/// Contains all events variants that can be emitted from the token transfer application
pub enum Event {
Recv(RecvEvent),
Ack(AckEvent),
Expand All @@ -18,6 +23,8 @@ pub enum Event {
Transfer(TransferEvent),
}

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

/// Event emitted in the [`onAcknowledgePacket`][super::context::on_acknowledgement_packet_execute]
/// module callback
pub struct AckEvent {
pub sender: Signer,
pub receiver: Signer,
Expand Down Expand Up @@ -86,6 +95,8 @@ impl From<AckEvent> for ModuleEvent {
}
}

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

/// Event emitted in the [`onTimeoutPacket`][super::context::on_timeout_packet_execute]
/// module callback
pub struct TimeoutEvent {
pub refund_receiver: Signer,
pub refund_denom: PrefixedDenom,
Expand Down Expand Up @@ -133,6 +146,8 @@ impl From<TimeoutEvent> for ModuleEvent {
}
}

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

/// Event emitted in [`sendTransfer`][super::send_transfer] after a successful
/// transfer
pub struct TransferEvent {
pub sender: Signer,
pub receiver: Signer,
Expand Down
4 changes: 4 additions & 0 deletions crates/ibc/src/applications/transfer/memo.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//! Defines the memo type, which represents the string that users can include
//! with a token transfer

use core::convert::Infallible;
use core::fmt::{self, Display};
use core::str::FromStr;

use crate::prelude::*;

/// Represents the token transfer memo
#[cfg_attr(
feature = "parity-scale-codec",
derive(
Expand Down
10 changes: 6 additions & 4 deletions crates/ibc/src/applications/transfer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! ICS 20: Token Transfer implementation allows for multi-chain denomination handling, which
//! constitutes a "fungible token transfer bridge module" between the IBC routing module and an
//! asset tracking module.
//! 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)

pub mod acknowledgement;
pub mod amount;
pub mod coin;
Expand All @@ -11,7 +10,6 @@ pub mod events;
pub mod memo;
pub mod msgs;
pub mod packet;
pub mod relay;

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

/// ICS20 application current version.
pub const VERSION: &str = "ics20-1";

mod relay;

pub use relay::send_transfer::{send_transfer, send_transfer_execute, send_transfer_validate};
2 changes: 2 additions & 0 deletions crates/ibc/src/applications/transfer/msgs.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//! Defines the token transfer message type

pub mod transfer;
13 changes: 6 additions & 7 deletions crates/ibc/src/applications/transfer/msgs/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This is the definition of a transfer messages that an application submits to a chain.
//! Defines the token transfer message type

use crate::prelude::*;

Expand All @@ -11,11 +11,10 @@ use crate::applications::transfer::packet::PacketData;
use crate::core::ics04_channel::error::PacketError;
use crate::core::ics04_channel::timeout::TimeoutHeight;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::core::ContextError;
use crate::timestamp::Timestamp;
use crate::tx_msg::Msg;
use crate::core::timestamp::Timestamp;
use crate::core::{ContextError, Msg};

pub const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
pub(crate) const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";

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

#[cfg(test)]
pub mod test_util {
use alloc::borrow::ToOwned;
use super::*;

use core::ops::Add;
use core::time::Duration;
use primitive_types::U256;
Expand All @@ -134,7 +134,6 @@ pub mod test_util {
applications::transfer::BaseCoin,
core::ics24_host::identifier::{ChannelId, PortId},
test_utils::get_dummy_bech32_account,
timestamp::Timestamp,
};

// Returns a dummy ICS20 `MsgTransfer`. If no `timeout_timestamp` is
Expand Down
3 changes: 3 additions & 0 deletions crates/ibc/src/applications/transfer/packet.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Contains the `PacketData` type that defines the structure of token transfers' packet bytes

use alloc::string::ToString;
use core::convert::TryFrom;
use core::str::FromStr;
Expand All @@ -8,6 +10,7 @@ use super::error::TokenTransferError;
use super::{Amount, Memo, PrefixedCoin, PrefixedDenom};
use crate::signer::Signer;

/// Defines the structure of token transfers' packet bytes
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
Expand Down
3 changes: 2 additions & 1 deletion crates/ibc/src/applications/transfer/relay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! This module implements the processing logic for ICS20 (token transfer) message.
//! Implements the processing logic for ICS20 (token transfer) message.

use crate::applications::transfer::error::TokenTransferError;
use crate::applications::transfer::is_sender_chain_source;
use crate::applications::transfer::packet::PacketData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::applications::transfer::error::TokenTransferError;
use crate::applications::transfer::events::DenomTraceEvent;
use crate::applications::transfer::packet::PacketData;
use crate::applications::transfer::{is_receiver_chain_source, TracePrefix};
use crate::core::ics04_channel::handler::ModuleExtras;
use crate::core::ics04_channel::packet::Packet;
use crate::core::router::ModuleExtras;
use crate::prelude::*;

/// This function handles the transfer receiving logic.
Expand Down
8 changes: 4 additions & 4 deletions crates/ibc/src/applications/transfer/relay/send_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use crate::applications::transfer::error::TokenTransferError;
use crate::applications::transfer::events::TransferEvent;
use crate::applications::transfer::msgs::transfer::MsgTransfer;
use crate::applications::transfer::{is_sender_chain_source, MODULE_ID_STR};
use crate::core::events::{MessageEvent, ModuleEvent};
use crate::core::ics04_channel::handler::send_packet::{send_packet_execute, send_packet_validate};
use crate::core::ics04_channel::packet::Packet;
use crate::core::ics24_host::path::{ChannelEndPath, SeqSendPath};
use crate::events::{MessageEvent, ModuleEvent};
use crate::prelude::*;

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

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

/// Executes the token transfer. A prior call to [`send_transfer_validate`] MUST have succeeded.
pub fn send_transfer_execute<Ctx>(
ctx_a: &mut Ctx,
msg: MsgTransfer,
Expand Down
Loading