0

I am using a loop to retrieve an object from array. Then get its details and compare it with other string. But it gives error

Type bytes32 is not implicitly convertible to expected type struct UserRecord.Service storage pointer.

contract UserRecord {
  address public owner;
  bytes32[] public Servicelist;

  constructor () public {
    owner = msg.sender;
    newService("1","Serviceone",msg.sender);
  }

  struct Service {
    address serviceowner;
    string servicename;
    bytes serviceid;
    bool isService;
  }

  mapping(bytes32 => Service) public servicestructs;

  function isService(bytes32 uid) public view returns(bool isIndeed) {
    return servicestructs[uid].isService;
  }

  function getServiceCount() public view returns(uint count) {
    return Servicelist.length;
  }

  function newService(bytes32 uid, string memory _servicename, address _serviceowner) public returns(bool success) {
    require(!isService(uid));
    servicestructs[uid].servicename = _servicename;
    servicestructs[uid].serviceowner = _serviceowner;
    servicestructs[uid].isService = true;
    Servicelist.push(uid);
    emit LognewService(owner, uid, _servicename, _serviceowner);
    return true;
  }

  function getService(string memory servicequery) public view returns(bool) {
    for(uint i=0;i<Servicelist.length;i++) {
      Service storage service=Servicelist[i];
      string memory service_name=Servicelist[i].servicename;
      if(keccak256(abi.encodePacked(service_name))==keccak256(abi.encodePacked(service_name))) {
        return service_name;
      }
    }
  } 

  event LognewService(address sender, bytes32 hash, string servicename, address serviceowner);
}
1
Service storage service=Servicelist[i];
string memory service_name=Servicelist[i].servicename;

should be

Service storage service=servicestructs [Servicelist[i]];
string memory service_name=service.servicename;

Also, there is another error in the following line:

return service_name;

It tries to return string from a function whose return type is bool.

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.