Skip to content

Instantly share code, notes, and snippets.

@coopermaruyama
Last active October 27, 2017 05:23
Show Gist options
  • Save coopermaruyama/546acc7dd1b59e3f186f83075fe7c0e8 to your computer and use it in GitHub Desktop.
Save coopermaruyama/546acc7dd1b59e3f186f83075fe7c0e8 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.15;
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
contract SafeProxy is Ownable {
mapping(address => bool) public whitelistedAddress;
event TransferFunds(address sender, address receiveingAddr);
/// @dev Adds a new address to the whitelist
/// @param _newAddress Address to add to the whitelist
function addAddress(address _newAddress)
onlyOwner
{
require(whitelistedAddress[_newAddress] == false);
whitelistedAddress[_newAddress] = true;
}
/// @dev Removes an old address to the whitelist
/// @param _oldAddress Address to remove from the whitelist
function removeAddress(address _oldAddress)
onlyOwner
{
require(whitelistedAddress[_oldAddress] == true);
whitelistedAddress[_oldAddress] = false;
}
/// @dev Converts an address passed into msg.data into address type
/// @param _address Bytes of the address to convert
function parseAddr(bytes _address)
public
returns (address)
{
uint160 iaddr = 0;
uint160 b1;
for (uint i=0; i<20; i++){
iaddr *= 256;
b1 = uint160(_address[i]);
iaddr += (b1);
}
return address(iaddr);
}
/// @dev Sends the data passed into the transaction through to the
function ()
payable
{
address receivingAddress = parseAddr(msg.data);
require(whitelistedAddress[receivingAddress] == true);
receivingAddress.delegatecall();
TransferFunds(msg.sender, receivingAddress);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment