-
Notifications
You must be signed in to change notification settings - Fork 6
/
DAO-V2.sol
154 lines (125 loc) · 3.99 KB
/
DAO-V2.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
pragma solidity ^0.4.18;
contract owned {
address public owner;
function owned() public{
owner = msg.sender;
}
modifier onlyOwner {
require (msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
owner = newOwner;
}
}
contract tokenRecipient {
event receivedEther(address sender, uint amount);
event receivedTokens(address _from, uint256 _value, address _token, bytes _extraData);
function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public{
Token t = Token(_token);
require (t.transferFrom(_from, this, _value));
receivedTokens(_from, _value, _token, _extraData);
}
function () payable public {
receivedEther(msg.sender, msg.value);
}
}
contract Token {
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
function transfer(address receiver, uint amount) public pure {
receiver = receiver;
amount = amount;
}
}
contract ContribData{
function set(bytes32 key, address recipient, uint amount, bytes32 desc, address token, bool executed, bool cancelled) public pure returns(bool success) {
}
function execute(bytes32 key) public pure{
key = key;
}
function cancel(bytes32 key) public pure{
key = key;
}
function isData(bytes32 key) public returns(bool yes) {
}
function getRecipient(bytes32 key) public returns(address _recipient){
}
function getAmount(bytes32 key) public returns(uint _amount){
}
function getExecuted(bytes32 key) public returns(bool _executed){
}
function getCancelled(bytes32 key) public returns(bool _cancelled){
}
function getToken(bytes32 key) public returns(address _token){
}
function isMember(address targetMember) public returns(bool _success) {
}
}
contract ContribDao is owned, tokenRecipient {
/* Contract Variables and events */
string public name;
ContribData private contribData;
address public addressOfContribData;
event ContributionAdded(bytes32 key, address recipient, uint amount, bytes32 desc, address token);
event ContributionTallied(bytes32 key);
/* First time setup */
function ContribDao(
string brandname,
address _addressOfContribData
) payable public {
name = brandname;
UpdateContribData(_addressOfContribData);
}
function UpdateContribData(address _addressOfContribData) public{
addressOfContribData = _addressOfContribData;
contribData = ContribData(addressOfContribData);
}
/* Function to create a new contribution */
function create(
bytes32 key,
address beneficiary,
uint amount,
bytes32 desc,
address tokenAddress
)
public onlyOwner
returns (bool success)
{
require(contribData.isMember(beneficiary) && !contribData.isData(key));
contribData.set(key, beneficiary, amount, desc, tokenAddress, false, false);
ContributionAdded(key, beneficiary, amount, desc, tokenAddress);
return true;
}
function execute(bytes32 key) public onlyOwner returns (bool success){
require(contribData.isData(key) && contribData.isMember(contribData.getRecipient(key)));
require(!contribData.getExecuted(key) && !contribData.getCancelled(key));
if(contribData.getToken(key)==address(0)){
require(contribData.getRecipient(key).call.value(contribData.getAmount(key) * 1 ether)());
}else{
Token t = Token(contribData.getToken(key));
t.transfer(contribData.getRecipient(key), contribData.getAmount(key));
}
contribData.execute(key);
// Fire Events
ContributionTallied(key);
return true;
}
function createExecute(
bytes32 key,
address beneficiary,
uint amount,
bytes32 desc,
address tokenAddress
)
public onlyOwner
returns (bool success)
{
if(create(key, beneficiary, amount, desc, tokenAddress))
execute(key);
return true;
}
function cancel(bytes32 key) public onlyOwner {
require(contribData.isData(key));
contribData.cancel(key);
}
}