Skip to content

Commit

Permalink
馃敡馃崱 -> Updating dna -> randomNum function for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Feb 5, 2022
1 parent 5786139 commit 32eeb30
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion contracts/CreditTokenRef.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"


contract LipToken is ERC721, Ownable {
constructor(string memory _name, string memory _symbol)
Expand Down
8 changes: 4 additions & 4 deletions contracts/GearToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ contract GearToken is ERC721, Ownable {
event NewGear(address indexed owner, uint256 id, uint256 dna);

// Helpers
function _genRandomDna(string memory _str) internal pure returns(uint256) { // generate DNA
uint256 randomNum = uint256(keccak256(abi.encodePacked(_str))); // Takes the string input into function _genRandomDna and hashes it into a random number (keccak256)
return randomNum % 10**16; // Make sure number is 16 digits
function _createRandomNum(uint256 _mod) internal view returns(uint256) { // generate DNA
uint256 randomNum = uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender))); // Takes the string input into function _genRandomDna and hashes it into a random number (keccak256)
return randomNum % _mod;
}

// Minting/creation stage of the token
Expand All @@ -40,7 +40,7 @@ contract GearToken is ERC721, Ownable {
}

function createRandomGear(string memory _name) public {
uint256 randDna = _genRandomDna(_name);
uint256 randDna = _createRandomNum(10**16);
_createGear(_name, randDna);
}

Expand Down

0 comments on commit 32eeb30

Please sign in to comment.