forked from MyFanss/MyFans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
87 lines (76 loc) · 2.22 KB
/
Copy pathlib.rs
File metadata and controls
87 lines (76 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![no_std]
use soroban_sdk::{contracterror, contracttype};
/// Subscription lifecycle status
#[contracttype]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum SubscriptionStatus {
Pending = 0,
Active = 1,
Cancelled = 2,
Expired = 3,
}
/// Content access type
#[contracttype]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum ContentType {
Free = 0,
Paid = 1,
}
/// Shared error enum across all MyFans contracts.
/// Codes preserved exactly for test snapshot compatibility.
#[contracterror]
#[repr(u32)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MyfansError {
/// Common init/admin errors
AlreadyInitialized = 1,
NotInitialized = 2,
NotAuthorized = 3,
/// Balance/transfer errors
InsufficientBalance = 4,
/// Fee/config errors
InvalidFeeBps = 5,
/// Spam/security
RateLimited = 6,
AlreadyRegistered = 7,
NotLiked = 8,
/// State control
Paused = 9,
/// content-access specific
ContentPriceNotSet = 101,
/// subscription specific
SubscriptionNotFound = 102,
SubscriptionExpired = 103,
AdminNotInitialized = 104,
/// treasury specific
NegativeMinBalance = 105,
MinBalanceViolation = 106,
}
// Ensure numeric discriminants are represented as `u32` in the compiled ABI.
// This keeps the contracterror discriminants stable across builds and targets.
/// Stable numeric error codes for every MyFans contract, grouped by contract.
/// Clients can import these instead of hard-coding magic numbers.
///
/// ```rust
/// use myfans_lib::error_codes::subscription as sub_err;
/// assert_eq!(sub_err::SUBSCRIPTION_NOT_FOUND, 3);
/// ```
pub mod error_codes;
/// Shared test fixtures for cross-contract integration tests.
/// Only compiled when the `testutils` feature is enabled.
#[cfg(any(test, feature = "testutils"))]
pub mod test_fixtures;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_subscription_status_values() {
assert_eq!(SubscriptionStatus::Pending as u32, 0);
assert_eq!(SubscriptionStatus::Active as u32, 1);
assert_eq!(SubscriptionStatus::Cancelled as u32, 2);
assert_eq!(SubscriptionStatus::Expired as u32, 3);
}
// ... (rest unchanged)
}