Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lesson-1/chapter-13/Contract.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pragma solidity ^0.4.25;
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ZombieFactory {

// declare our event here
event NewZombie(uint zombieId, string name, uint dna);

uint dnaDigits = 16;
Expand All @@ -14,19 +15,20 @@ contract ZombieFactory {

Zombie[] public zombies;

function _createZombie(string _name, uint _dna) private {
uint id = zombies.push(Zombie(_name, _dna)) - 1;
function _createZombie(string memory _name, uint _dna) private {
zombies.push(Zombie(_name, _dna));
uint id = zombies.length -1;
emit NewZombie(id, _name, _dna);
}

function _generateRandomDna(string _str) private view returns (uint) {
function _generateRandomDna(string memory _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}

function createRandomZombie(string _name) public {
function createRandomZombie(string memory _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}

}
}