forked from cy0802/data_storing_via_blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileStore.sol
50 lines (43 loc) · 1.63 KB
/
fileStore.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
//SPDX-License-Identifier: Unlicense
// make sure you have the same solidity version with hardhat.config.js
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract fileStore is ERC721 {
uint256 public tokenCounter;
// tokenid => tokenURI
mapping (uint256 => string) private _tokenURIs;
constructor(string memory name, string memory symbol) ERC721(name, symbol) {
tokenCounter = 0;
}
function mint(string memory _tokenURI) public {
_safeMint(msg.sender, tokenCounter);
_setTokenURI(tokenCounter, _tokenURI);
tokenCounter++;
}
function _setTokenURI(uint256 _tokenId, string memory _tokenURI) internal virtual {
require(
_exists(_tokenId),
"ERC721Metadata: URI set of nonexistent token"
);
_tokenURIs[_tokenId] = _tokenURI;
}
function tokenURI(uint256 _tokenId) public view virtual override returns(string memory) {
require(
_exists(_tokenId),
"ERC721Metadata: URI set of nonexistent token"
);
return _tokenURIs[_tokenId];
}
function isApprovedForAll(
address _owner,
address _operator
) public override view returns (bool isOperator) {
// 為了加快發佈到opensea速度,才寫這段code
// if OpenSea's ERC721 Proxy Address is detected, auto-return true
if (_operator == address(0x58807baD0B376efc12F5AD86aAc70E78ed67deaE)) {
return true;
}
// otherwise, use the default ERC721.isApprovedForAll()
return ERC721.isApprovedForAll(_owner, _operator);
}
}