...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Wednesday, April 4, 2018

Solidity Tips and Tricks - debug mode with simple switch


Well, designing a smart contract is pretty tricky, basically the contract is immutable so basically it is not upgradable, even if you use some direct patterns for update. So what you can basically do is to build in some debug functionalities, like getting extra debug information or updating parts of the system in a debug mode... The most simple way how you can control such a debug mode is to have a bool switch called debugMode that can be set true only once at the go live causing that the debug functionalities will not be accessible anymore. An example can be seen on the following code:

contract TestDebugMode {
    
 bool public debugMode = true ; 
    
   function goLive(){
      debugMode = false;
   }

   modifier isInDebug(){
      require(debugMode == true);        
      _;
   }

   function onlyInDebug() isInDebug {

   }
}

Certainly, a real smart code might be somewhat more difficult, as it has to be guaranteed that only an owner or an administrator can deactivate the debug mode by going live.