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

Retos completados #106

Open
wants to merge 3 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
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
.sass-cache
connect.lock
typings

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*


# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Lerna
lerna-debug.log

# System Files
.DS_Store
Thumbs.db
35 changes: 0 additions & 35 deletions PokemonFactory.sol

This file was deleted.

1 change: 1 addition & 0 deletions artifacts/build-info/286cc46e3afb87021a131bc8114d0d94.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\\286cc46e3afb87021a131bc8114d0d94.json"
}
146 changes: 146 additions & 0 deletions artifacts/contracts/PokemonFactory.sol/PokemonFactory.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions artifacts/hardhat/console.sol/console.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\..\\build-info\\286cc46e3afb87021a131bc8114d0d94.json"
}
10 changes: 10 additions & 0 deletions artifacts/hardhat/console.sol/console.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "console",
"sourceName": "hardhat/console.sol",
"abi": [],
"bytecode": "0x60566050600b82828239805160001a6073146043577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220cf6cf4b0c4a758bc9120133b56d845561a085faf5009abef1162b22aae84ec3e64736f6c63430008120033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220cf6cf4b0c4a758bc9120133b56d845561a085faf5009abef1162b22aae84ec3e64736f6c63430008120033",
"linkReferences": {},
"deployedLinkReferences": {}
}
77 changes: 77 additions & 0 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"_format": "hh-sol-cache-2",
"files": {
"C:\\Users\\rabel\\Downloads\\solidity-eth-challenge\\contracts\\PokemonFactory.sol": {
"lastModificationDate": 1678988454170,
"contentHash": "0886bb408d04ffc89b5a303dcd6f87c0",
"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": [
"hardhat/console.sol"
],
"versionPragmas": [
">=0.7.0 <0.9.0"
],
"artifacts": [
"PokemonFactory"
]
},
"C:\\Users\\rabel\\Downloads\\solidity-eth-challenge\\node_modules\\hardhat\\console.sol": {
"lastModificationDate": 1678987928513,
"contentHash": "4ff3cd2f6272c9a6516e9ee4f2b967d3",
"sourceName": "hardhat/console.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.4.22 <0.9.0"
],
"artifacts": [
"console"
]
}
}
}
80 changes: 80 additions & 0 deletions contracts/PokemonFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

import "hardhat/console.sol";


contract PokemonFactory {


struct Ability {
string name;
string description;
}

struct Pokemon {
uint id;
string name;
Ability[] abilities;
Type [] types;
Type [] weakness;

}
enum Type{ NORMAL ,FIGHTING ,FLYING ,POISON ,GROUND ,ROCK ,BUG ,GHOST ,STEEL ,FIRE
,WATER ,GRASS ,ELECTRIC ,PSYCHIC ,ICE ,DRAGON ,DARK ,FAIRY }




Pokemon[] private pokemons;
Ability[] private abilities;



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

event eventNewPokemon(address indexed user, string message);

function createPokemon (string memory _name, uint _id, Ability[] memory _abilities,
Type[] memory _types, Type[] memory _weakness) public {

require( _id > 0, "Debe ingresar un id que sea mayor a 0");
bytes memory str = bytes(_name);
require(str.length != 0, "El nombre no puede estar en blanco.");
require(str.length > 2, "El nombre debe tener minimo mas de dos caracteres.");


pokemons.push();
uint index=pokemons.length-1;
pokemons[index].name=_name;
pokemons[index].id=_id;


//Agregando abilidades
for(uint8 i=0; i < _abilities.length; i++)
pokemons[index].abilities.push(_abilities[i]);

//Agregando types
for(uint8 i=0; i < _types.length; i++)
pokemons[index].types.push(_types[i]);

//Agregando debilidades
for(uint8 i=0; i < _weakness.length; i++)
pokemons[index].weakness.push(_weakness[i]);


//pokemons.push(Pokemon(_id, _name, _abilities));
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;

emit eventNewPokemon(msg.sender, string.concat("The pokemon " , _name , "have been created"));
}

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


}
5 changes: 5 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require("@nomicfoundation/hardhat-toolbox");
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.18",
};
Loading