I am repeatedly facing this issue with structuring contracts' code:
contract Allower {
Allowed allowed;
function doSth() onlyallowed;
modifier onlyallowed {
if (msg.sender != address(allowed))
throw;
_
}
}
contract Allowed {
Allower allower;
function doSthOnAllower() {
allower.doSth();
}
}
In order to enforce that only a particular instance of Allowed
executes Allower.doSth
, we need the contracts to keep mutual references (assuming we like the 1-1 relationship, but still want to keep these contracts separate). Now, to deploy both contracts and have them work, we need to add, more or less:
contract Allower {
// snip...
function Allower(Allowed _allowed) {
allowed = _allowed;
allowed.setAllower(this);
}
}
contract Allowed {
// snip...
function setAllower(Allower _allower) allowernotset {
allower = _allower;
}
}
Is there any pattern which would allow to by-pass the necesity of setAllower
? It just seems like an anti-pattern to have such "set" methods propagate.