-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathoneToManyMultiSig.sol
118 lines (108 loc) · 4.52 KB
/
oneToManyMultiSig.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
contract oneToManyMultiSig {
address copyRightRecordAddress;
address[] public owners;
uint public ownersCount;
struct terminateContractVote {
uint lastVoteStartTime;
address buyer;
address contractAddress;
uint upVoteCount;
mapping(address => bool) ifVoteUp;
}
address[] public buyers;
uint public buyersCount;
mapping(address => terminateContractVote) contracts;
function oneToManyMultiSig(address owner) {
copyRightRecordAddress = msg.sender;
owners.push(owner);
ownersCount = 1;
}
function restartAllStatus() internal {
for(uint i=0; i<buyersCount;i++) {
contracts[buyers[i]].lastVoteStartTime = 0;
contracts[buyers[i]].upVoteCount = 0;
for(uint j=0; j<ownersCount;j++) {
contracts[buyers[i]].ifVoteUp[owners[j]] = false;
}
}
}
function registerOwnership(address owner) {
if(msg.sender != copyRightRecordAddress) throw;
owners.push(owner);
ownersCount += 1;
restartAllStatus();
}
function transferOwnership(address newOwner) { //if msg.sender == newOwners, revoke msg.sender itself
if(msg.sender != copyRightRecordAddress) throw;
for(uint i=0; i<ownersCount;i++) {
if(owners[i] == msg.sender) break;
if(i == ownersCount-1) throw;
}
if(newOwner != msg.sender) {
owners.push(newOwner);
ownersCount += 1;
}
delete owners[i];
ownersCount -= 1;
restartAllStatus();
}
function newContract(address buyer, address contractAddr){
if(msg.sender != copyRightRecordAddress) throw;
buyers.push(buyer);
buyersCount += 1;
contracts[buyer] = terminateContractVote(0, buyer, contractAddr, 0);
for(uint i=0; i<ownersCount;i++) {
contracts[buyer].ifVoteUp[owners[i]] = false;
}
}
function inquireLastVoteStartTime(address buyer) returns (uint) {
if(contracts[buyer].buyer == buyer) return contracts[buyer].lastVoteStartTime;
else return 1; //wrong buyer address
}
function voteUp(address buyer, uint timeStamp) returns (uint) {
for(uint i=0; i<ownersCount;i++) {
if(owners[i] == msg.sender) break;
if(i == ownersCount-1) throw;
}
if(contracts[buyer].buyer != buyer) return 0; //no such buyer
if(contracts[buyer].lastVoteStartTime == timeStamp && timeStamp != 0) { //vote to a certain round
if(now - contracts[buyer].lastVoteStartTime >= 6 days) { //voteRound expired. ps:6 could be replaced
restartAllStatus();
return 0;
}
else {
if(contracts[buyer].ifVoteUp[msg.sender] == false) {
if(contracts[buyer].upVoteCount >= (ownersCount*2/3)-1) { //get enough vote, start termination
copyRightRecord con = copyRightRecord(copyRightRecordAddress);
if(con.terminateContract() == true) {
contracts[buyer].lastVoteStartTime = 0;
contracts[buyer].upVoteCount = 0;
for(uint j=0; j<ownersCount;j++) {
contracts[buyer].ifVoteUp[owners[j]] = false;
}
return 2; // complete termination
}
else return 0; // termination process aborted, the contract is either terminated or wrong buyer address
}
}
else return 1; //already vote up before
}
}
else if(contracts[buyer].lastVoteStartTime == timeStamp && timeStamp == 0){ // start a new round of vote
contracts[buyer].ifVoteUp[msg.sender] = true;
contracts[buyer].upVoteCount += 1;
contracts[buyer].lastVoteStartTime = now;
return contracts[buyer].lastVoteStartTime;
}
else {
if(contracts[buyer].lastVoteStartTime != 0) {
if(now - contracts[buyer].lastVoteStartTime >= 6 days) { //vote round expired
restartAllStatus();
return 0;
}
else return 0; //wrong timeStamp
}
else return 0; //vote round already expired and removed
}
}
}