0

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.

0

Seems like you are missing "return" in getRegisteredClients()

| improve this answer | |
  • Ohh...that was dumb! Thanks a lot for pointing it out. – Prana Jul 9 '17 at 17:52
0

Actually you didn't add return keyword in your getRegisteredClients method.

function getRegisteredClients() constant returns (uint) {
   return registeredClients.length;
}
| improve this answer | |
  • Ohh...that was dumb! Thanks a lot for pointing it out. – Prana Jul 9 '17 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.