-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EthConnector: make AdminControlled and pausable (#88)
* EthConnector: make AdminControlled and pausable. * EthConnector: add AdminControlled&pausability tests. * Stylystic fixes. * AdminControlled: add panic message when paused. * AdminControlled: minor refactoring. * AdminControlled: add errors. Naming improvements. * AdminControlled: doc improvements. * Test fixes. * Fix fmt * AdminControlled: make IO in main contract module. * AdminControlled:explicitly check panic msg in tests.
- Loading branch information
Showing
6 changed files
with
372 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::sdk; | ||
|
||
pub type PausedMask = u8; | ||
|
||
pub trait AdminControlled { | ||
/// Returns true if the current account is owner | ||
fn is_owner(&self) -> bool { | ||
sdk::current_account_id() == sdk::predecessor_account_id() | ||
} | ||
|
||
/// Return the current mask representing all paused events. | ||
fn get_paused(&self) -> PausedMask; | ||
|
||
/// Update mask with all paused events. | ||
/// Implementor is responsible for guaranteeing that this function can only be | ||
/// called by owner of the contract. | ||
fn set_paused(&mut self, paused: PausedMask); | ||
|
||
/// Return if the contract is paused for the current flag and user | ||
fn is_paused(&self, flag: PausedMask) -> bool { | ||
(self.get_paused() & flag) != 0 && !self.is_owner() | ||
} | ||
|
||
/// Asserts the passed paused flag is not set. Panics with "ERR_PAUSED" if the flag is set. | ||
fn assert_not_paused(&self, flag: PausedMask) { | ||
assert!(!self.is_paused(flag), "ERR_PAUSED"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.