I am trying to create a factory contract that dynamically creates new instances of another contract. And I want the factory to return the newly created contract's address; however, when I test it in the Remix IDE, the function does not return anything. Here is my current code:
contract CreateTournament {
Tournament public newTournament;
address[] newTournaments;
uint index = 0;
function createNewTournament(string _title, uint32
_maxParticipants, uint _entryFee, uint _surcharge) public
returns(address) {
newTournament = new Tournament(_title, _maxParticipants,
_entryFee, _surcharge);
newTournaments.push(newTournament);
return newTournament;
}
function checkAddress(address tournament) public view returns(bool)
{
bool exists = false;
for (uint i = 0; i < newTournaments.length; i++) {
if (tournament == newTournaments[i]) {
exists = true;
}
}
return exists;
}
}
Any help would be appreciated!