Skip to content

Commit

Permalink
Add separate constructor for IbcReceiveResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Dec 13, 2023
1 parent e88ee72 commit 45acc95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 14 additions & 1 deletion packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,20 @@ impl<T> IbcReceiveResponse<T> {
/// ```
pub fn new(ack: impl Into<Binary>) -> Self {
Self {
acknowledgement: ack.into(),
acknowledgement: Some(ack.into()),
messages: vec![],
attributes: vec![],
events: vec![],
}
}

/// Creates a new response without an acknowledgement.
///
/// This allows you to send the acknowledgement asynchronously later using [`IbcMsg::WriteAcknowledgement`].
/// If you want to send the acknowledgement immediately, use [`IbcReceiveResponse::new`].
pub fn without_ack() -> Self {
Self {
acknowledgement: None,
messages: vec![],
attributes: vec![],
events: vec![],
Expand Down
15 changes: 0 additions & 15 deletions packages/std/src/stdack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ impl From<StdAck> for Binary {
}
}

impl From<StdAck> for Option<Binary> {
fn from(original: StdAck) -> Option<Binary> {
Some(original.into())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -166,13 +160,4 @@ mod tests {
let ack2 = StdAck::error("kaputt");
assert_eq!(ack2.to_binary(), br#"{"error":"kaputt"}"#);
}

#[test]
fn stdack_to_option_binary_works() {
let ack1 = StdAck::success(b"\x01");
assert_eq!(Option::<Binary>::from(ack1.clone()), Some(ack1.to_binary()));

let ack2 = StdAck::error("kaputt");
assert_eq!(Option::<Binary>::from(ack2.clone()), Some(ack2.to_binary()));
}
}

0 comments on commit 45acc95

Please sign in to comment.