multiversx_sc_scenario/scenario/model/transaction/
tx_response_status.rsuse multiversx_sc::chain_core::types::ReturnCode;
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct TxResponseStatus {
pub status: ReturnCode,
pub message: String,
}
impl TxResponseStatus {
pub fn new(status: ReturnCode, message: &str) -> Self {
Self {
status,
message: message.to_string(),
}
}
pub fn signal_error(message: &str) -> Self {
Self::new(ReturnCode::UserError, message)
}
pub fn is_success(&self) -> bool {
self.status.is_success()
}
}
impl std::fmt::Display for TxResponseStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.is_success() {
write!(f, "transaction successful")
} else {
write!(
f,
"transaction failed: (status: {}, message: {})",
self.status, self.message
)
}
}
}