pragma solidity ^0.8.11;
contract Owned {
address owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "You are not allowed");
_;
}
}
contract InheritanceModifierExample is Owned {
mapping(address => uint) public tokenBalance;
uint tokenPrice = 1 ether;
constructor() public {
tokenBalance[owner] = 100;
}
function createNewToken() public onlyOwner{
// require statement is originally here
tokenBalance[owner]++;
}
function burnToken() public onlyOwner{
// require statement is originally here
tokenBalance[owner]--;
}
function purchaseToken() public payable {
require((tokenBalance[owner] * tokenPrice) / msg.value > 0, "not enoug
h tokens");
tokenBalance[owner] -= msg.value / tokenPrice;
tokenBalance[msg.sender] += msg.value / tokenPrice;
}
function sendToken(address _to, uint _amount) public {
require(tokenBalance[msg.sender] >= _amount, "Not enough tokens");
assert(tokenBalance[_to] + _amount >= tokenBalance[_to]);
assert(tokenBalance[msg.sender] - _amount <= tokenBalance[msg.sender])
;
tokenBalance[msg.sender] -= _amount;
tokenBalance[_to] += _amount;
}
}