Created
January 11, 2017 03:09
-
-
Save PeterBorah/61dc14136b4a57359ddab044bce35a9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.7; | |
import "./Resolver.sol"; | |
contract EtherRouter { | |
Resolver resolver; | |
function EtherRouter(Resolver _resolver) { | |
resolver = _resolver; | |
} | |
function() { | |
uint r; | |
// Get routing information for the called function | |
var (destination, outsize) = resolver.lookup(msg.sig, msg.data); | |
// Make the call | |
assembly { | |
calldatacopy(mload(0x40), 0, calldatasize) | |
r := delegatecall(sub(gas, 700), destination, mload(0x40), calldatasize, mload(0x40), outsize) | |
} | |
// Throw if the call failed | |
if (r != 1) { throw;} | |
// Pass on the return value | |
assembly { | |
return(mload(0x40), outsize) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment