-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Ownership Library for better UX (#204)
## Type of change <!--Delete points that do not apply--> - Improvement (refactoring, restructuring repository, cleaning tech debt, ...) ## Changes The following changes have been made: - Swaps the need for declaring ownership in storage for a pre-defined `StorageKey` to store storage. This results in the following improvements in developer UX as the use of the library was previously very verbose. Before: ```sway storage { owner: Ownership = Ownership::initialized(Identity::Address(Address::from(ZERO_B256))), } fn foo() { let owner = storage.owner.owner(); storage.owner.only_owner(); storage.owner.renounce_ownership(); } ``` After: ```sway fn foo() { let owner = _owner(); only_owner(); renounce_ownership(); } ``` The downside to this approach is the inability to set the owner during compile time and a constructor must be implemented.
- Loading branch information
Showing
5 changed files
with
200 additions
and
317 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
library; | ||
|
||
/// Error log for when access is denied. | ||
pub enum AccessError { | ||
pub enum InitializationError { | ||
/// Emiited when an owner has already been set. | ||
CannotReinitialized: (), | ||
/// Emitted when the caller is not the owner of the contract. | ||
NotOwner: (), | ||
} |
Oops, something went wrong.