-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathMultiSigWallet.sol
165 lines (146 loc) · 4.46 KB
/
MultiSigWallet.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
155
156
157
158
159
160
161
162
163
164
165
pragma solidity ^0.4.0;
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <[email protected]>
contract MultiSigWallet {
event Confirmation(address sender, bytes32 transactionHash);
event Revocation(address sender, bytes32 transactionHash);
event Submission(address sender, bytes32 transactionHash);
event Execution(address sender, bytes32 transactionHash);
event Deposit(address sender, uint value);
event OwnerAddition(address owner);
event OwnerRemoval(address owner);
event RequiredUpdate(uint required);
mapping (bytes32 => Transaction) public transactions;
mapping (bytes32 => mapping (address => bool)) public confirmations;
mapping (address => bool) public isOwner;
address[] public owners;
uint public required;
struct Transaction {
address destination;
uint value;
bytes data;
uint nonce;
bool executed;
}
modifier onlyWallet() {
if (msg.sender != address(this))
throw;
_;
}
modifier ownerDoesNotExist(address owner) {
if (isOwner[owner])
throw;
_;
}
modifier ownerExists(address owner) {
if (!isOwner[owner])
throw;
_;
}
modifier maxRequired(address[] _owners, uint _required) {
if (_required > _owners.length)
throw;
_;
}
modifier notExecuted(bytes32 transactionHash) {
if (transactions[transactionHash].executed)
throw;
_;
}
function addOwner(address owner)
external
onlyWallet
ownerDoesNotExist(owner)
{
isOwner[owner] = true;
owners.push(owner);
OwnerAddition(owner);
}
function removeOwner(address owner)
external
onlyWallet
ownerExists(owner)
{
for (uint i=0; i<owners.length - 1; i++) {
if (owners[i] == owner)
isOwner[owner] = false;
if (!isOwner[owner])
owners[i] = owners[i+1];
}
owners.length -= 1;
if (required > owners.length)
required = owners.length;
OwnerRemoval(owner);
}
function updateRequired(uint _required)
external
onlyWallet
maxRequired(owners, _required)
{
required = _required;
RequiredUpdate(_required);
}
function confirmationCount(bytes32 transactionHash)
constant
public
returns (uint count)
{
for (uint i=0; i<owners.length; i++)
if (confirmations[transactionHash][owners[i]])
count += 1;
}
function submitTransaction(address destination, uint value, bytes data, uint nonce)
external
ownerExists(msg.sender)
notExecuted(sha3(destination, value, data, nonce))
returns (bytes32 transactionHash)
{
transactionHash = sha3(destination, value, data, nonce);
transactions[transactionHash] = Transaction({
destination: destination,
value: value,
data: data,
nonce: nonce,
executed: false
});
Submission(msg.sender, transactionHash);
confirmTransaction(transactionHash);
}
function confirmTransaction(bytes32 transactionHash)
public
ownerExists(msg.sender)
notExecuted(transactionHash)
{
confirmations[transactionHash][msg.sender] = true;
Confirmation(msg.sender, transactionHash);
if (confirmationCount(transactionHash) >= required) {
Transaction tx = transactions[transactionHash];
tx.executed = true;
if (!tx.destination.call.value(tx.value)(tx.data))
throw;
Execution(msg.sender, transactionHash);
}
}
function revokeConfirmation(bytes32 transactionHash)
external
ownerExists(msg.sender)
notExecuted(transactionHash)
{
confirmations[transactionHash][msg.sender] = false;
Revocation(msg.sender, transactionHash);
}
function MultiSigWallet(address[] _owners, uint _required)
maxRequired(_owners, _required)
{
for (uint i=0; i<_owners.length; i++)
isOwner[_owners[i]] = true;
required = _required;
owners = _owners;
}
function()
payable
{
if (msg.value > 0)
Deposit(msg.sender, msg.value);
}
}