Skip to content

Commit

Permalink
Synchronize with staging (CryptozombiesHQ#368)
Browse files Browse the repository at this point in the history
* lesson 5,6, 9

lesson 5,6, 9

* 7,8, and index.json

* Revert "7,8, and index.json"

This reverts commit fc1bf20.

* fixed lesson 9 folder name

fixed lesson 9 folder name

* synchronize with staging

synchronize with staging
  • Loading branch information
andreipope authored and mattkanwisher committed Nov 27, 2018
1 parent 1d1d084 commit 6c73526
Show file tree
Hide file tree
Showing 88 changed files with 13,193 additions and 845 deletions.
4 changes: 2 additions & 2 deletions en/1/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -21,7 +21,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
8 changes: 4 additions & 4 deletions en/1/arraysstructs2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -19,13 +19,13 @@ material:
Zombie[] public zombies;
function createZombie(string _name, uint _dna) {
function createZombie (string _name, uint _dna) {
// start here
}
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -40,7 +40,7 @@ material:
Zombie[] public zombies;
function createZombie(string _name, uint _dna) {
function createZombie (string _name, uint _dna) {
zombies.push(Zombie(_name, _dna));
}
Expand Down
8 changes: 4 additions & 4 deletions en/1/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ material:
//2. Create contract here
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -33,12 +33,12 @@ contract HelloWorld {

All solidity source code should start with a "version pragma" — a declaration of the version of the Solidity compiler this code should use. This is to prevent issues with future compiler versions potentially introducing changes that would break your code.

It looks like this: `pragma solidity ^0.4.19;` (for the latest solidity version at the time of this writing, 0.4.19).
It looks like this: `pragma solidity ^0.4.25;` (for the latest solidity version at the time of this writing, 0.4.25).

Putting it together, here is a bare-bones starting contract — the first thing you'll write every time you start a new project:

```
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract HelloWorld {
Expand All @@ -49,7 +49,7 @@ contract HelloWorld {

To start creating our Zombie army, let's create a base contract called `ZombieFactory`.

1. In the box to the right, make it so our contract uses solidity version `0.4.19`.
1. In the box to the right, make it so our contract uses solidity version `0.4.25`.

2. Create an empty contract called `ZombieFactory`.

Expand Down
4 changes: 2 additions & 2 deletions en/1/datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
//start here
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
12 changes: 6 additions & 6 deletions en/1/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -27,7 +27,7 @@ material:
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
Expand All @@ -38,7 +38,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -57,11 +57,11 @@ material:
function _createZombie(string _name, uint _dna) private {
uint id = zombies.push(Zombie(_name, _dna)) - 1;
NewZombie(id, _name, _dna);
emit NewZombie(id, _name, _dna);
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
Expand All @@ -86,7 +86,7 @@ event IntegersAdded(uint x, uint y, uint result);
function add(uint _x, uint _y) public {
uint result = _x + _y;
// fire an event to let the app know the function was called:
IntegersAdded(_x, _y, result);
emit IntegersAdded(_x, _y, result);
return result;
}
```
Expand Down
4 changes: 2 additions & 2 deletions en/1/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -23,7 +23,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
4 changes: 2 additions & 2 deletions en/1/functions2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -25,7 +25,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
4 changes: 2 additions & 2 deletions en/1/functions3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -27,7 +27,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
17 changes: 10 additions & 7 deletions en/1/keccak256.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -29,7 +29,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -49,7 +49,7 @@ material:
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
Expand All @@ -58,17 +58,20 @@ material:

We want our `_generateRandomDna` function to return a (semi) random `uint`. How can we accomplish this?

Ethereum has the hash function `keccak256` built in, which is a version of SHA3. A hash function basically maps an input string into a random 256-bit hexidecimal number. A slight change in the string will cause a large change in the hash.
Ethereum has the hash function `keccak256` built in, which is a version of SHA3. A hash function basically maps an input into a random 256-bit hexidecimal number. A slight change in the input will cause a large change in the hash.

It's useful for many purposes in Ethereum, but for right now we're just going to use it for pseudo-random number generation.


Also important, `keccak256` expects a single parameter of type `bytes`. This means that we have to "pack" any parameters before calling `keccak256`:

Example:

```
//6e91ec6b618bb462a4a6ee5aa2cb0e9cf30f7a052bb467b0ba58b8748c00d2e5
keccak256("aaaab");
keccak256(abi.encodePacked("aaaab"));
//b1f078126895a1424524de5321b339ab00408010b7cf0e6ed451514981e58aa9
keccak256("aaaac");
keccak256(abi.encodePacked("aaaac"));
```

As you can see, the returned values are totally different despite only a 1 character change in the input.
Expand All @@ -94,6 +97,6 @@ In the above, `a * b` returns a `uint`, but we were trying to store it as a `uin

Let's fill in the body of our `_generateRandomDna` function! Here's what it should do:

1. The first line of code should take the `keccak256` hash of `_str` to generate a pseudo-random hexidecimal, typecast it as a `uint`, and finally store the result in a `uint` called `rand`.
1. The first line of code should take the `keccak256` hash of `abi.encodePacked(_str)` to generate a pseudo-random hexidecimal, typecast it as a `uint`, and finally store the result in a `uint` called `rand`.

2. We want our DNA to only be 16 digits long (remember our `dnaModulus`?). So the second line of code should `return` the above value modulus (`%`) `dnaModulus`.
4 changes: 2 additions & 2 deletions en/1/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -14,7 +14,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
8 changes: 4 additions & 4 deletions en/1/puttingittogether.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -24,15 +24,15 @@ material:
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
// start here
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -52,7 +52,7 @@ material:
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
Expand Down
4 changes: 2 additions & 2 deletions en/1/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ material:
editor:
language: sol
startingCode: |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -16,7 +16,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand Down
10 changes: 5 additions & 5 deletions en/2/10-interactingcontracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ material:
language: sol
startingCode:
"zombiefeeding.sol": |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
import "./zombiefactory.sol";
Expand All @@ -24,7 +24,7 @@ material:
}
"zombiefactory.sol": |
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
contract ZombieFactory {
Expand All @@ -47,11 +47,11 @@ material:
uint id = zombies.push(Zombie(_name, _dna)) - 1;
zombieToOwner[id] = msg.sender;
ownerZombieCount[msg.sender]++;
NewZombie(id, _name, _dna);
emit NewZombie(id, _name, _dna);
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
Expand All @@ -63,7 +63,7 @@ material:
}
answer: >
pragma solidity ^0.4.19;
pragma solidity ^0.4.25;
import "./zombiefactory.sol";
Expand Down
Loading

0 comments on commit 6c73526

Please sign in to comment.