|
1 | 1 | #![no_std] |
2 | 2 |
|
| 3 | +mod calculator; |
3 | 4 | mod claim; |
| 5 | +mod ledger; |
4 | 6 | mod policy; |
| 7 | +mod policy_lifecycle; |
5 | 8 | mod premium; |
6 | 9 | mod storage; |
7 | 10 | mod token; |
@@ -176,26 +179,91 @@ impl NiffyInsure { |
176 | 179 | storage::get_active_policy_count(&env, &holder) |
177 | 180 | } |
178 | 181 |
|
179 | | - // ── Admin / pause ──────────────────────────────────────────────────── |
| 182 | + // ═════════════════════════════════════════════════════════════════════════════ |
| 183 | + // PAUSE SYSTEM |
| 184 | + // |
| 185 | + // Granular pause flags for operational flexibility: |
| 186 | + // - bind_paused: blocks new policy initiation/renewal |
| 187 | + // - claims_paused: blocks filing claims and voting |
| 188 | + // |
| 189 | + // Admin-only toggles with optional reason codes. |
| 190 | + // Read-only methods continue to work for transparency. |
| 191 | + // ═════════════════════════════════════════════════════════════════════════════ |
180 | 192 |
|
181 | | - pub fn pause(env: Env, admin: Address) { |
| 193 | + /// Pause the contract with optional reason code. |
| 194 | + /// Reason codes: 0=maintenance, 1=vulnerability, 2=key_compromise, 3=other |
| 195 | + /// Emits PauseToggled event with admin, paused=true, and reason code. |
| 196 | + pub fn pause(env: Env, admin: Address, reason_code: u32) { |
182 | 197 | admin.require_auth(); |
183 | 198 | let stored_admin = storage::get_admin(&env); |
184 | 199 | assert!(admin == stored_admin, "only admin can pause"); |
185 | 200 | storage::set_paused(&env, true); |
| 201 | + |
| 202 | + // Emit PauseToggled event for monitoring |
| 203 | + env.events().publish( |
| 204 | + (symbol_short!("p_toggle"),), |
| 205 | + (admin, true, reason_code), |
| 206 | + ); |
186 | 207 | } |
187 | 208 |
|
188 | | - pub fn unpause(env: Env, admin: Address) { |
| 209 | + /// Unpause the contract with optional reason code. |
| 210 | + /// Reason codes: 0=resolved, 1=manual, 2=other |
| 211 | + /// Emits PauseToggled event with admin, paused=false, and reason code. |
| 212 | + pub fn unpause(env: Env, admin: Address, reason_code: u32) { |
189 | 213 | admin.require_auth(); |
190 | 214 | let stored_admin = storage::get_admin(&env); |
191 | 215 | assert!(admin == stored_admin, "only admin can unpause"); |
192 | 216 | storage::set_paused(&env, false); |
| 217 | + |
| 218 | + // Emit PauseToggled event for monitoring |
| 219 | + env.events().publish( |
| 220 | + (symbol_short!("p_toggle"),), |
| 221 | + (admin, false, reason_code), |
| 222 | + ); |
| 223 | + } |
| 224 | + |
| 225 | + /// Granular pause: pause only policy binding (initiate/renew). |
| 226 | + pub fn pause_bind(env: Env, admin: Address, reason_code: u32) { |
| 227 | + admin.require_auth(); |
| 228 | + let stored_admin = storage::get_admin(&env); |
| 229 | + assert!(admin == stored_admin, "only admin can pause"); |
| 230 | + |
| 231 | + let mut flags = storage::get_pause_flags(&env); |
| 232 | + flags.bind_paused = true; |
| 233 | + storage::set_pause_flags(&env, &flags); |
| 234 | + |
| 235 | + env.events().publish( |
| 236 | + (symbol_short!("p_toggle"),), |
| 237 | + (admin, true, reason_code), |
| 238 | + ); |
193 | 239 | } |
194 | 240 |
|
| 241 | + /// Granular pause: pause only claims (file/vote/finalize). |
| 242 | + pub fn pause_claims(env: Env, admin: Address, reason_code: u32) { |
| 243 | + admin.require_auth(); |
| 244 | + let stored_admin = storage::get_admin(&env); |
| 245 | + assert!(admin == stored_admin, "only admin can pause"); |
| 246 | + |
| 247 | + let mut flags = storage::get_pause_flags(&env); |
| 248 | + flags.claims_paused = true; |
| 249 | + storage::set_pause_flags(&env, &flags); |
| 250 | + |
| 251 | + env.events().publish( |
| 252 | + (symbol_short!("p_toggle"),), |
| 253 | + (admin, true, reason_code), |
| 254 | + ); |
| 255 | + } |
| 256 | + |
| 257 | + /// Get current pause state (legacy - true if ANY pause flag is set). |
195 | 258 | pub fn is_paused(env: Env) -> bool { |
196 | 259 | storage::is_paused(&env) |
197 | 260 | } |
198 | 261 |
|
| 262 | + /// Get detailed pause flags (bind_paused, claims_paused). |
| 263 | + pub fn get_pause_flags(env: Env) -> storage::PauseFlags { |
| 264 | + storage::get_pause_flags(&env) |
| 265 | + } |
| 266 | + |
199 | 267 | // ── Test-only helpers ───────────────────────────────────────────────── |
200 | 268 |
|
201 | 269 | #[cfg(feature = "testutils")] |
@@ -231,6 +299,3 @@ impl NiffyInsure { |
231 | 299 | storage::remove_voter(&env, &holder); |
232 | 300 | } |
233 | 301 | } |
234 | | - |
235 | | -// Re-export error type so tests can reference it without the module path. |
236 | | -pub use claim::ContractError; |
|
0 commit comments