-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharedWallet.sol
53 lines (37 loc) · 1.62 KB
/
SharedWallet.sol
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pragma solidity ^0.8.1;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/ConsenSysMesh/openzeppelin-solidity/blob/master/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;
modifier ownerOrAllowed(uint _amount){
require(isOwner() || allowance[msg.sender] >= _amount, 'You are not allowed');
_;
}
function addAllowance(address _who, uint _amount) public onlyOwner{
emit AllowanceChanged(_who, msg.sender, allowance[_who], _amount);
allowance[_who] = SafeMath.add(allowance[_who], _amount);
}
function isOwner() internal view returns (bool) {
return owner() == msg.sender;
}
function reduceAllowance(address _who, uint _amount) internal {
emit AllowanceChanged(_who, msg.sender, allowance[_who], allowance[_who] - _amount);
allowance[_who] = SafeMath.sub(allowance[_who], _amount);
}
}
contract ShareWallet is Allowance {
function withdrawMoney(address payable _to, uint _amount) public ownerOrAllowed(_amount){
require(_amount <= address(this).balance, "There is not enough balance");
if(!isOwner()){
reduceAllowance(msg.sender, _amount);
}
_to.transfer(_amount);
}
function renounceOwnership() public {
revert("Could not renounce ownership here");
}
receive () external payable {
}
}