File tree 4 files changed +30
-34
lines changed
4 files changed +30
-34
lines changed Original file line number Diff line number Diff line change
1
+ pub mod macros;
2
+ pub use macros:: * ;
3
+
1
4
use near_sdk:: env;
2
5
3
6
pub type Mask = u128 ;
4
7
5
8
pub trait AdminControlled {
6
9
fn is_owner ( & self ) -> bool {
7
- env:: current_account_id ( ) == env:: signer_account_id ( )
8
- }
9
-
10
- fn assert_owner ( & self ) {
11
- assert ! ( self . is_owner( ) ) ;
10
+ env:: current_account_id ( ) == env:: predecessor_account_id ( )
12
11
}
13
12
14
13
/// Return the current mask representing all paused events.
Original file line number Diff line number Diff line change
1
+ #[ macro_export]
2
+ macro_rules! impl_admin_controlled {
3
+ ( $contract: ident, $paused: ident) => {
4
+ use admin_controlled:: { AdminControlled as AdminControlledInner , Mask as MaskInner } ;
5
+ use near_sdk as near_sdk_inner;
6
+
7
+ #[ near_bindgen]
8
+ impl AdminControlledInner for $contract {
9
+ #[ result_serializer( borsh) ]
10
+ fn get_paused( & self ) -> MaskInner {
11
+ self . $paused
12
+ }
13
+
14
+ #[ result_serializer( borsh) ]
15
+ fn set_paused( & mut self , #[ serializer( borsh) ] paused: MaskInner ) {
16
+ near_sdk_inner:: assert_self( ) ;
17
+ self . $paused = paused;
18
+ }
19
+ }
20
+ } ;
21
+ }
Original file line number Diff line number Diff line change 1
- use admin_controlled:: { AdminControlled , Mask } ;
1
+ use admin_controlled:: Mask ;
2
2
use borsh:: { BorshDeserialize , BorshSerialize } ;
3
3
use eth_types:: * ;
4
4
use near_sdk:: collections:: UnorderedMap ;
@@ -111,20 +111,6 @@ impl Default for EthClient {
111
111
}
112
112
}
113
113
114
- #[ near_bindgen]
115
- impl AdminControlled for EthClient {
116
- #[ result_serializer( borsh) ]
117
- fn get_paused ( & self ) -> Mask {
118
- self . paused
119
- }
120
-
121
- #[ result_serializer( borsh) ]
122
- fn set_paused ( & mut self , #[ serializer( borsh) ] paused : Mask ) {
123
- self . assert_owner ( ) ;
124
- self . paused = paused;
125
- }
126
- }
127
-
128
114
#[ near_bindgen]
129
115
impl EthClient {
130
116
#[ init]
@@ -441,3 +427,5 @@ impl EthClient {
441
427
( H256 ( pair. 0 ) , H256 ( pair. 1 ) )
442
428
}
443
429
}
430
+
431
+ admin_controlled:: impl_admin_controlled!( EthClient , paused) ;
Original file line number Diff line number Diff line change 1
- use admin_controlled:: { AdminControlled , Mask } ;
1
+ use admin_controlled:: Mask ;
2
2
use borsh:: { BorshDeserialize , BorshSerialize } ;
3
3
use eth_types:: * ;
4
4
use near_sdk:: { env, ext_contract, near_bindgen, PromiseOrValue } ;
@@ -320,16 +320,4 @@ impl EthProver {
320
320
}
321
321
}
322
322
323
- #[ near_bindgen]
324
- impl AdminControlled for EthProver {
325
- #[ result_serializer( borsh) ]
326
- fn get_paused ( & self ) -> Mask {
327
- self . paused
328
- }
329
-
330
- #[ result_serializer( borsh) ]
331
- fn set_paused ( & mut self , #[ serializer( borsh) ] paused : Mask ) {
332
- self . assert_owner ( ) ;
333
- self . paused = paused;
334
- }
335
- }
323
+ admin_controlled:: impl_admin_controlled!( EthProver , paused) ;
You can’t perform that action at this time.
0 commit comments