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§
Sourcefn get_owner(e: &Env) -> Option<Address>
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.
Sourcefn transfer_ownership(e: &Env, new_owner: Address, live_until_ledger: u32)
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 of0cancels any pending transfer.
§Errors
OwnableError::OwnerNotSet- If the owner is not set.crate::role_transfer::RoleTransferError::NoPendingTransfer- If trying to cancel a transfer that doesn’t exist.crate::role_transfer::RoleTransferError::InvalidLiveUntilLedger- If the specified ledger is in the past.crate::role_transfer::RoleTransferError::InvalidPendingAccount- If the specified pending account is not the same as the providednewaddress.
§Notes
- Authorization for the current owner is required.
Sourcefn accept_ownership(e: &Env)
fn accept_ownership(e: &Env)
Accepts a pending ownership transfer.
§Arguments
e- Access to the Soroban environment.
§Errors
crate::role_transfer::RoleTransferError::NoPendingTransfer- If there is no pending transfer to accept.
§Events
- topics -
["ownership_transfer_completed"] - data -
[new_owner: Address]
Sourcefn renounce_ownership(e: &Env)
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
OwnableError::TransferInProgress- If there is a pending ownership transfer.OwnableError::OwnerNotSet- If the owner is not set.
§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.