@@ -564,7 +564,93 @@ impl AdminAccessControl {
564564
565565 Ok ( ( ) )
566566 }
567+ }
568+
569+ // ===== CONTRACT PAUSE AND ADMIN TRANSFER =====
570+
571+ const CONTRACT_PAUSED_KEY : & str = "ContractPaused" ;
572+
573+ /// Contract-level pause and primary admin transfer.
574+ pub struct ContractPauseManager ;
575+
576+ impl ContractPauseManager {
577+ /// Returns true if the contract is currently paused.
578+ pub fn is_contract_paused ( env : & Env ) -> bool {
579+ env. storage ( )
580+ . persistent ( )
581+ . get ( & Symbol :: new ( env, CONTRACT_PAUSED_KEY ) )
582+ . unwrap_or ( false )
583+ }
567584
585+ /// Pause contract operations. Caller must be the current primary admin.
586+ pub fn pause ( env : & Env , admin : & Address ) -> Result < ( ) , Error > {
587+ admin. require_auth ( ) ;
588+ let stored: Address = env
589+ . storage ( )
590+ . persistent ( )
591+ . get ( & Symbol :: new ( env, "Admin" ) )
592+ . ok_or ( Error :: AdminNotSet ) ?;
593+ if admin != & stored {
594+ return Err ( Error :: Unauthorized ) ;
595+ }
596+ env. storage ( )
597+ . persistent ( )
598+ . set ( & Symbol :: new ( env, CONTRACT_PAUSED_KEY ) , & true ) ;
599+ EventEmitter :: emit_contract_paused ( env, admin) ;
600+ Ok ( ( ) )
601+ }
602+
603+ /// Unpause contract operations. Caller must be the current primary admin.
604+ pub fn unpause ( env : & Env , admin : & Address ) -> Result < ( ) , Error > {
605+ admin. require_auth ( ) ;
606+ let stored: Address = env
607+ . storage ( )
608+ . persistent ( )
609+ . get ( & Symbol :: new ( env, "Admin" ) )
610+ . ok_or ( Error :: AdminNotSet ) ?;
611+ if admin != & stored {
612+ return Err ( Error :: Unauthorized ) ;
613+ }
614+ env. storage ( )
615+ . persistent ( )
616+ . set ( & Symbol :: new ( env, CONTRACT_PAUSED_KEY ) , & false ) ;
617+ EventEmitter :: emit_contract_unpaused ( env, admin) ;
618+ Ok ( ( ) )
619+ }
620+
621+ /// Require that the contract is not paused; return Error::InvalidState otherwise.
622+ pub fn require_not_paused ( env : & Env ) -> Result < ( ) , Error > {
623+ if Self :: is_contract_paused ( env) {
624+ return Err ( Error :: InvalidState ) ;
625+ }
626+ Ok ( ( ) )
627+ }
628+
629+ /// Transfer the primary admin role to a new address. Caller must be the current primary admin.
630+ /// New admin must not be the zero/invalid address.
631+ pub fn transfer_admin ( env : & Env , current_admin : & Address , new_admin : & Address ) -> Result < ( ) , Error > {
632+ current_admin. require_auth ( ) ;
633+ let stored: Address = env
634+ . storage ( )
635+ . persistent ( )
636+ . get ( & Symbol :: new ( env, "Admin" ) )
637+ . ok_or ( Error :: AdminNotSet ) ?;
638+ if current_admin != & stored {
639+ return Err ( Error :: Unauthorized ) ;
640+ }
641+ if new_admin == current_admin {
642+ return Err ( Error :: InvalidInput ) ;
643+ }
644+ AdminValidator :: validate_admin_address ( env, new_admin) ?;
645+ env. storage ( )
646+ . persistent ( )
647+ . set ( & Symbol :: new ( env, "Admin" ) , new_admin) ;
648+ EventEmitter :: emit_admin_transferred ( env, current_admin, new_admin) ;
649+ Ok ( ( ) )
650+ }
651+ }
652+
653+ impl AdminAccessControl {
568654 /// Validates admin authentication and permissions for a specific action.
569655 ///
570656 /// This comprehensive validation function combines authentication and
0 commit comments