Is it possible to "forward" a call to another contract?

SemielSemiel Member Posts: 15
I'd like to write a "redirect" contract that takes an arbitrary call with arbitrary data, and forwards it to another contract. You can do this with "side effects only" functions, like this:

contract Redirector { address target; function set_target(address _target) { target = _target; } function() { target.call(msg.data); } }

But since `address.call()` just returns a success/failure boolean, this won't let us return the results of that forwarded call. Is there any way around this?

Comments

  • chrisethchriseth Member Posts: 170 ✭✭✭
    edited August 2015
    Unfortunately, not. The EVM requires that you know the size of the returned value in advance, so this is not possible in general (we might change that in the future).
    If you know the type or can guess it, this is of course possible in principle, although I cannot yet think of a good way to express that in Solidity. Perhaps something like
    `target.call[function(_) returns (uint32)](msg.data)` (i.e. using templates) might work.
Sign In or Register to comment.