-2

I am trying to compile but i get this error message I can not figure out what is wrong with the unlock message

ParserError: Expected '(' but got identifier function unlockMessage(string name ) public payable returns (bool) { ^-----------^

pragma solidity ^0.4.25;

contract TrojanSecret {
// Data Types
uint memberCount;

string public name;
string public symbol;

mapping (string => address) Trojans;
mapping (string => string) secrets;
mapping (string => address[]) access;
mapping (string => uint) balance;
uint amount_for_unlock;

//constructor

constructor() public{
        name   = "Secrets"; 
        symbol = "S" ;
        amount_for_unlock = 1 ether;

}

function registerTrojan(string name) public returns(bool){
    if( Trojans[name] == address(0))  
    {
        memberCount ++;
        Trojans[name] = msg.sender;
        return True;
    } else {
        return false;
    }
}
function unregisterTrojan(string name) public {
    require( Trojans[name] != address(0));
    Trojans[name] = address(0);
    memberCount --;
}
function setSecret(string name,string message) public {
   require (Trojans[name] != address(0)&& Trojans[name] == msg.sender);
   secrets[name] = message;
}
function getSecret(string name) public view returns(string){
    require( Trojans[name] != address(0));
    bool flag = false;

    for(uint i = 0; i < access[name].length;i++)
    {
        if(access[name][i] == msg.sender){
            flag = true;
            break;

    }
     if(flag){
         return secrets[name];
     }
     return "message is locked";
}

function unlockMessage(string name ) public payable returns (bool) {
        require( Trojans[name] != address(0));
        if( msg.value == amount_for_unlock){

            balance[Trojans[name]] += msg.value;
            Trojans[name].transfer(msg.value);
            access[name].push(msg.sender);

            return true;
        }else{
            return false;
        }
    }
  • You need to format your code properly. See the "Code Layout" section of the documentation -> solidity.readthedocs.io/en/v0.5.3/style-guide.html#code-layout – Richard Horrocks Jul 3 '19 at 15:42
  • You're missing a } at the end of the if(access[name][i] == msg.sender){ clause. If you had bothered to maintain strict conventions of spacing, indentation and how braces appear in your code, then you could have probably avoided ending up with this kind of error. – goodvibration Jul 3 '19 at 15:42
  • Having done that you'll be able to see the missing closing brace in getSecret(). – Richard Horrocks Jul 3 '19 at 15:43
  • I have made the updates suggested and i get this error now- TypeError: Type address is not implicitly convertible to expected type string memory. balance[Trojans[name]] += msg.value; ^-----------^ – Lillian Atuhire Jul 3 '19 at 15:56
  • 4
    I'm voting to close this question as off-topic because because it's not a question, it's a code-dump, and similarly to this "question", if this dude/lady had maintained his/her code properly organized, then he/she could have probably avoided dumping his/her syntax errors here. – goodvibration Jul 3 '19 at 16:00
1

This { isn't closed.

if(access[name][i] == msg.sender){
| improve this answer | |

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