@@ -7,6 +7,7 @@ use soroban_sdk::{
77enum DataKey {
88 CertificateContract ,
99 Balance ( Address , u32 ) ,
10+ MintPaused ,
1011}
1112
1213#[ contracterror]
@@ -15,6 +16,7 @@ pub enum TokenError {
1516 AlreadyInitialized = 1 ,
1617 NotAuthorized = 2 ,
1718 InvalidAmount = 3 ,
19+ ContractPaused = 4 ,
1820}
1921
2022#[ contract]
@@ -31,12 +33,46 @@ impl RsTokenContract {
3133 env. storage ( )
3234 . instance ( )
3335 . set ( & DataKey :: CertificateContract , & certificate_contract) ;
36+ env. storage ( )
37+ . instance ( )
38+ . set ( & DataKey :: MintPaused , & false ) ;
39+ }
40+
41+ fn require_mint_not_paused ( env : & Env ) {
42+ let paused: bool = env
43+ . storage ( )
44+ . instance ( )
45+ . get ( & DataKey :: MintPaused )
46+ . unwrap_or ( false ) ;
47+ if paused {
48+ panic_with_error ! ( env, TokenError :: ContractPaused ) ;
49+ }
50+ }
51+
52+ /// Only the certificate contract may pause minting (invoked when the cert contract pauses).
53+ pub fn set_mint_pause ( env : Env , caller : Address , paused : bool ) {
54+ caller. require_auth ( ) ;
55+
56+ let certificate_contract: Address = env
57+ . storage ( )
58+ . instance ( )
59+ . get ( & DataKey :: CertificateContract )
60+ . unwrap ( ) ;
61+
62+ if caller != certificate_contract {
63+ panic_with_error ! ( & env, TokenError :: NotAuthorized ) ;
64+ }
65+
66+ env. storage ( )
67+ . instance ( )
68+ . set ( & DataKey :: MintPaused , & paused) ;
3469 }
3570
3671 /// Mints non-transferable RS-Tokens to a student for a specific token ID.
3772 /// Only the configured certificate contract address may call this.
3873 pub fn mint ( env : Env , caller : Address , student : Address , token_id : u32 , amount : i128 ) {
3974 caller. require_auth ( ) ;
75+ Self :: require_mint_not_paused ( & env) ;
4076
4177 let certificate_contract: Address = env
4278 . storage ( )
@@ -136,6 +172,23 @@ mod tests {
136172 client. mint ( & unauthorized, & student, & 1 , & 10 ) ;
137173 }
138174
175+ #[ test]
176+ #[ should_panic]
177+ fn rejects_mint_when_paused ( ) {
178+ let env = Env :: default ( ) ;
179+ env. mock_all_auths ( ) ;
180+
181+ let contract_id = env. register ( RsTokenContract , ( ) ) ;
182+ let client = RsTokenContractClient :: new ( & env, & contract_id) ;
183+
184+ let certificate_contract = Address :: generate ( & env) ;
185+ let student = Address :: generate ( & env) ;
186+
187+ client. init ( & certificate_contract) ;
188+ client. set_mint_pause ( & certificate_contract, & true ) ;
189+ client. mint ( & certificate_contract, & student, & 1 , & 10 ) ;
190+ }
191+
139192 #[ test]
140193 fn mints_different_token_ids_for_same_student ( ) {
141194 let env = Env :: default ( ) ;
0 commit comments