Pausable
This template is used in many contracts whenever there needs to be able to pause entrypoints. It requires the Ownership
template.
Code
info
It is required to copy this code in the created contract to benefit from the pausable pattern.
/* PAUSABLE ---------------------------------------------------------------- */
variable paused : bool = false
function is_not_paused() : bool {
do_fail_if(paused, "CONTRACT_PAUSED");
return true
}
entry pause() {
called by owner
require {
pausable_r1: is_not_paused()
}
effect {
paused := true
}
}
entry unpause() {
called by owner
require {
pausable_r2: paused otherwise "CONTRACT_NOT_PAUSED"
}
effect {
paused := false
}
}
variable
bool
entry
called by
require
effect
:=
function
do_fail_if
Storage
paused
Type
Related
Functions
is_not_paused()
Utility function to call in require
section of entrypoints, like in pause()
entrypoint below for example.
Code
function is_not_paused() : bool {
do_fail_if(paused, "CONTRACT_PAUSED");
return true
}
Returns
Entrypoints
pause()
Pauses contract when unpaused.
Code
entry pause() {
called by owner
require {
pausable_r1: is_not_paused()
}
effect {
paused := true
}
}
Fails with
"INVALID_CALLER"
When
caller
is not owner
"CONTRACT_PAUSED"
When contract is already paused.
Related
unpause()
Unpauses contract when paused.
Code
entry unpause() {
called by owner
require {
pausable_r2: paused otherwise "CONTRACT_NOT_PAUSED"
}
effect {
paused := false
}
}
Fails with
"INVALID_CALLER"
When
caller
is not owner
"CONTRACT_NOT_PAUSED"
When contract is not paused.
Related