@@ -112,12 +112,7 @@ pub trait Owner {
112
112
/// Updates proposed owner without any checks or emitting events.
113
113
fn update_proposed_unchecked ( & mut self , new : Option < AccountId > ) ;
114
114
115
- /// Same as require_owner but as a method.
116
- fn assert_owner ( & self ) ;
117
-
118
- /// Initializes the contract owner. Can only be called once.
119
- ///
120
- /// Emits an `OwnerEvent::Transfer` event.
115
+ /// Rejects if the predecessor is not the current owner.
121
116
///
122
117
/// # Examples
123
118
///
@@ -131,19 +126,18 @@ pub trait Owner {
131
126
///
132
127
/// #[near]
133
128
/// impl Contract {
134
- /// #[init]
135
- /// pub fn new(owner_id: AccountId) -> Self {
136
- /// let mut contract = Self {};
137
- ///
138
- /// Owner::init(&mut contract, &owner_id);
129
+ /// pub fn owner_only_function(&self) {
130
+ /// self.require_owner();
139
131
///
140
- /// contract
132
+ /// // ...
141
133
/// }
142
134
/// }
143
135
/// ```
144
- fn init ( & mut self , owner_id : & AccountId ) ;
136
+ fn require_owner ( & self ) ;
145
137
146
- /// Requires the predecessor to be the owner.
138
+ /// Initializes the contract owner. Can only be called once.
139
+ ///
140
+ /// Emits an `OwnerEvent::Transfer` event.
147
141
///
148
142
/// # Examples
149
143
///
@@ -157,14 +151,17 @@ pub trait Owner {
157
151
///
158
152
/// #[near]
159
153
/// impl Contract {
160
- /// pub fn owner_only(&self) {
161
- /// Self::require_owner();
154
+ /// #[init]
155
+ /// pub fn new(owner_id: AccountId) -> Self {
156
+ /// let mut contract = Self {};
162
157
///
163
- /// // ...
158
+ /// Owner::init(&mut contract, &owner_id);
159
+ ///
160
+ /// contract
164
161
/// }
165
162
/// }
166
163
/// ```
167
- fn require_owner ( ) ;
164
+ fn init ( & mut self , owner_id : & AccountId ) ;
168
165
169
166
/// Removes the contract's owner. Can only be called by the current owner.
170
167
///
@@ -226,7 +223,7 @@ impl<T: OwnerInternal> Owner for T {
226
223
proposed_owner. set ( new. as_ref ( ) ) ;
227
224
}
228
225
229
- fn assert_owner ( & self ) {
226
+ fn require_owner ( & self ) {
230
227
require ! (
231
228
& env:: predecessor_account_id( )
232
229
== Self :: slot_owner( )
@@ -253,26 +250,15 @@ impl<T: OwnerInternal> Owner for T {
253
250
. emit ( ) ;
254
251
}
255
252
256
- fn require_owner ( ) {
257
- require ! (
258
- & env:: predecessor_account_id( )
259
- == Self :: slot_owner( )
260
- . read( )
261
- . as_ref( )
262
- . unwrap_or_else( || env:: panic_str( NO_OWNER_FAIL_MESSAGE ) ) ,
263
- ONLY_OWNER_FAIL_MESSAGE ,
264
- ) ;
265
- }
266
-
267
253
fn renounce_owner ( & mut self ) {
268
- Self :: require_owner ( ) ;
254
+ self . require_owner ( ) ;
269
255
270
256
self . update_proposed ( None ) ;
271
257
self . update_owner ( None ) ;
272
258
}
273
259
274
260
fn propose_owner ( & mut self , account_id : Option < AccountId > ) {
275
- Self :: require_owner ( ) ;
261
+ self . require_owner ( ) ;
276
262
277
263
self . update_proposed ( account_id) ;
278
264
}
@@ -312,7 +298,7 @@ pub mod hooks {
312
298
C : Owner ,
313
299
{
314
300
fn hook < R > ( contract : & mut C , _args : & A , f : impl FnOnce ( & mut C ) -> R ) -> R {
315
- contract. assert_owner ( ) ;
301
+ contract. require_owner ( ) ;
316
302
f ( contract)
317
303
}
318
304
}
@@ -377,7 +363,7 @@ mod tests {
377
363
}
378
364
379
365
pub fn owner_only ( & self ) {
380
- Self :: require_owner ( ) ;
366
+ self . require_owner ( ) ;
381
367
}
382
368
}
383
369
0 commit comments