[Ethereum] Call function on another contract

contract-designcontract-invocationsolidity

I've created a contract called "Name" which I've deployed to the testnet. this function just register some text for the user and display it back.

My contract is:

contract Name is mortal{

    mapping(address=>string) public text;
    string public test;

    function register(string _text){
        text[msg.sender]    = _text;
    }
}

I want to interact with this contract using a proxy contract:

contract Proxy is mortal {

    address watch_addr  = 0xEB1e2c19bd833b7f33F9bd0325B74802DF187935;
    address user_addr   = msg.sender;

    function register(){
        watch_addr.call(bytes4(sha3("register()")))
    }
}

(To save you from reading unnecessary code I've omitted the Mortal contract with its suicide function)

Now, calling the other function is not a problem using:

watch_addr.call(bytes4(sha3("register()")))

The problem is giving it arguments.

First, I can't parse an arguments with my proxy contract.
Second, I'm afraid that even if I was able to hard code the proxy call:

watch_addr.call(bytes4(sha3("register("This text is hard codded")")))

and get my original contract to accept it and insert it into a variable, the address of that variable (msg.sender) will be the (msg.sender) of the proxy contract, and not the address of the user who uses this proxy contract.

I think I'm missing something about the way it suppose to work, any idea?

Best Answer

You can do:

/* MORTAL CONTRACT HERE */

contract Name is mortal{

    mapping(address=>string) public text;
    string public test;

    function register(string _text){
        text[msg.sender]    = _text;
    }
}

contract Proxy is mortal {

    address watch_addr  = 0xEB1e2c19bd833b7f33F9bd0325B74802DF187935;
    address user_addr   = msg.sender;

    function register(string _text){
        Name name = Name(watch_addr);
        name.register(_text);
    }
}

BUT

Be aware that although you're using a "proxy" contract the Namecontract could access the user_addr just looking at the tx.originvariable.