cleanup
This commit is contained in:
parent
b3fe5072a1
commit
3cc0c36186
|
@ -0,0 +1,12 @@
|
|||
pragma solidity ^0.4.15;
|
||||
|
||||
contract ERC20 {
|
||||
uint256 public totalSupply;
|
||||
function balanceOf(address who) constant returns (uint256);
|
||||
function allowance(address owner, address spender) constant returns (uint256);
|
||||
function transfer(address to, uint256 value) returns (bool ok);
|
||||
function transferFrom(address from, address to, uint256 value) returns (bool ok);
|
||||
function approve(address spender, uint256 value) returns (bool ok);
|
||||
event Transfer(address indexed from, address indexed to, uint256 value);
|
||||
event Approval(address indexed owner, address indexed spender, uint256 value);
|
||||
}
|
|
@ -6,7 +6,7 @@ contract MultiSigFactory {
|
|||
|
||||
event Create(address indexed caller, address createdContract);
|
||||
|
||||
function create(address[] owners, uint256 required) returns (address wallet){
|
||||
function create(address[] owners, uint256 required) returns (address wallet) {
|
||||
wallet = new MultiSigStub(owners, required);
|
||||
Create(msg.sender, wallet);
|
||||
}
|
||||
|
|
|
@ -20,32 +20,32 @@ contract MultiSigStub {
|
|||
}
|
||||
|
||||
function MultiSigStub(address[] _owners, uint256 _required) {
|
||||
//bytes4 sig = bytes4(sha3("Constructor(address[],uint256)"));
|
||||
bytes4 sig = 0xe0c4e63b;
|
||||
//bytes4 sig = bytes4(sha3("constructor(address[],uint256)"));
|
||||
bytes4 sig = 0x36756a23;
|
||||
uint argarraysize = (2 + _owners.length);
|
||||
uint argsize = (1 + argarraysize) * 32;
|
||||
uint size = 4 + argsize;
|
||||
bytes32 m_data = _malloc(size);
|
||||
bytes32 mData = _malloc(size);
|
||||
|
||||
assembly {
|
||||
mstore(m_data, sig)
|
||||
codecopy(add(m_data, 0x4), sub(codesize, argsize), argsize)
|
||||
mstore(mData, sig)
|
||||
codecopy(add(mData, 0x4), sub(codesize, argsize), argsize)
|
||||
}
|
||||
_delegatecall(m_data, size);
|
||||
_delegatecall(mData, size);
|
||||
}
|
||||
|
||||
modifier delegated {
|
||||
uint size = msg.data.length;
|
||||
bytes32 m_data = _malloc(size);
|
||||
bytes32 mData = _malloc(size);
|
||||
|
||||
assembly {
|
||||
calldatacopy(m_data, 0x0, size)
|
||||
calldatacopy(mData, 0x0, size)
|
||||
}
|
||||
|
||||
bytes32 m_result = _delegatecall(m_data, size);
|
||||
bytes32 mResult = _delegatecall(mData, size);
|
||||
_;
|
||||
assembly {
|
||||
return(m_result, 0x20)
|
||||
return(mResult, 0x20)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ contract MultiSigStub {
|
|||
|
||||
}
|
||||
|
||||
function watch(address _tokenAddr, bytes _data)
|
||||
function watch(address _tokenAddr)
|
||||
public
|
||||
delegated
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ contract MultiSigStub {
|
|||
/*
|
||||
* Web3 call functions
|
||||
*/
|
||||
function tokenBalances(address)
|
||||
function tokenBalances(address tokenAddress)
|
||||
public
|
||||
constant
|
||||
delegated
|
||||
|
@ -165,14 +165,16 @@ contract MultiSigStub {
|
|||
address[] memory confirmationsTemp = new address[](owners.length);
|
||||
uint count = 0;
|
||||
uint i;
|
||||
for (i=0; i<owners.length; i++)
|
||||
for (i = 0; i < owners.length; i++) {
|
||||
if (confirmations[transactionId][owners[i]]) {
|
||||
confirmationsTemp[count] = owners[i];
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
_confirmations = new address[](count);
|
||||
for (i=0; i<count; i++)
|
||||
for (i = 0; i < count; i++) {
|
||||
_confirmations[i] = confirmationsTemp[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Returns list of transaction IDs in defined range.
|
||||
|
@ -186,43 +188,42 @@ contract MultiSigStub {
|
|||
constant
|
||||
returns (uint[] _transactionIds)
|
||||
{
|
||||
uint total = transactionCount;
|
||||
uint[] memory transactionIdsTemp = new uint[](total);
|
||||
uint[] memory transactionIdsTemp = new uint[](transactionCount);
|
||||
uint count = 0;
|
||||
uint i;
|
||||
for (i=0; i<total; i++)
|
||||
if ( pending && !transactions[i].executed
|
||||
|| executed && transactions[i].executed)
|
||||
{
|
||||
for (i = 0; i < transactionCount; i++) {
|
||||
if (pending && !transactions[i].executed || executed && transactions[i].executed) {
|
||||
transactionIdsTemp[count] = i;
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
_transactionIds = new uint[](to - from);
|
||||
for (i=from; i<to; i++)
|
||||
for (i = from; i < to; i++) {
|
||||
_transactionIds[i - from] = transactionIdsTemp[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function _malloc(uint size)
|
||||
private
|
||||
returns(bytes32 m_data)
|
||||
returns(bytes32 mData)
|
||||
{
|
||||
assembly {
|
||||
m_data := mload(0x40)
|
||||
mstore(0x40, add(m_data, size))
|
||||
mData := mload(0x40)
|
||||
mstore(0x40, add(mData, size))
|
||||
}
|
||||
}
|
||||
|
||||
function _delegatecall(bytes32 m_data, uint size)
|
||||
function _delegatecall(bytes32 mData, uint size)
|
||||
private
|
||||
returns(bytes32 m_result)
|
||||
returns(bytes32 mResult)
|
||||
{
|
||||
address target = 0x9485e92ab84b62c31c64465d8ff98fab87a8c908; //Rinkby only
|
||||
m_result = _malloc(32);
|
||||
address target = 0xcAFE992Df476564894C47999B5F81F7a785572c8; //Multinetwork
|
||||
mResult = _malloc(32);
|
||||
bool failed;
|
||||
|
||||
assembly {
|
||||
failed := iszero(delegatecall(sub(gas, 10000), target, m_data, size, m_result, 0x20))
|
||||
failed := iszero(delegatecall(sub(gas, 10000), target, mData, size, mResult, 0x20))
|
||||
}
|
||||
|
||||
assert(!failed);
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
pragma solidity ^0.4.15;
|
||||
|
||||
contract ERC20 {
|
||||
uint256 public totalSupply;
|
||||
function balanceOf(address who) constant returns (uint256);
|
||||
function allowance(address owner, address spender) constant returns (uint256);
|
||||
function transfer(address to, uint256 value) returns (bool ok);
|
||||
function transferFrom(address from, address to, uint256 value) returns (bool ok);
|
||||
function approve(address spender, uint256 value) returns (bool ok);
|
||||
event Transfer(address indexed from, address indexed to, uint256 value);
|
||||
event Approval(address indexed owner, address indexed spender, uint256 value);
|
||||
}
|
||||
import "./ERC20.sol";
|
||||
|
||||
contract MultiSigTokenWallet {
|
||||
|
||||
|
@ -86,10 +77,7 @@ contract MultiSigTokenWallet {
|
|||
}
|
||||
|
||||
modifier validRequirement(uint ownerCount, uint _required) {
|
||||
require (ownerCount <= MAX_OWNER_COUNT
|
||||
&& _required <= ownerCount
|
||||
&& _required != 0
|
||||
&& ownerCount != 0);
|
||||
require (ownerCount <= MAX_OWNER_COUNT && _required <= ownerCount && _required != 0 && ownerCount != 0);
|
||||
_;
|
||||
}
|
||||
|
||||
|
@ -108,13 +96,13 @@ contract MultiSigTokenWallet {
|
|||
/// @dev Contract constructor sets initial owners and required number of confirmations.
|
||||
/// @param _owners List of initial owners.
|
||||
/// @param _required Number of required confirmations.
|
||||
function Constructor(address[] _owners, uint _required)
|
||||
function constructor(address[] _owners, uint _required)
|
||||
public
|
||||
validRequirement(_owners.length, _required)
|
||||
{
|
||||
require(owners.length == 0 && required == 0);
|
||||
for (uint i=0; i<_owners.length; i++) {
|
||||
require (!isOwner[_owners[i]] && _owners[i] != 0);
|
||||
for (uint i = 0; i < _owners.length; i++) {
|
||||
require(!isOwner[_owners[i]] && _owners[i] != 0);
|
||||
isOwner[_owners[i]] = true;
|
||||
}
|
||||
owners = _owners;
|
||||
|
@ -142,29 +130,32 @@ contract MultiSigTokenWallet {
|
|||
function deposit(address _from, uint256 _amount, address _token, bytes _data)
|
||||
public
|
||||
{
|
||||
if(_from == address(this)) return;
|
||||
if (_from == address(this))
|
||||
return;
|
||||
uint _nonce = nonce;
|
||||
assert(ERC20(_token).transferFrom(_from, this, _amount));
|
||||
if(nonce == _nonce){ //ERC23 not executed _deposited tokenFallback by
|
||||
bool result = ERC20(_token).transferFrom(_from, this, _amount);
|
||||
assert(result);
|
||||
//ERC23 not executed _deposited tokenFallback by
|
||||
if (nonce == _nonce) {
|
||||
_deposited(_from, _amount, _token, _data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notice watches for balance in a token contract
|
||||
* @param _tokenAddr the token contract address
|
||||
* @param _data any data
|
||||
**/
|
||||
function watch(address _tokenAddr, bytes _data)
|
||||
function watch(address _tokenAddr)
|
||||
ownerExists(msg.sender)
|
||||
{
|
||||
uint oldBal = tokenBalances[_tokenAddr];
|
||||
uint newBal = ERC20(_tokenAddr).balanceOf(this);
|
||||
if(newBal > oldBal){
|
||||
_deposited(0x0, newBal-oldBal, _tokenAddr, _data);
|
||||
if (newBal > oldBal) {
|
||||
_deposited(0x0, newBal-oldBal, _tokenAddr, new bytes(0));
|
||||
}
|
||||
}
|
||||
|
||||
function setMyTokenList(address[] _tokenList)
|
||||
function setMyTokenList(address[] _tokenList)
|
||||
public
|
||||
{
|
||||
userList[msg.sender] = _tokenList;
|
||||
}
|
||||
|
@ -193,8 +184,7 @@ contract MultiSigTokenWallet {
|
|||
* @param _token the token contract address
|
||||
* @param _data (might be used by child classes)
|
||||
*/
|
||||
function receiveApproval(address _from, uint256 _amount, address _token, bytes _data)
|
||||
{
|
||||
function receiveApproval(address _from, uint256 _amount, address _token, bytes _data) {
|
||||
deposit(_from, _amount, _token, _data);
|
||||
}
|
||||
|
||||
|
@ -221,11 +211,13 @@ contract MultiSigTokenWallet {
|
|||
ownerExists(owner)
|
||||
{
|
||||
isOwner[owner] = false;
|
||||
for (uint i=0; i<owners.length - 1; i++)
|
||||
uint _len = owners.length - 1;
|
||||
for (uint i = 0; i < _len; i++) {
|
||||
if (owners[i] == owner) {
|
||||
owners[i] = owners[owners.length - 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
owners.length -= 1;
|
||||
if (required > owners.length)
|
||||
changeRequirement(owners.length);
|
||||
|
@ -241,11 +233,12 @@ contract MultiSigTokenWallet {
|
|||
ownerExists(owner)
|
||||
ownerDoesNotExist(newOwner)
|
||||
{
|
||||
for (uint i=0; i<owners.length; i++)
|
||||
for (uint i = 0; i < owners.length; i++) {
|
||||
if (owners[i] == owner) {
|
||||
owners[i] = newOwner;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isOwner[owner] = false;
|
||||
isOwner[newOwner] = true;
|
||||
OwnerRemoval(owner);
|
||||
|
@ -265,7 +258,7 @@ contract MultiSigTokenWallet {
|
|||
address[] memory _owners = owners;
|
||||
uint numOwners = _owners.length;
|
||||
addOwner(_dest);
|
||||
for(uint i = 0; i < numOwners; i++){
|
||||
for (uint i = 0; i < numOwners; i++) {
|
||||
removeOwner(_owners[i]);
|
||||
}
|
||||
}
|
||||
|
@ -326,13 +319,13 @@ contract MultiSigTokenWallet {
|
|||
notExecuted(transactionId)
|
||||
{
|
||||
if (isConfirmed(transactionId)) {
|
||||
Transaction storage tx = transactions[transactionId];
|
||||
tx.executed = true;
|
||||
if (tx.destination.call.value(tx.value)(tx.data))
|
||||
Transaction storage txx = transactions[transactionId];
|
||||
txx.executed = true;
|
||||
if (txx.destination.call.value(txx.value)(txx.data)) {
|
||||
Execution(transactionId);
|
||||
else {
|
||||
} else {
|
||||
ExecutionFailure(transactionId);
|
||||
tx.executed = false;
|
||||
txx.executed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,16 +353,16 @@ contract MultiSigTokenWallet {
|
|||
onlyWallet
|
||||
{
|
||||
address[] memory _tokenList;
|
||||
if(userList[_dest].length > 0){
|
||||
if (userList[_dest].length > 0) {
|
||||
_tokenList = userList[_dest];
|
||||
} else {
|
||||
_tokenList = tokens;
|
||||
}
|
||||
uint len = _tokenList.length;
|
||||
for(uint i = 0;i< len; i++){
|
||||
for (uint i = 0;i < len; i++) {
|
||||
address _tokenAddr = _tokenList[i];
|
||||
uint _amount = tokenBalances[_tokenAddr];
|
||||
if(_amount > 0) {
|
||||
if (_amount > 0) {
|
||||
delete tokenBalances[_tokenAddr];
|
||||
ERC20(_tokenAddr).transfer(_dest, _amount);
|
||||
}
|
||||
|
@ -391,7 +384,8 @@ contract MultiSigTokenWallet {
|
|||
uint _balance = tokenBalances[_tokenAddr];
|
||||
require(_amount <= _balance);
|
||||
tokenBalances[_tokenAddr] = _balance - _amount;
|
||||
assert(ERC20(_tokenAddr).transfer(_dest, _amount));
|
||||
bool result = ERC20(_tokenAddr).transfer(_dest, _amount);
|
||||
assert(result);
|
||||
}
|
||||
|
||||
/// @dev Returns the confirmation status of a transaction.
|
||||
|
@ -403,7 +397,7 @@ contract MultiSigTokenWallet {
|
|||
returns (bool)
|
||||
{
|
||||
uint count = 0;
|
||||
for (uint i=0; i<owners.length; i++) {
|
||||
for (uint i = 0; i < owners.length; i++) {
|
||||
if (confirmations[transactionId][owners[i]])
|
||||
count += 1;
|
||||
if (count == required)
|
||||
|
@ -438,15 +432,15 @@ contract MultiSigTokenWallet {
|
|||
/**
|
||||
* @dev register the deposit
|
||||
**/
|
||||
function _deposited(address _from, uint _amount, address _tokenAddr, bytes _data)
|
||||
function _deposited(address _from, uint _amount, address _tokenAddr, bytes)
|
||||
internal
|
||||
{
|
||||
TokenDeposit(_tokenAddr,_from,_amount);
|
||||
nonce++;
|
||||
if(tokenBalances[_tokenAddr] == 0){
|
||||
if (tokenBalances[_tokenAddr] == 0) {
|
||||
tokens.push(_tokenAddr);
|
||||
tokenBalances[_tokenAddr] = ERC20(_tokenAddr).balanceOf(this);
|
||||
}else{
|
||||
} else {
|
||||
tokenBalances[_tokenAddr] += _amount;
|
||||
}
|
||||
}
|
||||
|
@ -462,9 +456,10 @@ contract MultiSigTokenWallet {
|
|||
constant
|
||||
returns (uint count)
|
||||
{
|
||||
for (uint i=0; i<owners.length; i++)
|
||||
for (uint i = 0; i < owners.length; i++) {
|
||||
if (confirmations[transactionId][owners[i]])
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Returns total number of transactions after filters are applied.
|
||||
|
@ -476,10 +471,10 @@ contract MultiSigTokenWallet {
|
|||
constant
|
||||
returns (uint count)
|
||||
{
|
||||
for (uint i=0; i<transactionCount; i++)
|
||||
if ( pending && !transactions[i].executed
|
||||
|| executed && transactions[i].executed)
|
||||
for (uint i = 0; i < transactionCount; i++) {
|
||||
if (pending && !transactions[i].executed || executed && transactions[i].executed)
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Returns list of owners.
|
||||
|
@ -513,14 +508,16 @@ contract MultiSigTokenWallet {
|
|||
address[] memory confirmationsTemp = new address[](owners.length);
|
||||
uint count = 0;
|
||||
uint i;
|
||||
for (i=0; i<owners.length; i++)
|
||||
for (i = 0; i < owners.length; i++) {
|
||||
if (confirmations[transactionId][owners[i]]) {
|
||||
confirmationsTemp[count] = owners[i];
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
_confirmations = new address[](count);
|
||||
for (i=0; i<count; i++)
|
||||
for (i = 0; i < count; i++) {
|
||||
_confirmations[i] = confirmationsTemp[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Returns list of transaction IDs in defined range.
|
||||
|
@ -537,16 +534,16 @@ contract MultiSigTokenWallet {
|
|||
uint[] memory transactionIdsTemp = new uint[](transactionCount);
|
||||
uint count = 0;
|
||||
uint i;
|
||||
for (i=0; i<transactionCount; i++)
|
||||
if ( pending && !transactions[i].executed
|
||||
|| executed && transactions[i].executed)
|
||||
{
|
||||
for (i = 0; i < transactionCount; i++) {
|
||||
if (pending && !transactions[i].executed || executed && transactions[i].executed) {
|
||||
transactionIdsTemp[count] = i;
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
_transactionIds = new uint[](to - from);
|
||||
for (i=from; i<to; i++)
|
||||
for (i = from; i < to; i++) {
|
||||
_transactionIds[i - from] = transactionIdsTemp[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue