delta_base_sdk/
transactions.rs

1//! Types and utilities for creating, and signing transactions.
2//!
3//! This module provides everything needed to construct, sign, and submit
4//! transactions in delta. It includes a builder interface for creating
5//! transactions and types for tracking transaction status.
6
7use proto_types::{
8    error::{
9        MissingDataSnafu,
10        ProtoError,
11    },
12    transactions::TxFailed,
13};
14use snafu::OptionExt;
15use std::fmt::Display;
16
17// Re-export required types
18pub use primitives::{
19    constants::MIN_NEW_SHARD_FEE,
20    domain_agreement::DomainAgreement,
21    transaction::*,
22};
23pub use proto_types::transactions::TypeData;
24
25/// The status of a transaction
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub enum TransactionStatus {
28    /// The transaction is still processing.
29    Pending,
30    /// The transaction was successfully processed.
31    Applied,
32    /// The transaction failed processing, and reason why.
33    Failure(String),
34}
35
36impl Display for TransactionStatus {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        match self {
39            Self::Pending => write!(f, "PENDING"),
40            Self::Applied => write!(f, "APPLIED"),
41            Self::Failure(error) => write!(f, "FAILED ({error})"),
42        }
43    }
44}
45
46impl TryFrom<proto_types::transactions::TransactionStatus> for TransactionStatus {
47    type Error = ProtoError;
48
49    fn try_from(value: proto_types::transactions::TransactionStatus) -> Result<Self, Self::Error> {
50        use proto_types::transactions::Status;
51        let status = value.status.context(MissingDataSnafu { field: "status" })?;
52        Ok(match status {
53            Status::Pending(..) => Self::Pending,
54            Status::Applied(..) => Self::Applied,
55            Status::Failed(TxFailed { error }) => Self::Failure(error),
56        })
57    }
58}