forked from camohe90/platziretoDNFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNFT.sol
129 lines (112 loc) · 4.45 KB
/
DNFT.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;
import "@chainlink/contracts/src/v0.8/KeeperCompatible.sol";
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.6.0/utils/Counters.sol";
contract realStateRegistry is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
using Counters for Counters.Counter;
Counters.Counter public tokenIdCounter;
// Metadata information for each stage of the NFT on IPFS.
// RETO 2: Para este reto, decidí implementar una "simulación" del Registro de Propiedad Inmueble Argentino.
// El NFT dinámico refleja el cambio de estado de dominio de un inmueble en particular.
// Los datos de cada titular se encuentran en cada archivo JSON.
string[] IpfsUri = [
"https://gateway.pinata.cloud/ipfs/QmWJtUzYxYRi4dPBSDysHTL3gU4nf4Q8WwVQZWivqfpazF",
"https://gateway.pinata.cloud/ipfs/QmepKUJ5UZcQvt6mWwFrJgpji1aULpyXwJCCqPoGPcnr8k",
"https://gateway.pinata.cloud/ipfs/QmY1iA8JkpLSKGsnhGerxwucRM5vYtLYHCarBJYPuzArbC",
"https://gateway.pinata.cloud/ipfs/QmPUaDurn29xxhubqc2hysnbYuWb99qsjh7Wp4VCfcpzYz",
"https://gateway.pinata.cloud/ipfs/QmXEJC5L9bfk5kg9X5wxMgr2BHcDQKJXWufV3estUmwrsC"
];
uint256 lastTimeStamp;
uint256 interval;
constructor(uint _interval) ERC721("Arcos 1111, Piso 1, Apartamento 1, Bragado, CABA", "ARCOS1111P1A1") {
interval = _interval;
lastTimeStamp = block.timestamp;
}
function checkUpkeep(bytes calldata /* checkData */) external view override returns (bool upkeepNeeded, bytes memory /* performData */) {
uint256 tokenId = tokenIdCounter.current() - 1;
bool done;
if (domainStage(tokenId) >= IpfsUri.length) {
done = true;
}
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 {
//We highly recommend revalidating the upkeep in the performUpkeep function
if ((block.timestamp - lastTimeStamp) > interval ) {
lastTimeStamp = block.timestamp;
uint256 tokenId = tokenIdCounter.current() - 1;
growDomain(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 {
uint256 tokenId = tokenIdCounter.current();
tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, IpfsUri[0]);
}
function growDomain(uint256 _tokenId) public {
if(domainStage(_tokenId) >= IpfsUri.length){return;}
// Get the current stage of the flower and add 1
uint256 newVal = domainStage(_tokenId) + 1;
// store the new URI
string memory newUri = IpfsUri[newVal];
// Update the URI
_setTokenURI(_tokenId, newUri);
}
// determine the stage of the flower growth
function domainStage(uint256 _tokenId) public view returns (uint256) {
string memory _uri = tokenURI(_tokenId);
// Titular 1
if (compareStrings(_uri, IpfsUri[0])) {
return 0;
}
// Titular 2
if (
compareStrings(_uri, IpfsUri[1])
) {
return 1;
}
// Titular 3
if (
compareStrings(_uri, IpfsUri[2])
) {
return 2;
}
// Titular 4
if (
compareStrings(_uri, IpfsUri[3])
) {
return 3;
}
//Titular 5
return 4;
}
// helper function to compare strings
function compareStrings(string memory a, string memory b)
public
pure
returns (bool)
{
return (keccak256(abi.encodePacked((a))) ==
keccak256(abi.encodePacked((b))));
}
// The following functions is an override required by Solidity.
function _burn(uint256 tokenId)
internal
override(ERC721, ERC721URIStorage)
{
super._burn(tokenId);
}
// The following functions is an override required by Solidity.
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
}