Skip to content

Commit

Permalink
Add Validations
Browse files Browse the repository at this point in the history
  • Loading branch information
wolftrax5 committed Jul 24, 2022
1 parent 31ce6da commit a59d68e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ contract PokemonFactory {
uint id,
string name
);

mapping (uint => address) public pokemonToOwner;
mapping (address => uint) ownerPokemonCount;

function createPokemon (string memory _name, uint _id) public {
modifier validPokemon(string memory _name ,uint _id){
require(_id > 0, "El Id debe ser mayor de 0");
bytes memory strinCheck = bytes(_name);
require(strinCheck.length != 0,"El nombre no debe ser vacio");
require(strinCheck.length > 2,"La longitud del nombre debe ser mayor de 2");
_;
}

function createPokemon (string memory _name, uint _id) validPokemon(_name, _id) public {
pokemons.push(Pokemon(_id, _name));
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
Expand All @@ -39,3 +48,4 @@ contract PokemonFactory {

}


0 comments on commit a59d68e

Please sign in to comment.