-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllowance.sol
More file actions
30 lines (20 loc) · 1.06 KB
/
Allowance.sol
File metadata and controls
30 lines (20 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0-beta.0/contracts/ownership/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0-beta.0/contracts/math/SafeMath.sol";
contract Allowance is Ownable {
using SafeMath for uint;
event AllowanceChanged( address indexed _forWho, address indexed _fromWhom, uint _oldAmount, uint _newAmount);
mapping (address => uint) public allowance;
function addAllowance(address _who, uint _amount) public onlyOwner {
emit AllowanceChanged(_who, msg.sender, allowance[_who], _amount);
allowance[_who] = _amount;
}
modifier ownerOrAllowed(uint _amount) {
require(isOwner() || allowance[msg.sender] >= _amount, "You are not allowed" );
_;
}
function reduceAllowance(address _who, uint _amount) internal {
emit AllowanceChanged(_who, msg.sender, allowance[_who], allowance[_who].sub(_amount));
allowance[_who] = allowance[_who].sub(_amount);
}
}