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 1,2 y 3 terminados. #48

Open
wants to merge 2 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
101 changes: 77 additions & 24 deletions DNFT.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
//Begin
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;
pragma solidity 0.8.9;

import "@chainlink/contracts/src/v0.8/KeeperCompatible.sol";
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/[email protected]/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

contract keeperFlower is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
contract keeperFlower is
ERC721,
ERC721URIStorage,
KeeperCompatibleInterface,
ERC721Enumerable
{
using Counters for Counters.Counter;

Counters.Counter public tokenIdCounter;
// Metadata information for each stage of the NFT on IPFS.

// Metadata information for each stage of the NFT on IPFS.
string[] IpfsUri = [
"https://ipfs.io/ipfs/QmYaTsyxTDnrG4toc8721w62rL4ZBKXQTGj9c9Rpdrntou/seed.json",
"https://ipfs.io/ipfs/QmYaTsyxTDnrG4toc8721w62rL4ZBKXQTGj9c9Rpdrntou/purple-sprout.json",
"https://ipfs.io/ipfs/QmYaTsyxTDnrG4toc8721w62rL4ZBKXQTGj9c9Rpdrntou/purple-blooms.json"
];
"https://gateway.pinata.cloud/ipfs/QmTeUY5Ge3gnBMs4jw43Sv75eNj32VTTacWkyN5jGV8bnp",
"https://gateway.pinata.cloud/ipfs/QmVBCuXcYVVoAJZ33nrepgTiFS5zf4hNPhyRtNg1LmGnah",
"https://gateway.pinata.cloud/ipfs/QmQUE7Q5Aj2aSbLXfV7tYXyJ4gpiYFdMSgqrR5LDTNT1qi",
"https://gateway.pinata.cloud/ipfs/QmRpNRaEfQx9ZRm4UeKsfZCDcC8RQeoU49uFhHCb1EtxAR",
"https://gateway.pinata.cloud/ipfs/QmdQk4wsvhd4opmbk7pQsGCJKnCU7FAv17qTgfQn5mtc69"
];

uint256 lastTimeStamp;
uint256 interval;
Expand All @@ -26,21 +33,33 @@ contract keeperFlower is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
lastTimeStamp = block.timestamp;
}

function checkUpkeep(bytes calldata /* checkData */) external view override returns (bool upkeepNeeded, bytes memory /* performData */) {
function checkUpkeep(
bytes calldata /* checkData */
)
external
view
override
returns (
bool upkeepNeeded,
bytes memory /* performData */
)
{
uint256 tokenId = tokenIdCounter.current() - 1;
bool done;
if (flowerStage(tokenId) >= 2) {
if (flowerStage(tokenId) >= 4) {
done = true;
}

upkeepNeeded = !done && ((block.timestamp - lastTimeStamp) > interval);
upkeepNeeded = !done && ((block.timestamp - lastTimeStamp) > interval);
// We don't use the checkData in this example. The checkData is defined when the Upkeep was registered.
}

function performUpkeep(bytes calldata /* performData */) external override {
function performUpkeep(
bytes calldata /* performData */
) external override {
//We highly recommend revalidating the upkeep in the performUpkeep function
if ((block.timestamp - lastTimeStamp) > interval ) {
lastTimeStamp = block.timestamp;
if ((block.timestamp - lastTimeStamp) > interval) {
lastTimeStamp = block.timestamp;
uint256 tokenId = tokenIdCounter.current() - 1;
growFlower(tokenId);
}
Expand All @@ -54,8 +73,14 @@ contract keeperFlower is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
_setTokenURI(tokenId, IpfsUri[0]);
}

function updateNFT(uint _tokenId, string memory newUri) public {
_setTokenURI(_tokenId, newUri);
}

function growFlower(uint256 _tokenId) public {
if(flowerStage(_tokenId) >= 2){return;}
if (flowerStage(_tokenId) >= 4) {
return;
}
// Get the current stage of the flower and add 1
uint256 newVal = flowerStage(_tokenId) + 1;
// store the new URI
Expand All @@ -72,13 +97,23 @@ contract keeperFlower is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
return 0;
}
// Sprout
if (
compareStrings(_uri, IpfsUri[1])
) {
if (compareStrings(_uri, IpfsUri[1])) {
return 1;
}
// Must be a Bloom
return 2;
// Growing
if (compareStrings(_uri, IpfsUri[2])) {
return 2;
}
// Flourished
if (compareStrings(_uri, IpfsUri[3])) {
return 3;
}
// Is a final stage
if (compareStrings(_uri, IpfsUri[4])) {
return 4;
}
// Is a custom URI
return 5;
}

// helper function to compare strings
Expand Down Expand Up @@ -108,5 +143,23 @@ contract keeperFlower is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
{
return super.tokenURI(tokenId);
}

// The following functions is an override required by Solidity.
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}

// The following functions is an override required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
//End
15 changes: 15 additions & 0 deletions Metadata templates/1-semilla.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Flor semilla",
"description": "El aprendizaje empieza con la semilla de la curiosidad, estamos motivados y con ganas de empezar",
"image": "https://gateway.pinata.cloud/ipfs/QmXWE7cXbwegUX6uZA1DmWwGSuCk33r9UHskB1UBfvJXVJ",
"attributes": [
{
"trait-type": "EtapaFLor",
"value": "Semilla"
},
{
"trait-type": "ColorFlor",
"value": "CAFE"
}
]
}
15 changes: 15 additions & 0 deletions Metadata templates/2-germinando.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Flor germinando",
"description": "Empezamos a absorver conocimiento y trazamos la ruta y el objetivo",
"image": "https://gateway.pinata.cloud/ipfs/QmWchvQHz2vT6moCKJvaV3g6YSiyNxKmpcdXKqfeLLkGXg",
"attributes": [
{
"trait-type": "EtapaFLor",
"value": "Germinando"
},
{
"trait-type": "ColorFlor",
"value": "VERDE"
}
]
}
15 changes: 15 additions & 0 deletions Metadata templates/3-creciendo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Flor creciendo",
"description": "Empezamos a crecer y absorver conocimiento, siempre tenemos sed de saber mas",
"image": "https://gateway.pinata.cloud/ipfs/QmUeQCRLXxUQy2NDgm2jgmtCpRNMUr2UQCnRpbgkN7nDGw",
"attributes": [
{
"trait-type": "EtapaFLor",
"value": "Creciendo"
},
{
"trait-type": "ColorFlor",
"value": "VERDE"
}
]
}
15 changes: 15 additions & 0 deletions Metadata templates/4-floreciendo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Flor floreciendo",
"description": "Comprendemos y aplicamos lo que aprendemos, estamos listos para resolver problemas",
"image": "https://gateway.pinata.cloud/ipfs/QmT3yQnmkVpTJ1Bjr6bPxvY4kCikZg67PRiEV74hUH3fUP",
"attributes": [
{
"trait-type": "EtapaFLor",
"value": "Floreciendo"
},
{
"trait-type": "ColorFlor",
"value": "VERDE"
}
]
}
15 changes: 15 additions & 0 deletions Metadata templates/5-frutos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Flor frutos",
"description": "Somos expertos y ahora nuestro conocimiento lo compartimos con los demás pero sin dejar de aprender",
"image": "https://gateway.pinata.cloud/ipfs/QmZELcES5wVASQAfygr1rudvmv7dDvQkh57GHhAV6uDZqV",
"attributes": [
{
"trait-type": "EtapaFLor",
"value": "Frutos"
},
{
"trait-type": "ColorFlor",
"value": "VERDE-NARANJA"
}
]
}
23 changes: 23 additions & 0 deletions front-end/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions front-end/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
29 changes: 29 additions & 0 deletions front-end/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const webpack = require('webpack');
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
assert: require.resolve('assert'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify'),
url: require.resolve('url'),
});
config.resolve.fallback = fallback;
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: 'process/browser.js',
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
]);
config.module.rules.unshift({
test: /\.m?js$/,
resolve: {
fullySpecified: false, // disable the behavior
},
});
return config;
};
7 changes: 7 additions & 0 deletions front-end/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd ./build
FILES=$(find * -type f | awk -v q="'" '{print " -F " q "file=@\"" $0 "\";filename=\"" $0 "\"" q}')
# curl -X POST -F file='Hola mundo' -u "2DQEQZRAaAdrLXnWf0SUQLmng0j:a4ea750d8efd36735976ddf2b037e848" "https://ipfs.infura.io:5001/api/v0/add"
curl -u "2DQEQZRAaAdrLXnWf0SUQLmng0j:a4ea750d8efd36735976ddf2b037e848" "https://ipfs.infura.io:5001/api/v0/add?pin=true&recursive=true&wrap-with-directory=true&cid-version=1" -vv -X POST $FILES
cd ..
Loading