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

first challenge ETH Dinamic NFT #66

Open
wants to merge 1 commit 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
15 changes: 0 additions & 15 deletions Metadata templates/creciendo.json

This file was deleted.

15 changes: 0 additions & 15 deletions Metadata templates/florecida.json

This file was deleted.

15 changes: 0 additions & 15 deletions Metadata templates/semilla.json

This file was deleted.

Binary file removed image/fase 1.jpg
Binary file not shown.
Binary file removed image/fase 2.jpg
Binary file not shown.
Binary file removed image/fase 3.jpg
Binary file not shown.
Binary file removed image/uptadeMetadata_1.jpg
Binary file not shown.
Binary file added images/cedro.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/chanul.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/choiba.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sapan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions json/cedro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Cedro",
"scientific-name": "Cedrela odorata",
"image": "https://gateway.pinata.cloud/ipfs/QmXVkj3aHkdxY9C57QGzhNmE6guUj72UsR5wqGy1Q7iPtj",
"attributes": [
{
"trait-type": "color",
"value": "rojizo"
},
{
"trait-type": "veta",
"value": "textura gruesa"
}
],
"collection-data": [
{
"date": "02/10/2018",
"department": "Magdalena",
"Municipality": "Ariguaní"
}
]
}
22 changes: 22 additions & 0 deletions json/chanul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Chanul",
"scientific-name": "Humiriastrum procerum",
"image": "https://gateway.pinata.cloud/ipfs/QmeriTK2YQipMKvwpoayfnkbCBmjRrzT2zUbrirfCzo3yc",
"attributes": [
{
"trait-type": "color",
"value": "rosa-rojizo"
},
{
"trait-type": "veta",
"value": "suave con bandas marrones"
}
],
"collection-data": [
{
"date": "02/09/2017",
"department": "Valle",
"Municipality": "Guacarí"
}
]
}
22 changes: 22 additions & 0 deletions json/choiba.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Choiba",
"scientific-name": "Dipteryx oleifera",
"image": "https://gateway.pinata.cloud/ipfs/Qmdu8ArJAwRaWAhNpDxHsuGF2LC9YtjiBcyLq6asWSDr9y",
"attributes": [
{
"trait-type": "color",
"value": "marron-amarillento"
},
{
"trait-type": "veta",
"value": "finas y oscuras"
}
],
"collection-data": [
{
"date": "12/07/2020",
"department": "Antioquia",
"Municipality": "Turbo"
}
]
}
22 changes: 22 additions & 0 deletions json/sapan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Sapan",
"scientific-name": "Clathrotropis brunnea",
"image": "https://gateway.pinata.cloud/ipfs/QmRhJ2h5BxW75ad8uLSBGGMxbq2yeayECk68FiAc2VSn5L",
"attributes": [
{
"trait-type": "color",
"value": "catsaño oscuro"
},
{
"trait-type": "veta",
"value": "finas y oscuras"
}
],
"collection-data": [
{
"date": "11/17/2010",
"department": "Bolivar",
"Municipality": "Magangue"
}
]
}
70 changes: 37 additions & 33 deletions DNFT.sol → timberNFT.sol
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
//Begin
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

pragma solidity ^0.8.6;
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/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

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

Counters.Counter public tokenIdCounter;

// 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"
string[] uriData = [
"https://gateway.pinata.cloud/ipfs/QmZnSH1ieNtxBhposr2X9cYadenf2NoSpz9QD4zetUQWEe",
"https://gateway.pinata.cloud/ipfs/QmUcA7Ln1PKcQibTRc5PSwJqAEV4V5AqyGuWVQFZCc9BCB",
"https://gateway.pinata.cloud/ipfs/Qmas6ZQJSmRRRzqp1jmhA4LYVmJFXp4DyaY3Lw4Ei5cceC",
"https://gateway.pinata.cloud/ipfs/QmcTcEAzP2ScPs3Rvhk59CurvGW7CJE3k4kDNTVao1MPWU"
];

uint256 lastTimeStamp;
uint256 interval;

constructor(uint _interval) ERC721("Flower Platzi", "fPLTZ") {
interval = _interval;
Counters.Counter private tokenIdCounter;

constructor(uint _interval) ERC721("TIMBERNFT", "TLT") {
interval = _interval;
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 (woodType(tokenId) >= 2) {
done = true;
}

Expand All @@ -42,43 +40,49 @@ contract keeperFlower is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
if ((block.timestamp - lastTimeStamp) > interval ) {
lastTimeStamp = block.timestamp;
uint256 tokenId = tokenIdCounter.current() - 1;
growFlower(tokenId);
changeWood(tokenId);
}
// We don't use the performData in this example. The performData is generated by the Keeper's call to your checkUpkeep function
}

function safeMint(address to) public {
function safeMint(address to) public {
uint256 tokenId = tokenIdCounter.current();
tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, IpfsUri[0]);
_setTokenURI(tokenId, uriData[0]);
}

function growFlower(uint256 _tokenId) public {
if(flowerStage(_tokenId) >= 2){return;}
function changeWood(uint256 _tokenId) public {
if(woodType(_tokenId) >= uriData.length){return;}
// Get the current stage of the flower and add 1
uint256 newVal = flowerStage(_tokenId) + 1;
uint256 newVal = woodType(_tokenId) + 1;
// store the new URI
string memory newUri = IpfsUri[newVal];
string memory newUri = uriData[newVal];
// Update the URI
_setTokenURI(_tokenId, newUri);
}

// determine the stage of the flower growth
function flowerStage(uint256 _tokenId) public view returns (uint256) {
function woodType(uint256 _tokenId) public view returns (uint256) {
string memory _uri = tokenURI(_tokenId);
// Seed
if (compareStrings(_uri, IpfsUri[0])) {
// choiba wood
if (compareStrings(_uri, uriData[0])) {
return 0;
}
// Sprout
// sapan wood
if (
compareStrings(_uri, IpfsUri[1])
compareStrings(_uri, uriData[1])
) {
return 1;
}
// Must be a Bloom
return 2;
// chanul wood
if (
compareStrings(_uri, uriData[2])
) {
return 2;
}
// cedro wood
return 3;
}

// helper function to compare strings
Expand Down