Created
December 12, 2020 14:07
-
-
Save wissalHaji/9848d4d2b8ef646ba650b7db3869db32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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