pub trait Owner {
Show 14 methods fn root() -> Slot<()> { ... } fn slot_is_initialized() -> Slot<bool> { ... } fn slot_owner() -> Slot<AccountId> { ... } fn slot_proposed_owner() -> Slot<AccountId> { ... } fn update_owner(&mut self, new: Option<AccountId>) { ... } fn update_proposed(&mut self, new: Option<AccountId>) { ... } fn update_owner_unchecked(&mut self, new: Option<AccountId>) { ... } fn update_proposed_unchecked(&mut self, new: Option<AccountId>) { ... } fn assert_owner(&self) { ... } fn init(&mut self, owner_id: &AccountId) { ... } fn require_owner() { ... } fn renounce_owner(&mut self) { ... } fn propose_owner(&mut self, account_id: Option<AccountId>) { ... } fn accept_owner(&mut self) { ... }
}
Expand description

A contract with an owner

Provided Methods§

Storage root

Storage slot for initialization state

Storage slot for owner account ID

Storage slot for proposed owner account ID

Updates the current owner and emits relevant event

Updates proposed owner and emits relevant event

Updates the current owner without any checks or emitting events

Updates proposed owner without any checks or emitting events

Same as require_owner but as a method

Initializes the contract owner. Can only be called once.

Emits an OwnerEvent::Transfer event.

Examples
use near_sdk::{AccountId, near_bindgen};
use near_contract_tools::{Owner, owner::Owner};

#[derive(Owner)]
#[near_bindgen]
struct Contract {}

#[near_bindgen]
impl Contract {
    pub fn new(owner_id: AccountId) -> Self {
        let mut contract = Self {};

        Owner::init(&mut contract, &owner_id);

        contract
    }
}

Requires the predecessor to be the owner

Examples
use near_sdk::{AccountId, near_bindgen};
use near_contract_tools::{Owner, owner::Owner};

#[derive(Owner)]
#[near_bindgen]
struct Contract {}

#[near_bindgen]
impl Contract {
    pub fn owner_only(&self) {
        Self::require_owner();

        // ...
    }
}

Removes the contract’s owner. Can only be called by the current owner.

Emits an OwnerEvent::Transfer event, and an OwnerEvent::Propose event if there is a currently proposed owner.

Prepares the contract to change owners, setting the proposed owner to the provided account ID. Can only be called by the current owner.

Emits an OwnerEvent::Propose event.

The currently proposed owner may be reset by calling this function with the argument None.

Sets new owner equal to proposed owner. Can only be called by proposed owner.

Emits events corresponding to the transfer of ownership and reset of the proposed owner.

Implementors§