Skip to main content

bsv_wallet_toolbox/
status.rs

1//! Status enums for wallet entities.
2//!
3//! Each enum serializes to camelCase strings matching the TypeScript values exactly.
4//! All enums derive serde for JSON serialization and strum for Display/FromStr conversions.
5//! Database encoding/decoding is handled by the `impl_sqlx_string_enum!` macro in
6//! the sqlx_string_enum module, which treats each enum as a VARCHAR/TEXT string column.
7
8use serde::{Deserialize, Serialize};
9use strum::{Display, EnumString};
10
11/// Status of a wallet transaction.
12///
13/// Maps to TS `TransactionStatus` in `wallet-toolbox/src/sdk/types.ts`.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display, EnumString)]
15#[serde(rename_all = "camelCase")]
16#[strum(serialize_all = "camelCase")]
17pub enum TransactionStatus {
18    /// Transaction completed successfully and is proven on chain.
19    Completed,
20    /// Transaction failed to broadcast or was rejected.
21    Failed,
22    /// Transaction has not yet been processed.
23    Unprocessed,
24    /// Transaction is currently being broadcast to the network.
25    Sending,
26    /// Transaction was broadcast but is not yet proven in a block.
27    Unproven,
28    /// Transaction is awaiting signatures before it can be broadcast.
29    Unsigned,
30    /// Transaction was created with noSend flag and will not be broadcast.
31    Nosend,
32    /// Transaction contains nLockTime or nSequence constraints and is not yet final.
33    Nonfinal,
34    /// Transaction is being unfailed (moved from failed back to processing).
35    Unfail,
36}
37
38/// Status of a proven transaction request.
39///
40/// Maps to TS `ProvenTxReqStatus` in `wallet-toolbox/src/sdk/types.ts`.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display, EnumString)]
42#[serde(rename_all = "camelCase")]
43#[strum(serialize_all = "camelCase")]
44pub enum ProvenTxReqStatus {
45    /// Request is currently being sent to miners.
46    Sending,
47    /// Request has not yet been sent.
48    Unsent,
49    /// Request was created with noSend flag and will not be sent.
50    Nosend,
51    /// Request status is unknown or uninitialized.
52    Unknown,
53    /// Request contains a non-final transaction.
54    Nonfinal,
55    /// Request has not yet been processed.
56    Unprocessed,
57    /// Transaction was broadcast but is not yet mined.
58    Unmined,
59    /// Waiting for a callback from the broadcast service.
60    Callback,
61    /// Transaction is in a block but not yet sufficiently confirmed.
62    Unconfirmed,
63    /// Proof request completed successfully.
64    Completed,
65    /// Transaction was determined to be invalid.
66    Invalid,
67    /// Transaction was detected as a double spend.
68    DoubleSpend,
69    /// Request is being unfailed (moved from failed back to processing).
70    Unfail,
71}
72
73/// Status of wallet synchronization.
74///
75/// Maps to TS `SyncStatus` in `wallet-toolbox/src/sdk/WalletStorage.interfaces.ts`.
76#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display, EnumString)]
77#[serde(rename_all = "camelCase")]
78#[strum(serialize_all = "camelCase")]
79pub enum SyncStatus {
80    /// Synchronization completed successfully.
81    Success,
82    /// Synchronization encountered an error.
83    Error,
84    /// Remote storage has been identified but not yet synced.
85    Identified,
86    /// Records have been updated from the remote storage.
87    Updated,
88    /// Sync status has not been determined.
89    Unknown,
90}
91
92/// Status of a transaction output.
93#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display, EnumString)]
94#[serde(rename_all = "camelCase")]
95#[strum(serialize_all = "camelCase")]
96pub enum OutputStatus {
97    /// The output has not been spent and is available for use.
98    Unspent,
99    /// The output has been consumed as an input in another transaction.
100    Spent,
101}
102
103#[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgres"))]
104impl_sqlx_string_enum!(TransactionStatus);
105#[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgres"))]
106impl_sqlx_string_enum!(ProvenTxReqStatus);
107#[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgres"))]
108impl_sqlx_string_enum!(SyncStatus);
109#[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgres"))]
110impl_sqlx_string_enum!(OutputStatus);