-
Notifications
You must be signed in to change notification settings - Fork 15
/
SimpleMultiSig.sol
51 lines (47 loc) · 1.39 KB
/
SimpleMultiSig.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
contract SimpleMultiSig {
address alice1;
address alice2;
address bob;
uint numSigned = 0;
bytes32 error;
bool registeredYet;
mapping (address => bool) signedYet;
function SimpleMultiSig() {
bob = msg.sender;
registeredYet = false;
}
function register(address registerAlice1, address registerAlice2) {
if (msg.sender == bob && registeredYet == false) {
alice1 = registerAlice1;
alice2 = registerAlice2;
registeredYet = true;
} else if (msg.sender == bob) {
error = "registered already";
} else {
error = "you are not bob!";
}
}
function withdraw(address to) {
if ((msg.sender == alice1 || msg.sender == alice2) && numSigned >= 2) {
to.send(this.balance);
numSigned = 0;
signedYet[alice1] = signedYet[alice2] = signedYet[bob] = false;
} else {
error = "cannot withdraw yet!";
}
}
function addSignature() {
if (msg.sender == alice1 && signedYet[alice1]==false) {
signedYet[alice1] = true;
numSigned++;
} else if (msg.sender == alice2 && signedYet[alice2]==false) {
signedYet[alice2] = true;
numSigned++;
} else if (msg.sender == bob && signedYet[bob]==false) {
signedYet[bob] = true;
numSigned++;
} else {
error = 'unknown address';
}
}
}