Skip to content

@stdlib/stoppable

Provides traits that allow stopping a contract. Useful for emergency or maintenance modes. Requires an Ownable trait from @stdlib/ownable. This trait manages a single flag stopped in the contract, and handling the stopped state must be done in the contract itself.

To use this library, import @stdlib/stoppable:

import "@stdlib/stoppable"; // this would automatically import @stdlib/ownable too!

Traits

Stoppable

Trait Stoppable implements a receiver for the Message string “Stop” that can be sent by the owner. It implements the stopped() getter function that returns true if the contract is stopped (or false otherwise) and provides private (non-getter) functions requireNotStopped() and requireStopped().

Source code:

@interface("org.ton.stoppable")
trait Stoppable with Ownable {
stopped: Bool;
owner: Address;
fun requireNotStopped() {
require(!self.stopped, "Contract stopped");
}
fun requireStopped() {
require(self.stopped, "Contract not stopped");
}
receive("Stop") {
self.requireOwner();
self.requireNotStopped();
self.stopped = true;
self.reply("Stopped".asComment());
}
get fun stopped(): Bool {
return self.stopped;
}
}

Usage example:

import "@stdlib/ownable";
import "@stdlib/stoppable";
contract MyContract with Stoppable {
owner: Address;
stopped: Bool;
init(owner: Address) {
self.owner = owner;
self.stopped = false;
}
}

Resumable

The Resumable trait extends the Stoppable trait and allows resuming contract execution.

Source code:

@interface("org.ton.resumable")
trait Resumable with Stoppable {
stopped: Bool;
owner: Address;
receive("Resume") {
self.requireOwner();
self.requireStopped();
self.stopped = false;
self.reply("Resumed".asComment());
}
}

Usage example:

import "@stdlib/ownable";
import "@stdlib/stoppable";
contract MyContract with Resumable {
owner: Address;
stopped: Bool;
init(owner: Address) {
self.owner = owner;
self.stopped = false;
}
}

Sources