From 3cc0c36186654909601aaa8b3b0cfcc8a856d651 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sun, 20 Aug 2017 15:29:37 -0300 Subject: [PATCH] cleanup --- contracts/ERC20.sol | 12 ++++ contracts/MultiSigFactory.sol | 2 +- contracts/MultiSigStub.sol | 59 ++++++++--------- contracts/MultiSigTokenWallet.sol | 105 +++++++++++++++--------------- 4 files changed, 94 insertions(+), 84 deletions(-) create mode 100644 contracts/ERC20.sol diff --git a/contracts/ERC20.sol b/contracts/ERC20.sol new file mode 100644 index 0000000..e82eabb --- /dev/null +++ b/contracts/ERC20.sol @@ -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); +} \ No newline at end of file diff --git a/contracts/MultiSigFactory.sol b/contracts/MultiSigFactory.sol index e570705..62bc00a 100644 --- a/contracts/MultiSigFactory.sol +++ b/contracts/MultiSigFactory.sol @@ -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); } diff --git a/contracts/MultiSigStub.sol b/contracts/MultiSigStub.sol index 230e27c..da51d00 100644 --- a/contracts/MultiSigStub.sol +++ b/contracts/MultiSigStub.sol @@ -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 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) changeRequirement(owners.length); @@ -241,11 +233,12 @@ contract MultiSigTokenWallet { ownerExists(owner) ownerDoesNotExist(newOwner) { - for (uint i=0; i 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