-
Notifications
You must be signed in to change notification settings - Fork 0
/
BetNFT.sol
60 lines (48 loc) · 1.98 KB
/
BetNFT.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
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
contract BetNFT is ERC721, Ownable {
using Strings for uint256;
struct BetDetails {
string matchId;
uint256 betId;
}
// Optional mapping for token URIs
mapping (uint256 => string) private _tokenURIs;
mapping (uint256 => BetDetails) private _betIds;
constructor(string memory _name, string memory _symbol)
ERC721(_name, _symbol)
{}
function _setTokenURI(uint256 tokenId, string memory ipfsLocation,
string memory _matchId, uint256 _betId) internal virtual {
require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
_tokenURIs[tokenId] = ipfsLocation;
_betIds[tokenId] = BetDetails({matchId: _matchId, betId: _betId});
}
function tokenURI(uint256 tokenId)
public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
return _tokenURIs[tokenId];
}
function getTokenURI(uint256 tokenId)
external view returns (string memory) {
return tokenURI(tokenId);
}
function getBetDetails(uint256 tokenId)
external view returns (string memory matchId, uint256 betId) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
matchId = _betIds[tokenId].matchId;
betId = _betIds[tokenId].betId;
}
function redeemCollectible(uint256 tokenId) external {
require(_exists(tokenId), "ERC721: token doesn't exist");
_burn(tokenId);
delete _betIds[tokenId];
}
function mint(address _to, uint256 _tokenId, string calldata matchId,
uint256 _betId, string calldata ipfsLocation) external {
// call to ERC721 mint function
_mint(_to, _tokenId);
// Wrap it with details we need
_setTokenURI(_tokenId, ipfsLocation, matchId, _betId);
}
}