lever.sol 779 B

123456789101112131415161718192021222324252627282930
  1. @program_id("4wFN9As94uDgcBK9umEi6DNjRLi8gq7jaHwSw3829xq8")
  2. contract lever {
  3. // Switch state
  4. bool private isOn = true;
  5. @payer(payer) // payer for the data account
  6. constructor(address payer) {}
  7. // Switch the power on or off
  8. function switchPower(string name) public {
  9. // Flip the switch
  10. isOn = !isOn;
  11. // Print the name of the person who pulled the switch
  12. print("{:} is pulling the power switch!".format(name));
  13. // Print the current state of the switch
  14. if (isOn){
  15. print("The power is now on.");
  16. } else {
  17. print("The power is now off!");
  18. }
  19. }
  20. // Get the current state of the switch
  21. function get() public view returns (bool) {
  22. return isOn;
  23. }
  24. }