-
Notifications
You must be signed in to change notification settings - Fork 9
/
multiOwner.sol
131 lines (127 loc) · 4.07 KB
/
multiOwner.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
/*
multiOwner.sol
1.0.0
Rajci 'iFA' Andor @ [email protected] / [email protected]
CORION Platform
*/
pragma solidity ^0.4.15;
import "./safeMath.sol";
contract moduleMultiOwner {
/* Variables */
address public multiOwnerAddress;
mapping(bytes32 => address[]) public doDB;
/* Constructor */
function moduleMultiOwner(address _multiOwnerAddress) {
multiOwnerAddress = _multiOwnerAddress;
}
/* Internals */
function insertAndCheckDo(bytes32 doHash) internal returns (bool success) {
require( owners(msg.sender) );
if (doDB[doHash].length >= ownersForChange()) {
delete doDB[doHash];
return true;
}
for ( uint256 a=0 ; a<doDB[doHash].length ; a++ ) {
require( doDB[doHash][a] != msg.sender );
}
if ( doDB[doHash].length+1 >= ownersForChange() ) {
delete doDB[doHash];
return true;
} else {
doDB[doHash].push(msg.sender);
return false;
}
}
/* Constants */
function ownersForChange() public constant returns (uint256 owners) {
return multiOwner(multiOwnerAddress).ownersForChange();
}
function calcDoHash(string job, bytes32 data) public constant returns (bytes32 hash) {
return sha3(job, data);
}
function owners(address addr) public constant returns (bool valid) {
return multiOwner(multiOwnerAddress).owners(addr);
}
/* Modifiers */
modifier onlyOwner() {
/*
Only the owner is allowed to call it.
*/
require( owners(msg.sender) );
_;
}
}
contract multiOwner is safeMath {
/* Variables */
uint256 public ownerCount;
uint256 public constant doConfirmRate = 75;
mapping(address => bool) public owners;
mapping(bytes32 => address[]) public doDB;
/* Constructor */
function multiOwner(address[] newOwners) {
for ( uint256 a=0 ; a<newOwners.length ; a++ ) {
_addOwner(newOwners[a]);
}
}
/* Externals */
function insertOwner(address addr) external {
require( ! owners[addr]);
if ( insertAndCheckDo(calcDoHash("insertOwner", sha3(addr))) ) {
_addOwner(addr);
}
}
function dropOwner(address addr) external {
require( owners[addr]);
if ( insertAndCheckDo(calcDoHash("dropOwner", sha3(addr))) ) {
_delOwner(addr);
}
}
function cancelDo(bytes32 doHash) external {
if ( insertAndCheckDo(calcDoHash("cancelDo", doHash)) ) {
delete doDB[doHash];
}
}
/* Internals */
function insertAndCheckDo(bytes32 doHash) internal returns (bool success) {
require( owners[msg.sender] );
if (doDB[doHash].length >= ownersForChange()) {
delete doDB[doHash];
return true;
}
for ( uint256 a=0 ; a<doDB[doHash].length ; a++ ) {
require( doDB[doHash][a] != msg.sender );
}
if ( doDB[doHash].length+1 >= ownersForChange() ) {
delete doDB[doHash];
return true;
} else {
doDB[doHash].push(msg.sender);
return false;
}
}
/* Constants */
function ownersForChange() public constant returns (uint256 owners) {
return ownerCount * doConfirmRate / 100;
}
function calcDoHash(string job, bytes32 data) public constant returns (bytes32 hash) {
return sha3(job, data);
}
function validDoHash(bytes32 doHash) public constant returns (bool valid) {
return doDB[doHash].length > 0;
}
function hashAddress(address addr) public constant returns (bytes32 hash) {
return sha3(addr);
}
/* Privates */
function _addOwner(address addr) private {
if ( owners[addr] ) { return; }
owners[addr] = true;
ownerCount = safeAdd(ownerCount, 1);
}
function _delOwner(address addr) private {
if ( ! owners[addr] ) { return; }
require( ownerCount > 1 );
delete owners[addr];
ownerCount = safeSub(ownerCount, 1);
}
}