2
2
// SPDX-License-Identifier: MIT
3
3
pragma solidity >= 0.8.0 ;
4
4
5
- import "./ERC721PresetMinterPauserAutoId.sol " ;
6
- import "./extensions/Strings.sol " ;
7
- import '@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol ' ;
8
- import '@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol ' ;
9
- import '@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol ' ;
10
-
11
- contract DungeonsAndDragonsCharacter is ERC721PresetMinterPauserAutoId , VRFConsumerBaseV2 {
5
+ import './ERC721PresetMinterPauserAutoId.sol ' ;
6
+ import './extensions/Strings.sol ' ;
7
+ // import '@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol';
8
+ // import '@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol';
9
+ // import '@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol';
10
+ // import {VRFConsumerBaseV2Plus} from '@chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol';
11
+ // import {VRFV2PlusClient} from '@chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol';
12
+
13
+ contract DungeonsAndDragonsCharacter is ERC721PresetMinterPauserAutoId {
12
14
using Strings for string ;
13
15
14
- event FulfillRandomness (uint256 ,uint256 []);
15
- event RequestId (address ,uint256 );
16
+ // event FulfillRandomness(uint256, uint256[]);
17
+ // event RequestId(address, uint256);
18
+
19
+ // struct RequestStatus {
20
+ // bool fulfilled; // whether the request has been successfully fulfilled
21
+ // bool exists; // whether a requestId exists
22
+ // uint256[] randomWords;
23
+ // }
24
+
25
+ // mapping(uint256 => RequestStatus) public s_requests; /* requestId --> requestStatus */
16
26
17
- VRFCoordinatorV2Interface COORDINATOR;
18
- LinkTokenInterface LINKTOKEN;
27
+ // VRFCoordinatorV2Interface COORDINATOR;
28
+ // LinkTokenInterface LINKTOKEN;
19
29
20
30
// Your subscription ID.
21
- uint64 s_subscriptionId;
31
+ // uint256 s_subscriptionId;
22
32
23
- // Goerli coordinator. For other networks,
33
+ // sepolia coordinator. For other networks,
24
34
// see https://docs.chain.link/docs/vrf-contracts/#configurations
25
- address vrfCoordinator = 0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D ;
35
+ // address vrfCoordinator = 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B ;
26
36
27
- // Goerli LINK token contract. For other networks,
37
+ // sepolia LINK token contract. For other networks,
28
38
// see https://docs.chain.link/docs/vrf-contracts/#configurations
29
- address link = 0x326C977E6efc84E512bB9C30f76E30c160eD06FB ;
39
+ // address link = 0x779877A7B0D9E8603169DdbD7836e478b4624789 ;
30
40
31
41
// The gas lane to use, which specifies the maximum gas price to bump to.
32
42
// For a list of available gas lanes on each network,
33
43
// see https://docs.chain.link/docs/vrf-contracts/#configurations
34
- bytes32 keyHash = 0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15 ;
44
+ // bytes32 keyHash = 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae ;
35
45
36
46
// Depends on the number of requested values that you want sent to the
37
47
// fulfillRandomWords() function. Storing each word costs about 20,000 gas,
@@ -64,74 +74,56 @@ contract DungeonsAndDragonsCharacter is ERC721PresetMinterPauserAutoId, VRFConsu
64
74
65
75
Character[] public characters;
66
76
67
- mapping (uint256 => string ) requestToCharacterName;
68
- mapping (uint256 => address ) requestToSender;
69
- mapping (uint256 => uint256 ) requestToRandnum;
70
-
71
- constructor (uint64 subscriptionId ,string memory tokenURI )
72
- public
73
- VRFConsumerBaseV2 (vrfCoordinator)
74
- ERC721PresetMinterPauserAutoId ("DungeonsAndDragonsCharacter " , "D&D " ,tokenURI)
75
- {
76
- COORDINATOR = VRFCoordinatorV2Interface (vrfCoordinator);
77
- LINKTOKEN = LinkTokenInterface (link);
78
- s_subscriptionId = subscriptionId;
79
- }
80
-
81
- function requestNewRandomCharacter (
82
- string memory name
83
- ) public returns (uint256 ) {
84
- // Will revert if subscription is not set and funded.
85
- uint256 requestId = COORDINATOR.requestRandomWords (keyHash, s_subscriptionId, requestConfirmations, callbackGasLimit, numWords);
86
- emit RequestId (msg .sender ,requestId);
87
-
88
- requestToCharacterName[requestId] = name;
89
- requestToSender[requestId] = msg .sender ;
90
- return requestId;
91
- }
77
+ // mapping(uint256 => string) requestToCharacterName;
78
+ // mapping(uint256 => address) requestToSender;
79
+ // mapping(uint256 => uint256) requestToRandnum;
80
+
81
+ constructor (string memory tokenURI , string memory _name ) public ERC721PresetMinterPauserAutoId (_name, 'D&D ' , tokenURI) {}
82
+
83
+ // @param enableNativePayment: Set to `true` to enable payment in native tokens, or
84
+ // `false` to pay in LINK
85
+ // function requestNewRandomCharacter(string memory name, bool enableNativePayment) public returns (uint256) {
86
+ // // Will revert if subscription is not set and funded.
87
+ // // uint256 requestId = s_vrfCoordinator.requestRandomWords(keyHash, s_subscriptionId, requestConfirmations, callbackGasLimit, numWords);
88
+ // uint256 requestId = s_vrfCoordinator.requestRandomWords(
89
+ // VRFV2PlusClient.RandomWordsRequest({
90
+ // keyHash: keyHash,
91
+ // subId: s_subscriptionId,
92
+ // requestConfirmations: requestConfirmations,
93
+ // callbackGasLimit: callbackGasLimit,
94
+ // numWords: numWords,
95
+ // extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: enableNativePayment}))
96
+ // })
97
+ // );
98
+ // requestToCharacterName[requestId] = name;
99
+ // requestToSender[requestId] = msg.sender;
100
+ // emit RequestId(msg.sender, requestId);
101
+ // return requestId;
102
+ // }
92
103
93
104
function setTokenURI (uint256 tokenId , string memory _tokenURI ) public {
94
- require (
95
- _isApprovedOrOwner (_msgSender (), tokenId),
96
- "ERC721: transfer caller is not owner nor approved "
97
- );
105
+ require (_isApprovedOrOwner (_msgSender (), tokenId), 'ERC721: transfer caller is not owner nor approved ' );
98
106
_setTokenURI (tokenId, _tokenURI);
99
107
}
100
108
101
- function fulfillRandomWords (
102
- uint256 requestId , /* requestId */
103
- uint256 [] memory randomWords )
104
- internal override
105
- {
106
- requestToRandnum[requestId] = randomWords[0 ];
109
+ // function fulfillRandomWords(uint256 _requestId /* requestId */, uint256[] calldata _randomWords) internal override {
110
+ // requestToRandnum[_requestId] = _randomWords[0];
111
+ // emit FulfillRandomness(_requestId, _randomWords);
112
+ // }
107
113
108
- emit FulfillRandomness (requestId,randomWords);
109
- }
110
-
111
- function blindCharacter (uint256 requestId ) public {
112
- uint256 randomNum = requestToRandnum[requestId];
114
+ function blindCharacter (uint256 _randomNum , address _requestToSender , string memory _name ) public {
113
115
uint256 newId = characters.length ;
116
+ uint256 randomNum = _randomNum;
114
117
uint256 strength = (randomNum % 100 );
115
- uint256 dexterity = ((randomNum % 10000 ) / 100 );
116
- uint256 constitution = ((randomNum % 1000000 ) / 10000 );
117
- uint256 intelligence = ((randomNum % 100000000 ) / 1000000 );
118
- uint256 wisdom = ((randomNum % 10000000000 ) / 100000000 );
118
+ uint256 dexterity = ((randomNum % 10000 ) / 100 );
119
+ uint256 constitution = ((randomNum % 1000000 ) / 10000 );
120
+ uint256 intelligence = ((randomNum % 100000000 ) / 1000000 );
121
+ uint256 wisdom = ((randomNum % 10000000000 ) / 100000000 );
119
122
uint256 charisma = ((randomNum % 1000000000000 ) / 10000000000 );
120
123
uint256 experience = 0 ;
121
124
122
- characters.push (
123
- Character (
124
- strength,
125
- dexterity,
126
- constitution,
127
- intelligence,
128
- wisdom,
129
- charisma,
130
- experience,
131
- requestToCharacterName[requestId]
132
- )
133
- );
134
- _safeMint (requestToSender[requestId], newId);
125
+ characters.push (Character (strength, dexterity, constitution, intelligence, wisdom, charisma, experience, _name));
126
+ _safeMint (_requestToSender, newId);
135
127
}
136
128
137
129
function getLevel (uint256 tokenId ) public view returns (uint256 ) {
@@ -142,21 +134,17 @@ contract DungeonsAndDragonsCharacter is ERC721PresetMinterPauserAutoId, VRFConsu
142
134
return characters.length ;
143
135
}
144
136
145
- function getCharacterOverView (uint256 tokenId )
146
- public
147
- view
148
- returns (
149
- string memory ,
150
- uint256 ,
151
- uint256 ,
152
- uint256
153
- )
154
- {
137
+ function getCharacterOverView (uint256 tokenId ) public view returns (string memory , uint256 , uint256 , uint256 ) {
155
138
return (
156
- characters[tokenId].name,
157
- characters[tokenId].strength + characters[tokenId].dexterity + characters[tokenId].constitution + characters[tokenId].intelligence + characters[tokenId].wisdom + characters[tokenId].charisma,
158
- getLevel (tokenId),
159
- characters[tokenId].experience
139
+ characters[tokenId].name,
140
+ characters[tokenId].strength +
141
+ characters[tokenId].dexterity +
142
+ characters[tokenId].constitution +
143
+ characters[tokenId].intelligence +
144
+ characters[tokenId].wisdom +
145
+ characters[tokenId].charisma,
146
+ getLevel (tokenId),
147
+ characters[tokenId].experience
160
148
);
161
149
}
162
150
@@ -169,12 +157,12 @@ contract DungeonsAndDragonsCharacter is ERC721PresetMinterPauserAutoId, VRFConsu
169
157
}
170
158
}
171
159
172
- // expand to more random
173
- // function expand(uint256 randomValue, uint256 n) public pure returns (uint256[] memory expandedValues) {
174
- // expandedValues = new uint256[](n);
175
- // for (uint256 i = 0; i < n; i++) {
176
- // expandedValues[i] = uint256(keccak256(abi.encode(randomValue, i)));
177
- // }
178
- // return expandedValues;
179
- // }
160
+ // expand to more random
161
+ // function expand(uint256 randomValue, uint256 n) public pure returns (uint256[] memory expandedValues) {
162
+ // expandedValues = new uint256[](n);
163
+ // for (uint256 i = 0; i < n; i++) {
164
+ // expandedValues[i] = uint256(keccak256(abi.encode(randomValue, i)));
165
+ // }
166
+ // return expandedValues;
167
+ // }
180
168
}
0 commit comments