From c2c28caa04071ee952702bac6638df458519996e Mon Sep 17 00:00:00 2001 From: IvySaskia Date: Mon, 1 Aug 2022 19:42:54 -0400 Subject: [PATCH 1/8] [gelopfalcon/solidity-eth-challenge#1] Add: Reto 1 --- PokemonFactory.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index a3267da1..f55045c0 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -14,10 +14,14 @@ contract PokemonFactory { mapping (uint => address) public pokemonToOwner; mapping (address => uint) ownerPokemonCount; - function createPokemon (string memory _name, uint _id) public { - pokemons.push(Pokemon(_id, _name)); + event eventNewPokemon (Pokemon pokemon); + + function createPokemon (string memory _name, uint _id) public { + Pokemon memory p = Pokemon(_id, _name); + pokemons.push(p); pokemonToOwner[_id] = msg.sender; ownerPokemonCount[msg.sender]++; + emit eventNewPokemon (p); } function getAllPokemons() public view returns (Pokemon[] memory) { From 605efb62c52183b6f2caa71b1b219cb1b73ad886 Mon Sep 17 00:00:00 2001 From: IvySaskia Date: Mon, 1 Aug 2022 20:29:42 -0400 Subject: [PATCH 2/8] [gelopfalcon/solidity-eth-challenge#2] Add: Reto 2 --- PokemonFactory.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index f55045c0..c6f3d7d6 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -17,6 +17,8 @@ contract PokemonFactory { event eventNewPokemon (Pokemon pokemon); function createPokemon (string memory _name, uint _id) public { + require(_id > 0, "Pokemon's id should be greater than 0"); + require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); Pokemon memory p = Pokemon(_id, _name); pokemons.push(p); pokemonToOwner[_id] = msg.sender; From b42b7dff9cadf248e11114f2827d4a6ce82aa579 Mon Sep 17 00:00:00 2001 From: IvySaskia Date: Tue, 2 Aug 2022 09:58:31 -0400 Subject: [PATCH 3/8] [gelopfalcon/solidity-eth-challenge#3] Add: Reto 3 --- PokemonFactory.sol | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index c6f3d7d6..ecfeeee4 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -4,10 +4,16 @@ pragma solidity >=0.7.0 <0.9.0; contract PokemonFactory { - struct Pokemon { - uint id; - string name; - } + struct Pokemon { + uint id; + string name; + Ability[] abilities; + } + + struct Ability { + string name; + string description; + } Pokemon[] private pokemons; @@ -16,14 +22,19 @@ contract PokemonFactory { event eventNewPokemon (Pokemon pokemon); - function createPokemon (string memory _name, uint _id) public { - require(_id > 0, "Pokemon's id should be greater than 0"); - require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); - Pokemon memory p = Pokemon(_id, _name); - pokemons.push(p); - pokemonToOwner[_id] = msg.sender; - ownerPokemonCount[msg.sender]++; - emit eventNewPokemon (p); + function createPokemon (string memory _name, uint _id, Ability[] memory _abilities) public { + require(_id > 0, "Pokemon's id should be greater than 0"); + require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); + Pokemon storage pokemon = pokemons.push(); + pokemon.id = _id; + pokemon.name = _name; + for (uint i = 0; i < _abilities.length; i++) { + pokemon.abilities.push(_abilities[i]); + } + + pokemonToOwner[_id] = msg.sender; + ownerPokemonCount[msg.sender]++; + emit eventNewPokemon (pokemon); } function getAllPokemons() public view returns (Pokemon[] memory) { From 8bd7a81c43bf9aadd3bb25b9b2cc314c284f708e Mon Sep 17 00:00:00 2001 From: IvySaskia Date: Tue, 2 Aug 2022 10:11:39 -0400 Subject: [PATCH 4/8] [gelopfalcon/solidity-eth-challenge#3] Add: Reto 3 version 2 --- PokemonFactory.sol | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index ecfeeee4..6264bf0f 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -22,19 +22,26 @@ contract PokemonFactory { event eventNewPokemon (Pokemon pokemon); - function createPokemon (string memory _name, uint _id, Ability[] memory _abilities) public { - require(_id > 0, "Pokemon's id should be greater than 0"); - require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); - Pokemon storage pokemon = pokemons.push(); - pokemon.id = _id; - pokemon.name = _name; - for (uint i = 0; i < _abilities.length; i++) { - pokemon.abilities.push(_abilities[i]); + function createPokemon (string memory _name, uint _id) public { + require(_id > 0, "Pokemon's id should be greater than 0"); + require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); + Pokemon storage pokemon = pokemons.push(); + pokemon.id = _id; + pokemon.name = _name; + pokemonToOwner[_id] = msg.sender; + ownerPokemonCount[msg.sender]++; + emit eventNewPokemon (pokemon); + } + + function addAbilitiesToPokemon(uint _idPokemon, Ability[] memory _abilities) public { + for (uint256 i; i Date: Wed, 3 Aug 2022 14:08:06 -0400 Subject: [PATCH 5/8] [gelopfalcon/solidity-eth-challenge#4] Add: Reto 4 (1) --- PokemonFactory.sol | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index 6264bf0f..76429797 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -8,6 +8,7 @@ contract PokemonFactory { uint id; string name; Ability[] abilities; + PokemonType[] pokemonTypes; } struct Ability { @@ -15,10 +16,31 @@ contract PokemonFactory { string description; } + enum PokemonType { + BUG, + DARK, + DRAGON, + ELECTRIC, + FAIRY, + FIGHTING, + FIRE, + FLYING, + GHOST, + GRASS, + GROUND, + ICE, + NORMAL, + POISON, + PSYCHIC, + ROCK, + STEEL, + WATER + } + Pokemon[] private pokemons; - mapping (uint => address) public pokemonToOwner; - mapping (address => uint) ownerPokemonCount; + mapping (uint => address) public pokemonToOwner; //guarda el id del pokemon vs el address del que esta ejecutando el smart contract, el address viene del frontend + mapping (address => uint) ownerPokemonCount;// vamos a a tener un conteo de la cantidad de pokemones por address. event eventNewPokemon (Pokemon pokemon); @@ -27,7 +49,7 @@ contract PokemonFactory { require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); Pokemon storage pokemon = pokemons.push(); pokemon.id = _id; - pokemon.name = _name; + pokemon.name = _name; pokemonToOwner[_id] = msg.sender; ownerPokemonCount[msg.sender]++; emit eventNewPokemon (pokemon); @@ -44,6 +66,17 @@ contract PokemonFactory { } } + function addTypesToPokemon(uint _idPokemon, PokemonType[] memory _pokemonTypes) public { + for (uint256 i; i Date: Wed, 3 Aug 2022 14:16:46 -0400 Subject: [PATCH 6/8] [gelopfalcon/solidity-eth-challenge#4] Add: Reto 4 (2) --- PokemonFactory.sol | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index 76429797..f53f8aa7 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -9,6 +9,7 @@ contract PokemonFactory { string name; Ability[] abilities; PokemonType[] pokemonTypes; + PokemonType[] weaknesses; } struct Ability { @@ -77,6 +78,17 @@ contract PokemonFactory { } } + function addWeaknessesToPokemon(uint _idPokemon, PokemonType[] memory _pokemonWeaknesses) public { + for (uint256 i; i Date: Wed, 3 Aug 2022 14:34:20 -0400 Subject: [PATCH 7/8] Add: ReadMe --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..503d0325 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# solidity-eth-challenge + +## Imagen mostrando las pruebas hechas a los métodos requeridos +![image](https://user-images.githubusercontent.com/41027286/182682049-6bab47e4-d69f-4cd0-b88f-18f5dbff69cf.png) + + +## Respuestas de investigación +https://ivy-saskia.notion.site/Crea-tu-primer-smart-contract-Actividades-3746a7eb891d4808a9a093a19102d01d From 3328988bcf235f229a8693757794a7871636efb3 Mon Sep 17 00:00:00 2001 From: IvySaskia <41027286+IvySaskia@users.noreply.github.com> Date: Wed, 3 Aug 2022 14:34:55 -0400 Subject: [PATCH 8/8] Update: README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 503d0325..3069a1e4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # solidity-eth-challenge -## Imagen mostrando las pruebas hechas a los métodos requeridos +## Imagen mostrando las pruebas hechas a los métodos requeridos usando REMIX ![image](https://user-images.githubusercontent.com/41027286/182682049-6bab47e4-d69f-4cd0-b88f-18f5dbff69cf.png)