Reference
@stdlib/stoppable

@stdlib/stoppable

Provides traits that allow to stop a contract. Useful for emergency or maintenance modes. Requires an Ownable trait from @stdlib/ownable. This trait just manages a single flag stopped in the contract and handling stopped state have to 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 receiver for the Message string "Stop" that can be sent by owner, implements stopped() getter function that returns true if 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

Resumable trait extends Stoppable trait and allows to resume 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