// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
// A contract that demonstrates the use of modifiers to enforce access control.
contract ContractWithModifier {
// State variable to store the owner's address.
address owner;
// Public state variable to store an integer value.
int public mydata;
// Constructor to initialize the contract.
// Sets the contract deployer as the owner.
constructor() {
owner = msg.sender;
}
// Modifier to restrict function access to the owner of the contract.
modifier isOwner {
// Checks if the message sender is the owner of the contract.
// Continues execution of the function if true.
if(msg.sender == owner) {
_; // Placeholder for the modified function's body.
}
}
// Function to assign double the input value to 'mydata'.
// Access is restricted to the owner by using the 'isOwner' modifier.
function AssignDoubleValue(int _data) public isOwner {
mydata = _data * 2;
}
// Public function to assign ten times the input value to 'mydata'.
// This function is accessible by any caller, not restricted to the owner.
function AssignTenerValue(int _data) public {
mydata = _data * 10;
}
}
//Deploy: