Circuit Break Pattern in Solidity

In the live contract there are many chances we find an type of error and we have to stop smart contract to handle malicious activity. here is the sample of Circuit Break Pattern.

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract circutBreakPattern{
    
    address owner;
    
    bool private stopped = false;
    
    constructor(){
        owner = msg.sender;
    }
    
    modifier onlyOwner(){
        require(msg.sender == owner, "Only Owner is Allowed");
        _;
    }
    
    modifier stopInEmergency(){
        if(!stopped)
        _;
    }
    
    modifier onlyInEmergency(){
        if(stopped)
        _;
    }
    
    function toggleContractAction() public onlyOwner{
        stopped = !stopped;
    }
    
    function deposit()public  stopInEmergency {
        
    }
    
    function withdraw() public onlyInEmergency {
        
    }
}

By Shabair

Frontend | Blockchain | Smart Contract Developer