Ownership
This template is used in many contracts whenever there needs a special address to administrate the contract. The ownership of the contract may be transferred.
Code
info
It is required to copy this code in the created contract to benefit from the ownership pattern.
/* OWNERSHIP TRANSFER ------------------------------------------------------- */
variable owner_candidate : option<address> = none
entry declare_ownership(candidate : address) {
called by owner
effect {
owner_candidate := some(candidate);
}
}
entry claim_ownership() {
require {
ownership_r1: (owner_candidate ? the = caller : false) otherwise "INVALID_CALLER"
}
effect {
owner := caller;
owner_candidate := none
}
}
variable
option
address
none
entry
require
?:
effect
:=
caller
none
address
called by
some
Storage
owner
Contract parameter for the contract owner.
It is typically used to protect an entrypoint against other callers with a called by
section:
entry exec() {
called by owner
/* ... */
}
Code
archetype my_contract(owner : address)
Type
Related
owner_candidate
Variable used during transfer of ownership to store the owner candidate address.
Code
variable owner_candidate : option<address> = none
Type
Related
Entrypoints
declare_candidate(candidate)
Declares a condidate address to be the contract's owner.
Code
entry declare_ownership(candidate : address) {
called by owner
effect {
owner_candidate := some(candidate);
}
}
Parameter
claim_candidate()
Declared candidate calls this method to confirm it is the new contract owner.
Code
entry claim_ownership() {
require {
ownership_r1: (owner_candidate ? the = caller : false) otherwise "INVALID_CALLER"
}
effect {
owner := caller;
owner_candidate := none
}
}