I'm trying to map the address with the account name, but with the find_user_name function in my contract, it keeps showing the Gas estimation failed while deploying the contract. I have the struct user:
struct user{
string account;
string password;
address useraddress;
}
and initialize the userlist
user[] public userlist;
then I write the find_user_name function to map to address with the account
//return the user name by mapping the address
function find_user_name(address _address) public view returns(string){
uint256 i;
string account_name;
for(i=0; i < userlist.length; i++){//find the mapping user account name
if(_address == userlist[i].useraddress)account_name = userlist[i].account;
}
return account_name;
}
Is there anything wrong with my logic? Otherwise It sholud be okay when deploying the contract..