Expand description
§Ownable Contract Module.
This module introduces a simple access control mechanism where a contract has an account (owner) that can be granted exclusive access to specific functions.
The Ownable trait exposes methods for:
- Getting the current owner
- Transferring ownership
- Renouncing ownership
The helper enforce_owner_auth() is available to restrict access to only
the owner. You can also use the #[only_owner] macro (provided elsewhere)
to simplify this.
ⓘ
#[only_owner]
fn set_config(e: &Env, new_config: u32) { ... }See examples/ownable/src/contract.rs for a working example.
§Note
The ownership transfer is processed in 2 steps:
- Initiating the ownership transfer by the current owner
- Accepting the ownership by the designated owner
Not providing a direct ownership transfer is a deliberate design decision to help avoid mistakes by transferring to a wrong address.
Structs§
- Ownable
Args - OwnableArgs is a type for building arg lists for functions defined in “Ownable”.
- Ownable
Client - OwnableClient is a client for calling the contract defined in “Ownable”.
- Ownable
Spec - Ownership
Renounced - Event emitted when ownership is renounced.
- Ownership
Transfer - Event emitted when an ownership transfer is initiated.
- Ownership
Transfer Completed - Event emitted when an ownership transfer is completed.
Enums§
- Ownable
Error - Ownable
Storage Key - Storage keys for
Ownableutility.
Statics§
- __
SPEC_ XDR_ EVENT_ OWNERSHIPRENOUNCED - __
SPEC_ XDR_ EVENT_ OWNERSHIPTRANSFER - __
SPEC_ XDR_ EVENT_ OWNERSHIPTRANSFERCOMPLETED - __
SPEC_ XDR_ TYPE_ OWNABLEERROR
Traits§
- Ownable
- A trait for managing contract ownership using a 2-step transfer pattern.
Functions§
- accept_
ownership - Completes the 2-step ownership transfer process.
- emit_
ownership_ renounced - Emits an event when ownership is renounced.
- emit_
ownership_ transfer - Emits an event when an ownership transfer is initiated.
- emit_
ownership_ transfer_ completed - Emits an event when an ownership transfer is completed.
- enforce_
owner_ auth - Enforces authorization from the current owner.
- get_
owner - Returns
Some(Address)if ownership is set, orNoneif ownership has been renounced or has never been set. - renounce_
ownership - Renounces ownership of the contract.
- set_
owner - Sets owner role.
- transfer_
ownership - Initiates a 2-step ownership transfer to a new owner.