abstract the DelegatedCall logic
This commit is contained in:
parent
53cc9c2c0e
commit
1b2a941869
|
@ -0,0 +1,71 @@
|
|||
pragma solidity ^0.4.12;
|
||||
|
||||
/**
|
||||
* @title DelegatedCall
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* Abstract contract that delegates all calls to contract returned by abstract function `_getDelegatedContract`
|
||||
*/
|
||||
contract DelegatedCall {
|
||||
|
||||
/**
|
||||
* @dev delegates the call of this function
|
||||
*/
|
||||
modifier delegated
|
||||
{
|
||||
uint inSize = msg.data.length;
|
||||
bytes32 inDataPtr = _malloc(inSize);
|
||||
|
||||
assembly {
|
||||
calldatacopy(inDataPtr, 0x0, inSize)
|
||||
}
|
||||
|
||||
uint256 outSize;
|
||||
bytes32 outDataPtr;
|
||||
|
||||
_delegatecall(inDataPtr, inSize);
|
||||
_;
|
||||
assembly {
|
||||
return(0, outSize)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev defines the address for delegation of calls
|
||||
*/
|
||||
function _getDelegatedContract()
|
||||
internal
|
||||
returns(address);
|
||||
|
||||
/**
|
||||
* @dev allocates memory to a pointer
|
||||
*/
|
||||
function _malloc(uint size)
|
||||
internal
|
||||
returns(bytes32 ptr)
|
||||
{
|
||||
assembly {
|
||||
ptr := mload(0x40)
|
||||
mstore(0x40, add(ptr, size))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev delegates the data in pointer
|
||||
*/
|
||||
function _delegatecall(bytes32 inDataPtr, uint inSize)
|
||||
internal
|
||||
returns(bytes32 outDataPtr, uint256 outSize)
|
||||
{
|
||||
outSize = 0x20;
|
||||
address target = _getDelegatedContract();
|
||||
outDataPtr = _malloc(outSize);
|
||||
bool failed;
|
||||
|
||||
assembly {
|
||||
failed := iszero(delegatecall(sub(gas, 10000), target, inDataPtr, inSize, outDataPtr, outSize))
|
||||
}
|
||||
|
||||
assert(!failed);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
pragma solidity ^0.4.15;
|
||||
|
||||
import "./DelegatedCall.sol";
|
||||
|
||||
/**
|
||||
* @title MultiSigStub
|
||||
* Contract that delegates calls to a library to build a full MultiSigWallet that is cheap to create.
|
||||
*/
|
||||
contract MultiSigStub {
|
||||
contract MultiSigStub is DelegatedCall {
|
||||
|
||||
address[] public owners;
|
||||
address[] public tokens;
|
||||
mapping (uint => Transaction) public transactions;
|
||||
mapping (uint => mapping (address => bool)) public confirmations;
|
||||
uint public transactionCount;
|
||||
|
@ -34,21 +35,6 @@ contract MultiSigStub {
|
|||
_delegatecall(mData, size);
|
||||
}
|
||||
|
||||
modifier delegated {
|
||||
uint size = msg.data.length;
|
||||
bytes32 mData = _malloc(size);
|
||||
|
||||
assembly {
|
||||
calldatacopy(mData, 0x0, size)
|
||||
}
|
||||
|
||||
bytes32 mResult = _delegatecall(mData, size);
|
||||
_;
|
||||
assembly {
|
||||
return(mResult, 0x20)
|
||||
}
|
||||
}
|
||||
|
||||
function()
|
||||
payable
|
||||
delegated
|
||||
|
@ -70,20 +56,7 @@ contract MultiSigStub {
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
function watch(address _tokenAddr)
|
||||
public
|
||||
delegated
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function setMyTokenList(address[] _tokenList)
|
||||
public
|
||||
delegated
|
||||
{
|
||||
|
||||
}
|
||||
/// @dev Returns the confirmation status of a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
/// @return Confirmation status.
|
||||
|
@ -99,15 +72,6 @@ contract MultiSigStub {
|
|||
/*
|
||||
* Web3 call functions
|
||||
*/
|
||||
function tokenBalances(address tokenAddress)
|
||||
public
|
||||
constant
|
||||
delegated
|
||||
returns (uint)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// @dev Returns number of confirmations of a transaction.
|
||||
/// @param transactionId Transaction ID.
|
||||
|
@ -144,16 +108,6 @@ contract MultiSigStub {
|
|||
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.
|
||||
|
@ -206,6 +160,7 @@ contract MultiSigStub {
|
|||
|
||||
function _malloc(uint size)
|
||||
private
|
||||
pure
|
||||
returns(bytes32 mData)
|
||||
{
|
||||
assembly {
|
||||
|
@ -218,8 +173,7 @@ contract MultiSigStub {
|
|||
private
|
||||
returns(bytes32 mResult)
|
||||
{
|
||||
address target = 0xc0FFeEE61948d8993864a73a099c0E38D887d3F4; //Multinetwork
|
||||
mResult = _malloc(32);
|
||||
address target = 0xCaFFE810d0dF52E27DC580AD4a3C6283B0094291;
|
||||
bool failed;
|
||||
|
||||
assembly {
|
||||
|
|
Loading…
Reference in New Issue