Trait near_contract_tools::owner::Owner
source · 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§
sourcefn slot_is_initialized() -> Slot<bool>
fn slot_is_initialized() -> Slot<bool>
Storage slot for initialization state
sourcefn slot_owner() -> Slot<AccountId>
fn slot_owner() -> Slot<AccountId>
Storage slot for owner account ID
sourcefn slot_proposed_owner() -> Slot<AccountId>
fn slot_proposed_owner() -> Slot<AccountId>
Storage slot for proposed owner account ID
sourcefn update_owner(&mut self, new: Option<AccountId>)
fn update_owner(&mut self, new: Option<AccountId>)
Updates the current owner and emits relevant event
sourcefn update_proposed(&mut self, new: Option<AccountId>)
fn update_proposed(&mut self, new: Option<AccountId>)
Updates proposed owner and emits relevant event
sourcefn update_owner_unchecked(&mut self, new: Option<AccountId>)
fn update_owner_unchecked(&mut self, new: Option<AccountId>)
Updates the current owner without any checks or emitting events
sourcefn update_proposed_unchecked(&mut self, new: Option<AccountId>)
fn update_proposed_unchecked(&mut self, new: Option<AccountId>)
Updates proposed owner without any checks or emitting events
sourcefn assert_owner(&self)
fn assert_owner(&self)
Same as require_owner but as a method
sourcefn init(&mut self, owner_id: &AccountId)
fn init(&mut self, owner_id: &AccountId)
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
}
}
sourcefn require_owner()
fn require_owner()
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();
// ...
}
}
sourcefn renounce_owner(&mut self)
fn renounce_owner(&mut self)
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.
sourcefn propose_owner(&mut self, account_id: Option<AccountId>)
fn propose_owner(&mut self, account_id: Option<AccountId>)
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
.
sourcefn accept_owner(&mut self)
fn accept_owner(&mut self)
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.