// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
// This contract demonstrates basic access control without using modifiers.
// It restricts certain actions to only the owner of the contract, but does so
// directly in the function bodies instead of using a reusable modifier.
contract ContractWithoutModifier {
// State variable to store the owner's address. The owner is set
// to the address that deploys the contract.
address owner;
// Public state variable to store an integer value. This value can be
// modified by the contract's functions, under certain conditions.
int public mydata;
// Constructor that runs once upon contract deployment.
// It sets the deploying address as the owner of the contract.
constructor() {
owner = msg.sender;
}
// Function to double the input value and assign it to 'mydata',
// but only if the caller is the owner of the contract.
// This function demonstrates a pattern of inline access control,
// checking the sender's address directly within the function body.
function AssignDoubleValue(int _data) public {
if(msg.sender == owner) {
mydata = _data * 2;
}
// If the caller is not the owner, this function does nothing.
// In a real-world scenario, it might be better to give feedback
// (e.g., by reverting the transaction) when unauthorized callers attempt this action.
}
// Function to multiply the input value by ten and assign it to 'mydata',
// with the same ownership check as in AssignDoubleValue.
// This function further demonstrates direct access control without modifiers.
function AssignTenerValue(int _data) public {
if(msg.sender == owner) {
mydata = _data * 10;
}
// Similar to AssignDoubleValue, this function also silently ignores calls
// from non-owner addresses, which may not be the best practice for access control.
}
}
//Deploy: