0

i'm new to solidity and i'm developing an easy app. This is the contract i'm working on. It's all functioning but i need to: do some sort of function that return me all the array value whit the same user hash; I need to insert automatically a new _address because when i insert new data whit the same addres, the stored data is overwrited and i don't want that because i need to store all data. For example: i inserted .setUser('0xb23A1ff49C4d7c8997C414276917f974E6dD93D7','some md5','user m5d'), and after a couple of min i needed to insert other data that is linked to that same userHash. how can i do that?

pragma solidity >=0.4.22 <0.7.0;

contract crud{
struct user{
    string hash;
    string userhash;
}

 mapping(address=> user)  users;
 
 address[] public user_arr;
 
 function setUser(address_address, string _hash, string _userhash) public {
     var array=users[_address];
     array.hash= _hash;
     array.userhash= _userhash;
     
     user_arr.push(_address) -1;
     
 }
 
 function getAllUser() view public returns (address[]) {
    return user_arr;
}

function getUser(address_address) view public returns (string, string) {
    return (users[_address].hash, users[_address].userhash);
}

}

Your Answer

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

Browse other questions tagged or ask your own question.