Created
October 30, 2022 06:07
-
-
Save shubham-kanodia/98f5489d65805dd6420b96e0d5bc182f to your computer and use it in GitHub Desktop.
Trivia #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.13; | |
contract A { | |
error InvalidOwnerOrNewAddress(address newOwner); | |
address public owner; | |
constructor() { | |
owner = msg.sender; | |
} | |
function changeOwner(address _newOwner) public { | |
// Only an owner can set a new owner | |
bool isOwner = (owner == msg.sender); | |
bool isNewOwnerValid = (_newOwner != address(0)); | |
if (isOwner && isNewOwnerValid) { | |
owner = _newOwner; | |
} | |
else { | |
revert InvalidOwnerOrNewAddress(_newOwner); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment