Skip to content

Instantly share code, notes, and snippets.

@wissalHaji
Created December 12, 2020 14:07
Show Gist options
  • Save wissalHaji/9848d4d2b8ef646ba650b7db3869db32 to your computer and use it in GitHub Desktop.
Save wissalHaji/9848d4d2b8ef646ba650b7db3869db32 to your computer and use it in GitHub Desktop.
contract Factory{
Child[] public children;
uint disabledCount;
event ChildCreated(address childAddress, uint data);
function createChild(uint data) external{
Child child = new Child(data, children.length);
children.push(child);
emit ChildCreated(address(child), data);
}
function getChildren() external view returns(Child[] memory _children){
_children = new Child[](children.length- disabledCount);
uint count;
for(uint i=0;i<children.length; i++){
if(children[i].isEnabled()){
_children[count] = children[i];
count++;
}
}
}
function disable(Child child) external {
children[child.index()].disable();
disabledCount++;
}
}
contract Child{
uint data;
bool public isEnabled;
uint public index;
constructor(uint _data,uint _index){
data = _data;
isEnabled = true;
index = _index;
}
function disable() external{
isEnabled = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment