Skip to content

Commit b123201

Browse files
move admin auth to require_admin_auth trait fn
1 parent e5d0f91 commit b123201

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

soroban-sdk/src/_migrating/v25_contracttrait.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@
5656
//! // Define a trait with default implementations
5757
//! #[contracttrait]
5858
//! pub trait Pausable {
59+
//! fn require_admin_auth(env: &Env);
60+
//!
5961
//! fn is_paused(env: &Env) -> bool {
6062
//! env.storage().instance().has(&PAUSED)
6163
//! }
6264
//!
6365
//! fn pause(env: &Env) {
64-
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
65-
//! admin.require_auth();
66+
//! Self::require_admin_auth(env);
6667
//! env.storage().instance().set(&PAUSED, &true);
6768
//! }
6869
//!
6970
//! fn unpause(env: &Env) {
70-
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
71-
//! admin.require_auth();
71+
//! Self::require_admin_auth(env);
7272
//! env.storage().instance().remove(&PAUSED);
7373
//! }
7474
//! }
@@ -78,7 +78,12 @@
7878
//!
7979
//! // Implement the trait - default functions are automatically exported
8080
//! #[contractimpl(contracttrait)]
81-
//! impl Pausable for MyContract {}
81+
//! impl Pausable for MyContract {
82+
//! fn require_admin_auth(env: &Env) {
83+
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
84+
//! admin.require_auth();
85+
//! }
86+
//! }
8287
//!
8388
//! #[contractimpl]
8489
//! impl MyContract {
@@ -109,19 +114,19 @@
109114
//! // Define a trait with default implementations
110115
//! #[contracttrait]
111116
//! pub trait Pausable {
117+
//! fn require_admin_auth(env: &Env);
118+
//!
112119
//! fn is_paused(env: &Env) -> bool {
113120
//! env.storage().instance().has(&PAUSED)
114121
//! }
115122
//!
116123
//! fn pause(env: &Env) {
117-
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
118-
//! admin.require_auth();
124+
//! Self::require_admin_auth(env);
119125
//! env.storage().instance().set(&PAUSED, &true);
120126
//! }
121127
//!
122128
//! fn unpause(env: &Env) {
123-
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
124-
//! admin.require_auth();
129+
//! Self::require_admin_auth(env);
125130
//! env.storage().instance().remove(&PAUSED);
126131
//! }
127132
//! }
@@ -132,6 +137,11 @@
132137
//! // Implement the trait - override default implementations as needed
133138
//! #[contractimpl(contracttrait)]
134139
//! impl Pausable for MyContract {
140+
//! fn require_admin_auth(env: &Env) {
141+
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
142+
//! admin.require_auth();
143+
//! }
144+
//!
135145
//! // Override is_paused with custom logic that returns false when not set
136146
//! fn is_paused(env: &Env) -> bool {
137147
//! env.storage().instance().get(&PAUSED).unwrap_or(false)
@@ -168,19 +178,19 @@
168178
//! // Define a trait with default implementations
169179
//! #[contracttrait]
170180
//! pub trait Pausable {
181+
//! fn require_admin_auth(env: &Env);
182+
//!
171183
//! fn is_paused(env: &Env) -> bool {
172184
//! env.storage().instance().has(&PAUSED)
173185
//! }
174186
//!
175187
//! fn pause(env: &Env) {
176-
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
177-
//! admin.require_auth();
188+
//! Self::require_admin_auth(env);
178189
//! env.storage().instance().set(&PAUSED, &true);
179190
//! }
180191
//!
181192
//! fn unpause(env: &Env) {
182-
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
183-
//! admin.require_auth();
193+
//! Self::require_admin_auth(env);
184194
//! env.storage().instance().remove(&PAUSED);
185195
//! }
186196
//! }
@@ -190,7 +200,12 @@
190200
//!
191201
//! // Implement the trait - default functions are automatically exported
192202
//! #[contractimpl(contracttrait)]
193-
//! impl Pausable for MyContract {}
203+
//! impl Pausable for MyContract {
204+
//! fn require_admin_auth(env: &Env) {
205+
//! let admin: Address = env.storage().instance().get(&ADMIN).unwrap();
206+
//! admin.require_auth();
207+
//! }
208+
//! }
194209
//!
195210
//! #[contractimpl]
196211
//! impl MyContract {

0 commit comments

Comments
 (0)