Skip to main content

ootle_rs/types/transaction/
outcome.rs

1//   Copyright 2026 The Tari Project
2//   SPDX-License-Identifier: BSD-3-Clause
3
4use std::fmt;
5
6use tari_ootle_common_types::engine_types::commit_result::RejectReason;
7
8#[derive(Debug, Clone)]
9pub enum TransactionOutcome {
10    /// The transaction was fully committed.
11    Commit,
12    /// Only the fee intent was committed. The main transaction was not committed.
13    OnlyFeeCommit(RejectReason),
14    /// Transaction was rejected with the given reason. NOTE: calling get_receipt on the transaction will fail.
15    Reject(RejectReason),
16}
17
18impl TransactionOutcome {
19    pub fn is_commit(&self) -> bool {
20        matches!(self, TransactionOutcome::Commit)
21    }
22
23    pub fn is_only_fee_commit(&self) -> bool {
24        matches!(self, TransactionOutcome::OnlyFeeCommit(_))
25    }
26
27    pub fn is_reject(&self) -> bool {
28        matches!(self, TransactionOutcome::Reject(_))
29    }
30
31    pub fn reject_reason(&self) -> Option<&RejectReason> {
32        match self {
33            TransactionOutcome::OnlyFeeCommit(reason) | TransactionOutcome::Reject(reason) => Some(reason),
34            _ => None,
35        }
36    }
37}
38
39impl fmt::Display for TransactionOutcome {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            TransactionOutcome::Commit => write!(f, "Commit"),
43            TransactionOutcome::OnlyFeeCommit(reason) => write!(f, "OnlyFeeCommit({reason})"),
44            TransactionOutcome::Reject(reason) => write!(f, "Reject({reason})"),
45        }
46    }
47}