You want to use msg.sender
as a reliable means of authenticating the sender. I think what you're getting at is how to cope with the limitations of msg.sender
; it reveals only the latest sender in a (possibly) long chain.
Consider another example:
contractFactory
produces FundRaiser
contracts with "owner
" set to the originator who asked contractFactory
to deploy a new contract. So, the transaction originator is a step removed from the deployed contract.
The usual approach wouldn't work:
owner = msg.sender;
That would set the new FundRaiser
owner to the contractFactory
. Not what we want. Since msg.sender
isn't giving us the information we need, we'll have to pass it into the FundRaiser
constructor, like:
function FundRaiser(address originator) {
owner = originator;
}
The deploying function in the factory can pass it along, like:
function newCampaign() {
FundRaiser f = new FundRaiser(msg.sender);
}
That way, the original msg.sender
(and any other important information) ends up passed down the chain where it's needed.
Hope it helps.
function approveSelfSpender(address _spender, uint _valuue) returns (bool success) { allowed[this][_spender] = _value; Approval(this, _spender, _value); return true; }
approveSelfSpender(msg.sender, balanceOf[this]);