The smart contract app I am writing follows what I consider good practice - it is decoupled so that a controller contract calls a logic contract which calls a storage contract. So Contract A
calls Contract B
calls Contract C
.
However, I'm wondering if, because of security, such decoupling is a good idea for smart contracts. That's because I need the onlyOwner
modifier to tie down who calls my functions (as describe here: https://github.com/ethereum/wiki/wiki/Solidity-Features). To my mind, it would be great if I could do something like this:
import "Owned.sol";
contract A is Owned {
B private b;
function A(address B) {
b = B(b);
}
function myInterface() public onlyOwner {
a.doStuff({from: msg.sender});
}
}
contract B is Owned {
C private c;
function B(address c) {
c = C(c);
}
function doStuff() public onlyOwner {
c.store(42,{from: msg.sender});
}
}
contract C is Owned {
int private theAnswer;
function store(int value) public onlyOwner {
theAnswer = value
}
}
However, I believe I can't send msg.sender
that way. Hence, would I be better bundling Contract A
, Contract B
and Contract C
into a single monolithic contract where msg.sender
is valid?
msg.sender
within the constructor of B to set the owner. Then do the same, creating C from within the constructor of B