fisco bcos solidity destroys the contract and deletes the contract

1. There is a selfdestruct instruction in the bytecode to destroy the contract. So just expose the self-destruct interface:

contract Mortal{
 //自毁 
function destroy() public{
 selfdestruct(msg.sender);
 } 
}

2.Automatic Deprecation-Allow the contract to automatically stop the service

If you want a contract to stop service after a specified period without manual intervention, you can use the Automatic Deprecation mode.

contract AutoDeprecated{

    uint private _deadline;

    function setDeadline(uint time) public {
        _deadline = time;
    }

    modifier notExpired(){
        require(now <= _deadline);
        _;
    }

    function service() public notExpired{ 
        //some code    
    } 
}

When the user calls the service, the notExpired modifier will first check the date, so that once a certain time has passed, the call will be blocked at the notExpired layer due to expiration.

ps: Before the contract is deployed, only the above-mentioned functions can be built-in before it can be triggered manually or periodically to trigger the destruction. Otherwise, the deployed contract will run permanently in the system.

Guess you like

Origin blog.csdn.net/ws327443752/article/details/108602296