Could someone please point out what is wrong in this code? It seems that when I call the registerClient() function, it succeeds and returns TRUE. But when I call the getRegisteredClients() method, it always returns 0!!
struct RegisteredCandidate {
bytes32 ownerID;
address clientAddress;
}
mapping( bytes32=> RegisteredCandidate) registeredCandidates;
bytes32[] registeredClients; //an array of clients to keep track of numbers
//Just a modifier to restrict calls
modifier ifIssuer() {
if (issuer != msg.sender){
revert();
}
else {
_;
}
}
function registerClient(bytes32 _clientID) public returns (bool) {
//if the clientID is not already present in the map
if(registeredCandidates[_clientID].ownerID != _clientID) {
registeredCandidates[_clientID].ownerID = _clientID;
registeredCandidates[_clientID].clientAddress = msg.sender;
registeredClients.push(_clientID); //updating the counter array
return true;
}
return false;
}
function getRegisteredClients() constant returns (uint) {
registeredClients.length;
}
Thanks for any help on this.
One more question to ask: is there a better way to form the same logic?
Thanks.