Module near_contract_tools::owner
source · Expand description
Owner pattern implements methods to query, manage and transfer ownership of the contract.
The account that owns the contract is called the “current” owner. A contract is always initialized with an owner account. The current owner can propose an ownership transfer to a different account. This proposed account is the “proposed owner”. If the proposed owner accepts the transfer, it becomes the current owner. The current owner can also renounce ownership of the contract.
The owner of the contract may be initialized once (e.g. at contract
creation) using Owner::init
.
Note: There is no way to recover ownership of a renounced contract.
The pattern consists of methods in Owner
and OwnerExternal
. The
latter exposes methods externally and can be called by other contracts.
This derive macro
derives default implementation both these traits.
Safety
The default implementation assumes or enforces the following invariants. Violating assumed invariants may corrupt contract state and show unexpected behavior (UB). Enforced invariants throw an error (ERR) but contract state remains intact.
- (UB) The owner root storage slot is not used or modified. The default key is
~o
. - (ERR)
Owner::init
may be called a maximum of one time. - (ERR) Only the current owner can call
Owner::renounce_owner
andOwner::propose_owner
. - (ERR) Only the proposed owner can call
Owner::accept_owner
. - (ERR) The external functions exposed in
OwnerExternal
call their respectiveOwner
methods and expect the same invariants.
Modules
Enums
Traits
Owner