Module ownable

Module ownable 

Source
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:

  1. Initiating the ownership transfer by the current owner
  2. 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§

OwnableArgs
OwnableArgs is a type for building arg lists for functions defined in “Ownable”.
OwnableClient
OwnableClient is a client for calling the contract defined in “Ownable”.
OwnableSpec
OwnershipRenounced
Event emitted when ownership is renounced.
OwnershipTransfer
Event emitted when an ownership transfer is initiated.
OwnershipTransferCompleted
Event emitted when an ownership transfer is completed.

Enums§

OwnableError
OwnableStorageKey
Storage keys for Ownable utility.

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, or None if 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.