Created
April 4, 2022 11:08
-
-
Save sagar-barapatre/0a309439845abe84b08f9397a8428392 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
This file contains 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
pragma solidity ^0.6.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol"; | |
contract Allowance is Ownable { | |
using SafeMath for uint; | |
event AllowanceChanged(address indexed _forWho, address indexed _byWhom, uint _oldAmount , uint _newAmount); | |
mapping(address => uint) public allowance; | |
function setAllowance(address _who, uint _amount) public onlyOwner { | |
emit AllowanceChanged(_who, msg.sender, allowance[_who], _amount); allowance[_who] = _amount; | |
} | |
modifier ownerOrAllowed(uint _amount) { | |
require(msg.sender == owner() || allowance[msg.sender] >= _amount, "You are not allowed!"); | |
_; | |
} | |
function reduceAllowance(address _who, uint _amount) internal ownerOrAllowed(_amount) { | |
emit AllowanceChanged(_who, msg.sender, allowance[_who], allowance[_who].sub(_amount | |
)); | |
} | |
function renounceOwnership() public override onlyOwner { | |
revert("can't renounceOwnership here"); //not possible with this smart contract | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment