use cosmwasm_std::{from_binary, to_binary, Binary, IbcAcknowledgement, SubMsgResponse, Uint64};
pub use crate::callbacks::Callback;
use crate::callbacks::{ErrorResponse, ExecutionResponse};
pub type Ack = Callback;
pub fn ack_query_success(result: Vec<Binary>) -> Binary {
to_binary(&Callback::Query(Ok(result))).unwrap()
}
pub fn ack_query_fail(message_index: Uint64, error: String) -> Binary {
to_binary(&Callback::Query(Err(ErrorResponse {
message_index,
error,
})))
.unwrap()
}
pub fn ack_execute_success(result: Vec<SubMsgResponse>, executed_by: String) -> Binary {
to_binary(&Callback::Execute(Ok(ExecutionResponse {
result,
executed_by,
})))
.unwrap()
}
pub fn ack_execute_fail(error: String) -> Binary {
to_binary(&Callback::Execute(Err(error))).unwrap()
}
pub fn ack_fail(err: String) -> Binary {
to_binary(&Callback::FatalError(err)).unwrap()
}
pub fn unmarshal_ack(ack: &IbcAcknowledgement) -> Ack {
from_binary(&ack.data).unwrap_or_else(|e| {
Callback::FatalError(format!(
"error unmarshalling ack ({}): {}",
ack.data.to_base64(),
e
))
})
}