Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ivy Saskia Sejas Rocabado-solidity-eth-challenge #85

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
85 changes: 77 additions & 8 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,89 @@ pragma solidity >=0.7.0 <0.9.0;

contract PokemonFactory {

struct Pokemon {
uint id;
string name;
}
struct Pokemon {
uint id;
string name;
Ability[] abilities;
PokemonType[] pokemonTypes;
PokemonType[] weaknesses;
}

struct Ability {
string name;
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);

function createPokemon (string memory _name, uint _id) public {
pokemons.push(Pokemon(_id, _name));
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<pokemons.length; i++) {
if (pokemons[i].id == _idPokemon) {
for (uint j = 0; j < _abilities.length; j++) {
pokemons[i].abilities.push(_abilities[j]);
}
break;
}
}
}

function addTypesToPokemon(uint _idPokemon, PokemonType[] memory _pokemonTypes) public {
for (uint256 i; i<pokemons.length; i++) {
if (pokemons[i].id == _idPokemon) {
for (uint j = 0; j < _pokemonTypes.length; j++) {
pokemons[i].pokemonTypes.push(_pokemonTypes[j]);
}
break;
}
}
}

function addWeaknessesToPokemon(uint _idPokemon, PokemonType[] memory _pokemonWeaknesses) public {
for (uint256 i; i<pokemons.length; i++) {
if (pokemons[i].id == _idPokemon) {
for (uint j = 0; j < _pokemonWeaknesses.length; j++) {
pokemons[i].weaknesses.push(_pokemonWeaknesses[j]);
}
break;
}
}
}

function getAllPokemons() public view returns (Pokemon[] memory) {
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# solidity-eth-challenge

## 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)


## Respuestas de investigación
https://ivy-saskia.notion.site/Crea-tu-primer-smart-contract-Actividades-3746a7eb891d4808a9a093a19102d01d