-
Notifications
You must be signed in to change notification settings - Fork 3
/
tipbot.sol
95 lines (71 loc) · 2.04 KB
/
tipbot.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
pragma solidity ^0.4.18;
contract Owned {
modifier onlyOwner {
require(msg.sender == owner);
_;
}
event NewOwner(address indexed old, address indexed current);
function setOwner(address _new) onlyOwner public {
NewOwner(owner, _new);
owner = _new;
}
address public owner = 0x01ff0FFd25B64dE2217744fd7d4dc4aA3cAbceE7;
}
contract Delegated is Owned {
modifier onlyDelegate {
require(msg.sender == delegate);
_;
}
event NewDelegate(address indexed old, address indexed current);
function setDelegate(address _new) onlyOwner public {
NewDelegate(delegate, _new);
delegate = _new;
}
address public delegate = address(0);
}
contract TipFactory is Delegated {
mapping(address => bool) users;
event NewTipUser(address indexed user);
function isTipUser(address _user) constant public returns (bool) {
return users[_user];
}
function newTipUser() onlyDelegate public returns (address) {
TipUser _user = new TipUser(this);
users[address(_user)] = true;
NewTipUser(address(_user));
return address(_user);
}
}
contract TipUser {
TipFactory public factory;
address public withdrawAddress = address(0);
modifier onlyDelegate {
require(msg.sender == factory.delegate());
_;
}
function TipUser(TipFactory _factory) public {
factory = _factory;
}
function() payable public {
if (msg.value == 0 && msg.sender == withdrawAddress) {
require(withdrawAddress != address(0));
withdrawAddress.transfer(address(this).balance);
}
}
function setWithdrawAddress(address _withdrawAddress) onlyDelegate public {
require(withdrawAddress == address(0));
withdrawAddress = _withdrawAddress;
}
function changeWithdrawAddress(address _withdrawAddress) onlyDelegate public {
require(withdrawAddress != address(0));
withdrawAddress = _withdrawAddress;
}
function withdraw(uint _amount) onlyDelegate public {
require(withdrawAddress != address(0));
withdrawAddress.transfer(_amount);
}
function transfer(address _to, uint _amount) onlyDelegate public {
require(factory.isTipUser(_to));
_to.transfer(_amount);
}
}