Normally a factory includes the bytecode of any contract it creates. Now let's think about a scenario where there is an update of the child contract code necessary. I don't want to change existing childs, but I want to inject different bytecode into the factory, so from now on it produces the new variant of the child contracts.
Sample code:
contract Factory {
// ...
function newChild() returns (address) {
Child c = new Child();
return c;
}
// ...
}
contract Child_v1 {
// ...
public getVersion() constant returns (uint) {
return 1;
}
}
When compiling this the bytecode of Child_v1 will be embedded into the Factory contract. Now I want to change the factory so it produces childs of the type Child_v2:
contract Child_v2 {
// ...
public getVersion() constant returns (uint) {
return 2;
}
}
Is there a way to change the embedded bytecode of Child_v1 in Factory? E.g. I could compile Child_v2 offline and inject the new bytecode into the factory, something like this:
contract Factory {
// ...
function newChild() returns (address){
Child c = new Child(); // should use bytecode as provided below
return c;
}
function setChildCode(bytes[] bytecode) {
// Some magic that updates the bytecode used in newChild() above
}
}