Skip to content

Commit

Permalink
Improve some docs around StdAck -> Binary conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Aug 23, 2023
1 parent 2947d94 commit 5487d8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,17 @@ impl<T> IbcReceiveResponse<T> {
}

/// Set the acknowledgement for this response.
///
/// ## Examples
///
/// ```
/// use cosmwasm_std::{StdAck, IbcReceiveResponse};
///
/// fn make_response_with_ack() -> IbcReceiveResponse {
/// let ack = StdAck::success(b"\x01"); // 0x01 is a FungibleTokenPacketSuccess from ICS-20.
/// IbcReceiveResponse::new().set_ack(ack)
/// }
/// ```
pub fn set_ack(mut self, ack: impl Into<Binary>) -> Self {
self.acknowledgement = ack.into();
self
Expand Down
8 changes: 5 additions & 3 deletions packages/std/src/stdack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ impl StdAck {
///
/// Set acknowledgement field in `IbcReceiveResponse`:
///
/// ```ignore
/// ```
/// use cosmwasm_std::{StdAck, IbcReceiveResponse};
///
/// let ack = StdAck::success(b"\x01"); // 0x01 is a FungibleTokenPacketSuccess from ICS-20.
///
/// let res = IbcReceiveResponse::new().set_ack(ack.to_binary());
/// let res = IbcReceiveResponse::new().set_ack(ack); // Does the same but consumes the instance
/// let res: IbcReceiveResponse = IbcReceiveResponse::new().set_ack(ack.to_binary());
/// let res: IbcReceiveResponse = IbcReceiveResponse::new().set_ack(ack); // Does the same but consumes the instance
/// ```
pub fn to_binary(&self) -> Binary {
// We need a non-failing StdAck -> Binary conversion to allow using StdAck in
// `impl Into<Binary>` arguments.
// Pretty sure this cannot fail. If that changes we can create a non-failing implementation here.
to_binary(&self).unwrap()
}
Expand Down

0 comments on commit 5487d8f

Please sign in to comment.