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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use anchor_lang::prelude::*;
use crate::constants::{PUBKEY_SIZE, MAXIMUM_SUBSCRIPTIONS_PER_PLAN, MAXIMUM_SUBSCRIPTIONS_PER_USER, MAXIMUM_SUBSCRIPTION_PLAN_PER_AUTHOR, MAXIMUM_SUBSCRIPTION_PLANS, MAXIMUM_NODES};
#[account]
pub struct Subscriber {
pub bump: u8,
pub has_already_been_initialized: bool,
pub authority: Pubkey,
pub subscriber_payment_account: Pubkey,
pub subscription_accounts: Vec<Pubkey>,
}
impl Subscriber {
pub fn space() -> usize {
8 +
1 +
1 +
PUBKEY_SIZE +
PUBKEY_SIZE +
4 + (PUBKEY_SIZE * MAXIMUM_SUBSCRIPTIONS_PER_USER)
}
}
#[account]
pub struct Subscription {
pub bump: u8,
pub has_already_been_initialized: bool,
pub subscriber: Pubkey,
pub subscription_plan: Pubkey,
pub is_active: bool,
pub is_cancelled: bool,
pub cancellation_reason: i8,
pub last_payment_timestamp: i64,
pub next_payment_timestamp: i64,
}
impl Subscription {
pub fn space() -> usize {
8 +
1 +
1 +
PUBKEY_SIZE +
PUBKEY_SIZE +
1 +
1 +
1 +
8 +
8
}
}
#[account]
pub struct SubscriptionPlan {
pub bump: u8,
pub has_already_been_initialized: bool,
pub plan_name: String,
pub subscription_plan_author: Pubkey,
pub subscription_plan_payment_account: Pubkey,
pub amount: i64,
pub frequency: i64,
pub is_active: bool,
pub fee_percentage: i8,
pub subscription_accounts: Vec<Pubkey>,
}
impl SubscriptionPlan {
pub fn space(plan_name: &str) -> usize {
8 +
1 +
1 +
4 + plan_name.len() +
PUBKEY_SIZE +
PUBKEY_SIZE +
8 +
8 +
1 +
1 +
4 + (PUBKEY_SIZE * MAXIMUM_SUBSCRIPTIONS_PER_PLAN)
}
}
#[account]
pub struct SubscriptionPlanAuthor {
pub bump: u8,
pub has_already_been_initialized: bool,
pub authority: Pubkey,
pub subscription_plan_accounts: Vec<Pubkey>,
}
impl SubscriptionPlanAuthor {
pub fn space() -> usize {
8 +
1 +
1 +
PUBKEY_SIZE +
4 + (PUBKEY_SIZE * MAXIMUM_SUBSCRIPTION_PLAN_PER_AUTHOR)
}
}
#[account]
pub struct Protocol {
pub bump: u8,
pub has_already_been_initialized: bool,
pub authority: Pubkey,
pub subscription_plan_accounts: Vec<Pubkey>,
pub registered_nodes: Vec<Pubkey>,
}
impl Protocol {
pub fn space() -> usize {
8 +
1 +
1 +
PUBKEY_SIZE +
4 + (PUBKEY_SIZE * MAXIMUM_SUBSCRIPTION_PLANS) +
4 + (PUBKEY_SIZE * MAXIMUM_NODES)
}
}
#[account]
pub struct ProtocolSigner {
pub bump: u8,
}
impl ProtocolSigner {
pub fn space() -> usize {
8 +
1
}
}
#[account]
pub struct Node {
pub bump: u8,
pub is_registered: bool,
pub authority: Pubkey,
pub node_payment_wallet: Pubkey,
pub node_payment_account: Pubkey,
}
impl Node {
pub fn space() -> usize {
8 +
1 +
1 +
PUBKEY_SIZE +
PUBKEY_SIZE +
PUBKEY_SIZE
}
}