Skip to main content

Pausable

This template is used in many contracts whenever there needs to be able to pause entrypoints. It requires the Ownership template.

Repository


Author


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​

Contract's pausable state.

Code


variable paused : bool = false

variable bool

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
}

function do_fail_if

Returns


true if contract is not paused

Fails with

"CONTRACT_PAUSED"

When contract is already paused.


Related

Entrypoints​

pause()​

Pauses contract when unpaused.

Code


entry pause() {
called by owner
require {
pausable_r1: is_not_paused()
}
effect {
paused := true
}
}

entry called by require effect :=

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
}
}

entry called by require effect :=

Fails with

"INVALID_CALLER"

When caller is not owner


"CONTRACT_NOT_PAUSED"

When contract is not paused.


Related