Ownable

Trait Ownable 

Source
pub trait Ownable {
    // Provided methods
    fn get_owner(e: &Env) -> Option<Address> { ... }
    fn transfer_ownership(e: &Env, new_owner: Address, live_until_ledger: u32) { ... }
    fn accept_ownership(e: &Env) { ... }
    fn renounce_ownership(e: &Env) { ... }
}
Expand description

A trait for managing contract ownership using a 2-step transfer pattern.

Provides functions to query ownership, initiate a transfer, or renounce ownership.

Provided Methods§

Source

fn get_owner(e: &Env) -> Option<Address>

Returns Some(Address) if ownership is set, or None if ownership has been renounced.

§Arguments
  • e - Access to the Soroban environment.
Source

fn transfer_ownership(e: &Env, new_owner: Address, live_until_ledger: u32)

Initiates a 2-step ownership transfer to a new address.

Requires authorization from the current owner. The new owner must later call accept_ownership() to complete the transfer.

§Arguments
  • e - Access to the Soroban environment.
  • new_owner - The proposed new owner.
  • live_until_ledger - Ledger number until which the new owner can accept. A value of 0 cancels any pending transfer.
§Errors
§Notes
  • Authorization for the current owner is required.
Source

fn accept_ownership(e: &Env)

Accepts a pending ownership transfer.

§Arguments
  • e - Access to the Soroban environment.
§Errors
§Events
  • topics - ["ownership_transfer_completed"]
  • data - [new_owner: Address]
Source

fn renounce_ownership(e: &Env)

Renounces ownership of the contract.

Permanently removes the owner, disabling all functions gated by #[only_owner].

§Arguments
  • e - Access to the Soroban environment.
§Errors
§Notes
  • Authorization for the current owner is required.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§