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

Reto 1 Ethereum Developer Program #107

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
35 changes: 0 additions & 35 deletions PokemonFactory.sol

This file was deleted.

1 change: 1 addition & 0 deletions artifacts/build-info/f1e77b9c374db68ed896b3e5ceef49da.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\..\\build-info\\f1e77b9c374db68ed896b3e5ceef49da.json"
}
197 changes: 197 additions & 0 deletions artifacts/contracts/PokemonFactory.sol/PokemonFactory.json

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"_format": "hh-sol-cache-2",
"files": {
"J:\\Curso\\blockchain\\solidity-eth-challenge\\contracts\\PokemonFactory.sol": {
"lastModificationDate": 1679067774333,
"contentHash": "2c5707b16b1e2ac7587dfd4f6d34b261",
"sourceName": "contracts/PokemonFactory.sol",
"solcConfig": {
"version": "0.8.18",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
">=0.7.0 <0.9.0"
],
"artifacts": [
"PokemonFactory"
]
}
}
}
81 changes: 81 additions & 0 deletions contracts/PokemonFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract PokemonFactory {



struct Pokemon {
uint id;
string name;
Tipos [] Type;
Tipos [] Weaknesses;
uint[] Habilities;
}

struct Habilities {
string Name;
string Description;
}

event eventNewPokemon(
uint id,
string name
);

modifier onlyId (uint _id) {
require( _id > 0,
"El id de tu pokemon debe ser mayor a 0");
_;
}

modifier onlyName (string memory _name) {
require( bytes(_name).length > 2,
"El nombre de tu pokemon debe ser mayor a 2 caracteres");
_;
}
modifier onlyOwner(uint _id) {
require(msg.sender == pokemonToOwner[_id],
"este pokemon no es tuyo");
_;
}

Pokemon[] private pokemons;

enum Tipos {fire, water, grass, electric, psychic, ghost, dragon, normal, fighting, flying, poison, ground, rock, bug, steel, fairy, ice, dark}

mapping (uint => address) public pokemonToOwner;
mapping (address => uint) ownerPokemonCount;
mapping (uint => Habilities[]) public pokemonHabilities;

function createPokemon (uint _id, string memory _name, Tipos[] memory _Type, Tipos[] memory _Weaknesses, uint[] memory _habilities) public onlyId(_id) onlyName(_name) {
pokemons.push(Pokemon(_id, _name, _Type, _Weaknesses, _habilities));
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;

for (uint i = 0; i < _habilities.length; i++) {
pokemonHabilities[_id].push(Habilities("",""));
}

emit eventNewPokemon(_id, _name);
}

function pokemonEvolution (uint _pokemonId, uint _habilityIndex, string memory _name, string memory _description) public onlyOwner(_pokemonId){
pokemonHabilities[_pokemonId][_habilityIndex] = Habilities(_name, _description);

}

function getAllPokemons() public view returns (Pokemon[] memory) {
return (pokemons);
}


function getResult() public pure returns(uint product, uint sum){
uint a = 1;
uint b = 2;
product = a * b;
sum = a + b;
}

}
6 changes: 6 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.18",
};
Loading