|
|
|
@ -12,8 +12,6 @@ pragma solidity ^0.4.4; |
|
|
|
|
* use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by some number (specified in constructor) of the set of owners (specified in the constructor) before the interior is executed. |
|
|
|
|
*/ |
|
|
|
|
contract Shareable { |
|
|
|
|
// TYPES |
|
|
|
|
|
|
|
|
|
// struct for the status of a pending operation. |
|
|
|
|
struct PendingState { |
|
|
|
|
uint yetNeeded; |
|
|
|
@ -21,15 +19,11 @@ contract Shareable { |
|
|
|
|
uint index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIELDS |
|
|
|
|
|
|
|
|
|
// the number of owners that must confirm the same operation before it is run. |
|
|
|
|
uint public required; |
|
|
|
|
|
|
|
|
|
// list of owners |
|
|
|
|
uint[256] owners; |
|
|
|
|
uint constant c_maxOwners = 250; |
|
|
|
|
// index on the list of owners to allow reverse lookup |
|
|
|
|
mapping(uint => uint) ownerIndex; |
|
|
|
|
// the ongoing operations. |
|
|
|
@ -37,33 +31,28 @@ contract Shareable { |
|
|
|
|
bytes32[] pendingsIndex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// EVENTS |
|
|
|
|
|
|
|
|
|
// this contract only has six types of events: it can accept a confirmation, in which case |
|
|
|
|
// we record owner and operation (hash) alongside it. |
|
|
|
|
event Confirmation(address owner, bytes32 operation); |
|
|
|
|
event Revoke(address owner, bytes32 operation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MODIFIERS |
|
|
|
|
|
|
|
|
|
// simple single-sig function modifier. |
|
|
|
|
modifier onlyOwner { |
|
|
|
|
if (isOwner(msg.sender)) |
|
|
|
|
if (isOwner(msg.sender)) { |
|
|
|
|
_; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// multi-sig function modifier: the operation must have an intrinsic hash in order |
|
|
|
|
// that later attempts can be realised as the same underlying operation and |
|
|
|
|
// thus count as confirmations. |
|
|
|
|
modifier onlymanyowners(bytes32 _operation) { |
|
|
|
|
if (confirmAndCheck(_operation)) |
|
|
|
|
if (confirmAndCheck(_operation)) { |
|
|
|
|
_; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CONSTRUCTOR |
|
|
|
|
|
|
|
|
|
// constructor is given number of sigs required to do protected "onlymanyowners" transactions |
|
|
|
|
// as well as the selection of addresses capable of confirming them. |
|
|
|
|
function Shareable(address[] _owners, uint _required) { |
|
|
|
@ -76,14 +65,13 @@ contract Shareable { |
|
|
|
|
required = _required; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// METHODS |
|
|
|
|
|
|
|
|
|
// Revokes a prior confirmation of the given operation |
|
|
|
|
function revoke(bytes32 _operation) external { |
|
|
|
|
uint index = ownerIndex[uint(msg.sender)]; |
|
|
|
|
// make sure they're an owner |
|
|
|
|
if (index == 0) return; |
|
|
|
|
if (index == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
uint ownerIndexBit = 2**index; |
|
|
|
|
var pending = pendings[_operation]; |
|
|
|
|
if (pending.ownersDone & ownerIndexBit > 0) { |
|
|
|
@ -107,20 +95,22 @@ contract Shareable { |
|
|
|
|
uint index = ownerIndex[uint(_owner)]; |
|
|
|
|
|
|
|
|
|
// make sure they're an owner |
|
|
|
|
if (index == 0) return false; |
|
|
|
|
if (index == 0) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// determine the bit to set for this owner. |
|
|
|
|
uint ownerIndexBit = 2**index; |
|
|
|
|
return !(pending.ownersDone & ownerIndexBit == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// INTERNAL METHODS |
|
|
|
|
|
|
|
|
|
function confirmAndCheck(bytes32 _operation) internal returns (bool) { |
|
|
|
|
// determine what index the present sender is: |
|
|
|
|
uint index = ownerIndex[uint(msg.sender)]; |
|
|
|
|
// make sure they're an owner |
|
|
|
|
if (index == 0) return; |
|
|
|
|
if (index == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var pending = pendings[_operation]; |
|
|
|
|
// if we're not yet working on this operation, switch over and reset the confirmation status. |
|
|
|
@ -143,21 +133,21 @@ contract Shareable { |
|
|
|
|
delete pendingsIndex[pendings[_operation].index]; |
|
|
|
|
delete pendings[_operation]; |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
// not enough: record that this owner in particular confirmed. |
|
|
|
|
pending.yetNeeded--; |
|
|
|
|
pending.ownersDone |= ownerIndexBit; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// not enough: record that this owner in particular confirmed. |
|
|
|
|
pending.yetNeeded--; |
|
|
|
|
pending.ownersDone |= ownerIndexBit; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function clearPending() internal { |
|
|
|
|
uint length = pendingsIndex.length; |
|
|
|
|
for (uint i = 0; i < length; ++i) |
|
|
|
|
if (pendingsIndex[i] != 0) |
|
|
|
|
delete pendings[pendingsIndex[i]]; |
|
|
|
|
for (uint i = 0; i < length; ++i) { |
|
|
|
|
if (pendingsIndex[i] != 0) { |
|
|
|
|
delete pendings[pendingsIndex[i]]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
delete pendingsIndex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|