owners array getter, better custom tokenlist, interface to new contract

This commit is contained in:
Ricardo Guilherme Schmidt 2017-08-17 10:06:14 -03:00
parent cc4e742d03
commit ee5823a120
4 changed files with 120 additions and 67 deletions

View File

@ -2,7 +2,7 @@ pragma solidity ^0.4.15;
/**
* @title MultiSigStub
* Contact that delegates calls to a library to build a full MultiSigWallet that is cheap to create.
* Contract that delegates calls to a library to build a full MultiSigWallet that is cheap to create.
*/
contract MultiSigStub {

View File

@ -19,7 +19,7 @@ contract MultiSigTokenWallet {
mapping (address => bool) public isOwner;
mapping (address => uint) public tokenBalances;
mapping (address => bool) public ignoredTokens;
mapping (address => address[]) public userList;
address[] public tokens;
uint public required;
uint public transactionCount;
@ -44,8 +44,7 @@ contract MultiSigTokenWallet {
event OwnerAddition(address indexed _owner);
event OwnerRemoval(address indexed _owner);
event RequirementChange(uint _required);
event IgnoredToken(address indexed _owner, address _token, bool ignored);
modifier onlyWallet() {
require (msg.sender == address(this));
_;
@ -103,9 +102,9 @@ contract MultiSigTokenWallet {
}
/**
* Public functions
*
**/
* Public functions
*
**/
/// @dev Contract constructor sets initial owners and required number of confirmations.
/// @param _owners List of initial owners.
/// @param _required Number of required confirmations.
@ -150,7 +149,32 @@ contract MultiSigTokenWallet {
_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)
ownerExists(msg.sender)
{
uint oldBal = tokenBalances[_tokenAddr];
uint newBal = ERC20(_tokenAddr).balanceOf(this);
if(newBal > oldBal){
_deposited(0x0, newBal-oldBal, _tokenAddr, _data);
}
}
function setMyTokenList(address[] _tokenList)
{
userList[msg.sender] = _tokenList;
}
function setTokenList(address[] _tokenList)
onlyWallet
{
tokens = _tokenList;
}
/**
* @notice ERC23 Token fallback
* @param _from address incoming token
@ -189,33 +213,6 @@ contract MultiSigTokenWallet {
OwnerAddition(owner);
}
/**
* @notice watches for balance in a token contract
* @param _tokenAddr the token contract address
* @param _data any data
**/
function watch(address _tokenAddr, bytes _data)
ownerExists(msg.sender)
{
uint oldBal = tokenBalances[_tokenAddr];
uint newBal = ERC20(_tokenAddr).balanceOf(this);
if(newBal > oldBal){
_deposited(0x0, newBal-oldBal, _tokenAddr, _data);
}
}
/**
* @notice ignores a token for sendAll
* @param _tokenAddr the token contract address
* @param _ignore true if is to ignore, false if not ignore (default)
**/
function ignoreToken(address _tokenAddr, bool _ignore)
ownerExists(msg.sender)
{
IgnoredToken(msg.sender, _tokenAddr, _ignore);
ignoredTokens[_tokenAddr] = _ignore;
}
/// @dev Allows to remove an owner. Transaction has to be sent by wallet.
/// @param owner Address of owner.
function removeOwner(address owner)
@ -255,6 +252,24 @@ contract MultiSigTokenWallet {
OwnerAddition(newOwner);
}
/**
* @dev gives full ownership of this wallet to `_dest` removing older owners from wallet
* @param _dest the address of new controller
**/
function releaseWallet(address _dest)
public
notNull(_dest)
ownerDoesNotExist(_dest)
onlyWallet
{
address[] memory _owners = owners;
uint numOwners = _owners.length;
addOwner(_dest);
for(uint i = 0; i < numOwners; i++){
removeOwner(_owners[i]);
}
}
/// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet.
/// @param _required Number of required confirmations.
function changeRequirement(uint _required)
@ -322,24 +337,6 @@ contract MultiSigTokenWallet {
}
}
/**
* @dev gives full ownership of this wallet to `_dest` removing older owners from wallet
* @param _dest the address of new controller
**/
function releaseWallet(address _dest)
public
notNull(_dest)
ownerDoesNotExist(_dest)
onlyWallet
{
address[] memory _owners = owners;
uint numOwners = _owners.length;
addOwner(_dest);
for(uint i = 0; i < numOwners; i++){
removeOwner(_owners[i]);
}
}
/**
* @dev withdraw all recognized tokens balances and ether to `_dest`
* @param _dest the address of receiver
@ -362,11 +359,17 @@ contract MultiSigTokenWallet {
notNull(_dest)
onlyWallet
{
uint len = tokens.length;
address[] memory _tokenList;
if(userList[_dest].length > 0){
_tokenList = userList[_dest];
} else {
_tokenList = tokens;
}
uint len = _tokenList.length;
for(uint i = 0;i< len; i++){
address _tokenAddr = tokens[i];
address _tokenAddr = _tokenList[i];
uint _amount = tokenBalances[_tokenAddr];
if(_amount > 0 && !ignoredTokens[_tokenAddr]) {
if(_amount > 0) {
delete tokenBalances[_tokenAddr];
ERC20(_tokenAddr).transfer(_dest, _amount);
}
@ -449,8 +452,8 @@ contract MultiSigTokenWallet {
}
/*
* Web3 call functions
*/
* Web3 call functions
*/
/// @dev Returns number of confirmations of a transaction.
/// @param transactionId Transaction ID.
/// @return Number of confirmations.
@ -489,6 +492,16 @@ contract MultiSigTokenWallet {
return owners;
}
/// @dev Returns list of tokens.
/// @return List of token addresses.
function getTokenList()
public
constant
returns (address[])
{
return tokens;
}
/// @dev Returns array with owner addresses, which confirmed transaction.
/// @param transactionId Transaction ID.
/// @return Returns array of owner addresses.

View File

@ -6,7 +6,8 @@
[clojure.string :refer [join]]
[clojure.tools.logging :as log]
[clojure.string :as str]
[pandect.core :as pandect]))
[pandect.core :as pandect]
[commiteth.eth.multisig-wallet :as multisig]))
(defn eth-rpc-url [] (env :eth-rpc-url "http://localhost:8545"))
(defn eth-account [] (:eth-account env))
@ -95,13 +96,7 @@
(defn deploy-contract
[owner]
(let [contract-code (-> "contracts/wallet.data" io/resource slurp)
owner1 (format-param (eth-account))
owner2 (format-param owner)
data (str contract-code owner1 owner2)
value (format "0x%x" 0)]
(send-transaction (eth-account) nil value {:gas "0x80000"
:data data})))
(multisig/create-new (eth-account) owner 2))
(defn format-call-params
[method-id & params]

View File

@ -2,12 +2,26 @@
(:require [commiteth.eth.core :as eth]
[clojure.tools.logging :as log]))
(defonce confirmation-topic "0xc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51")
(defonce method-ids
{:submit-transaction (eth/sig->method-id "submitTransaction(address,uint256,bytes)")
:withdraw-everything (eth/sig->method-id "withdrawEverything(address)")})
(defonce factory "0xbcBc5b8cE5c76Ed477433636926f76897401f838")
(defonce factory-topic "0x96b5b9b8a7193304150caccf9b80d150675fa3d6af57761d8d8ef1d6f9a1a909")
(defonce confirmation-topic "0xc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e51")
(defn create-new
[owner1 owner2 required]
(eth/execute (eth/eth-account)
factory
"0xf8f73808"
0x40
0x2
required
owner1
owner2))
(defn execute
[contract to value]
@ -32,6 +46,18 @@
(when confirmation-data
(subs confirmation-data 2 66))))
(defn find-factory-hash
[receipt]
(let [logs (:logs receipt)
has-factory-event #(some (fn [topic] (= topic
factory-topic))
(:topics %))
factory-event (first (filter has-factory-event logs))
factory-data (:data factory-event)]
(when factory-data
(subs factory-data 2 66))))
(defn send-all
[contract to]
(log/debug "multisig.send-all(contract, to)" contract to)
@ -46,3 +72,22 @@
"0x60"
"0x24"
params)))
(defn watch-token
[contract token]
(log/debug "multisig.watch-token(contract, token)" contract token)
(eth/execute (eth/eth-account)
contract
"0xf375c07a"
token
0))
(defn token-balance
[contract token]
(eth/call contract "0x523fba7f" token))
(defn tokens-list
[contract]
(eth/call contract "0x273cbaa0"))