[Ethereum] how to loop through a mapping of address to struct

solidity

I have a mapping where the key is the artist name, the value is msg.sender address. In a function, I want to check if the parameter username has already existed in the mapping keys, if yes, i will throw

How do I loop through a mapping of value keys to check and compare with input parameter?

mapping(bytes32 => address) public reserved_names;

function create_artist(bytes32 username, string ipfs) {

   //todo throw exception if artists username already exists

   reserved_names[username] = msg.sender;

Best Answer

assert(reserved_names[username] == 0x0);
Related Topic