forked from CryptozombiesHQ/cryptozombie-lessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into lang-ko-patch
- Loading branch information
Showing
58 changed files
with
2,023 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: ์ข๋น๊ฐ ํฌ์๋ฌผ์ ๊ณต๊ฒฉํ๋ค | ||
header: ๊ทธ๋ฌ๋๊น ์๋ค๊ฐ ๋ ์จ 2์ ์๋ค๋ ๊ฑฐ๊ตฐ! | ||
roadmap: roadmap2.jpg | ||
--- | ||
|
||
ํ๋ฅญํ๋ค, ์ธ๊ฐ์ด์ฌ! ๋ด๊ฐ ์๊ฐํ๋ ๊ฒ๋ณด๋ค ์๋ค๊ฐ ์ฝ๋ฉ์ ๋ ์ํ๋๊ตฐ. | ||
|
||
๋ ์จ 2๋ **์ข๋น์๊ฒ ๋ค๋ฅธ ์๋ช ์ฒด๋ฅผ ๋จน์ฌ์ ์ข๋น ๊ตฐ๋์ ๊ท๋ชจ๋ฅผ ๋๋ฆฌ๋ ๋ฐฉ๋ฒ์** ์๋ค์๊ฒ ๊ฐ๋ฅด์ณ ์ค ๊ฑธ์ธ. | ||
|
||
์ด ๋ ์จ์์ ๋ช ๊ฐ์ง ๊ณ ๊ธ ์๋ฆฌ๋ํฐ ๊ฐ๋ ์ ๋ํด ๋ค๋ฃฐ ๊ฒ์ด๋, ์์ํ๊ธฐ ์ ์ ๋ ์จ 1์ ์๋ฃํ๋ ๊ฑธ ๊ฐ๋ ฅ ์ถ์ฒํ๋ค. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: ๋ ์จ 2 ๊ฐ์ | ||
actions: ['์ ๋ต ํ์ธํ๊ธฐ', 'ํํธ ๋ณด๊ธฐ'] | ||
material: | ||
saveZombie: false | ||
zombieBattle: | ||
zombie: | ||
lesson: 1 | ||
humanBattle: true | ||
ignoreZombieCache: true | ||
answer: 1 | ||
--- | ||
|
||
์ง๋ ๋ ์จ์์ ์ข๋น์ ์ด๋ฆ์ ๋ฐ์์ ๋๋ค์ผ๋ก ์ข๋น๋ฅผ ์์ฑํ ๋ค์, ์ด ์ข๋น๋ฅผ ๋ธ๋ก์ฒด์ธ ์์ ์ฐ๋ฆฌ ์ฑ ์ข๋น ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ถ๊ฐํ๋ ํจ์๋ฅผ ์์ฑํ์ง. | ||
|
||
์ด๋ฒ ๋ ์จ์์๋ ์ฐ๋ฆฌ ์ฑ์ ์ข ๋ ๊ฒ์๋ต๊ฒ ๋ง๋ค ๊ฑธ์ธ: ์ฑ์ ๋ฉํฐํ๋ ์ด์ด ๊ฒ์์ผ๋ก ๋ง๋ค๊ณ , ์ข๋น๋ฅผ ๋๋ค์ผ๋ก๋ง ์์ฑํ์ง ์๊ณ ์ข๋ ์ฌ๋ฏธ์๋ ๋ฐฉ์์ผ๋ก ์ข๋น๋ฅผ ์์ฑํ ๊ฒ์ด๋ค. | ||
|
||
์ด๋ป๊ฒ ์๋ก์ด ์ข๋น๋ฅผ ์์ฑํ ๊น? ์ข๋น๊ฐ ๋ค๋ฅธ ์๋ช ์ฒด๋ฅผ "๋จน๋๋ก" ํด์! | ||
|
||
## ์ข๋น ๋จน์ด๊ธฐ | ||
|
||
์ข๋น๊ฐ ๋จน์ด๋ฅผ ๋จน์ ๋ ๋จน์ด๋ ๋ฐ์ด๋ฌ์ค์ ๊ฐ์ผ๋๊ฒ ๋์ง. ์ด ๋ฐ์ด๋ฌ์ค๋ ๋จน์ด๋ฅผ ์๋ก์ด ์ข๋น๋ก ๋ฐ๊พธ์ด ์ข๋น ๊ตฐ๋์ ์ผ์์ด ๋๋๋ก ํ์ง. ์๋ก์ด ์ข๋น์ DNA๋ ์ด์ ์ข๋น์ DNA์ ๋จน์ด์ DNA๋ฅผ ํ์ฉํ์ฌ ๊ณ์ฐ๋ ๊ฒ์ด๋ค. | ||
|
||
๊ทธ๋ผ ์ฐ๋ฆฌ ์ข๋น๋ค์ด ๊ฐ์ฅ ์ข์ํ๋ ๋จน์ด๊ฐ ๋ฌด์์ผ๊น? | ||
|
||
๊ทธ๊ฑธ ์๊ณ ์ถ์ผ๋ฉด... ๋ ์จ 2๋ฅผ ๋ง์ณ์ผ ํ ๊ฒ์ด๋ค! | ||
|
||
# ์ง์ ํด๋ณด๊ธฐ | ||
|
||
์ค๋ฅธ์ชฝ์ ๋ณด๋ฉด ์ข๋น๊ฐ ๋จน์ด๋ฅผ ๋จน๋ ๊ฐ๋จํ ๋ฐ๋ชจ๊ฐ ์์ง. ์ธ๊ฐ์ ํด๋ฆญํด์ ์ข๋น๊ฐ ๋จน์ด๋ฅผ ๋จน์ ๋ ์ด๋ค ์ผ์ด ์ผ์ด๋๋์ง ๋ณด๊ฒ! | ||
|
||
์๋ก์ด ์ข๋น์ DNA๊ฐ ์๋ ์ข๋น์ DNA์ ๋จน์ด์ DNA์ ์ํด ๊ฒฐ์ ๋๋ค๋ ๊ฒ์ ์ ์ ์์ง. | ||
|
||
์ค๋น๊ฐ ๋๋ฉด, "๋ค์ ์ฑํฐ"๋ฅผ ํด๋ฆญํด์ ๊ณ์ ์งํํ๊ฒ. ์ฐ๋ฆฌ ๊ฒ์์ ๋ฉํฐ ํ๋ ์ด์ด ๊ฒ์์ผ๋ก ๋ง๋๋ ๊ฒ๋ถํฐ ์์ํ๋๋ก ํ์ง. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
--- | ||
title: ์ข๋น๊ฐ ๋ฌด์์ ๋จน๋์? | ||
actions: ['์ ๋ต ํ์ธํ๊ธฐ', 'ํํธ ๋ณด๊ธฐ'] | ||
material: | ||
editor: | ||
language: sol | ||
startingCode: | ||
"zombiefeeding.sol": | | ||
pragma solidity ^0.4.19; | ||
import "./zombiefactory.sol"; | ||
// ์ฌ๊ธฐ์ KittyInterface๋ฅผ ์์ฑํ๋ค | ||
contract ZombieFeeding is ZombieFactory { | ||
function feedAndMultiply(uint _zombieId, uint _targetDna) public { | ||
require(msg.sender == zombieToOwner[_zombieId]); | ||
Zombie storage myZombie = zombies[_zombieId]; | ||
_targetDna = _targetDna % dnaModulus; | ||
uint newDna = (myZombie.dna + _targetDna) / 2; | ||
_createZombie("NoName", newDna); | ||
} | ||
} | ||
"zombiefactory.sol": | | ||
pragma solidity ^0.4.19; | ||
contract ZombieFactory { | ||
event NewZombie(uint zombieId, string name, uint dna); | ||
uint dnaDigits = 16; | ||
uint dnaModulus = 10 ** dnaDigits; | ||
struct Zombie { | ||
string name; | ||
uint dna; | ||
} | ||
Zombie[] public zombies; | ||
mapping (uint => address) public zombieToOwner; | ||
mapping (address => uint) ownerZombieCount; | ||
function _createZombie(string _name, uint _dna) internal { | ||
uint id = zombies.push(Zombie(_name, _dna)) - 1; | ||
zombieToOwner[id] = msg.sender; | ||
ownerZombieCount[msg.sender]++; | ||
NewZombie(id, _name, _dna); | ||
} | ||
function _generateRandomDna(string _str) private view returns (uint) { | ||
uint rand = uint(keccak256(_str)); | ||
return rand % dnaModulus; | ||
} | ||
function createRandomZombie(string _name) public { | ||
require(ownerZombieCount[msg.sender] == 0); | ||
uint randDna = _generateRandomDna(_name); | ||
_createZombie(_name, randDna); | ||
} | ||
} | ||
answer: > | ||
pragma solidity ^0.4.19; | ||
import "./zombiefactory.sol"; | ||
contract KittyInterface { | ||
function getKitty(uint256 _id) external view returns ( | ||
bool isGestating, | ||
bool isReady, | ||
uint256 cooldownIndex, | ||
uint256 nextActionAt, | ||
uint256 siringWithId, | ||
uint256 birthTime, | ||
uint256 matronId, | ||
uint256 sireId, | ||
uint256 generation, | ||
uint256 genes | ||
); | ||
} | ||
contract ZombieFeeding is ZombieFactory { | ||
function feedAndMultiply(uint _zombieId, uint _targetDna) public { | ||
require(msg.sender == zombieToOwner[_zombieId]); | ||
Zombie storage myZombie = zombies[_zombieId]; | ||
_targetDna = _targetDna % dnaModulus; | ||
uint newDna = (myZombie.dna + _targetDna) / 2; | ||
_createZombie("NoName", newDna); | ||
} | ||
} | ||
--- | ||
|
||
์ด์ ์ข๋น๋ค์๊ฒ ๋จน์ด๋ฅผ ์ค ์๊ฐ์ด๊ตฐ! ์ข๋น๊ฐ ๊ฐ์ฅ ์ข์ํ๋ ๋จน์ด๊ฐ ๋ญ๊น? | ||
|
||
ํฌ๋ฆฝํ ์ข๋น๊ฐ ๊ฐ์ฅ ์ข์ํ๋ ๋จน์ด๋... | ||
|
||
**ํฌ๋ฆฝํ ํคํฐ!** ๐ฑ๐ฑ๐ฑ | ||
|
||
(๊ทธ๋, ์ ๋ง์ด๋ผ๋ค ๐ ) | ||
|
||
์ข๋น์๊ฒ ํฌ๋ฆฝํ ํคํฐ๋ฅผ ๋จน์ด๋ก ์ฃผ๋ ค๋ฉด ํฌ๋ฆฝํ ํคํฐ ์ค๋งํธ ์ปจํธ๋ ํธ์์ ํคํฐ DNA๋ฅผ ์ฝ์ด์์ผ ํ ๊ฒ์ด๋ค. ์ด๊ฒ ๊ฐ๋ฅํ ์ด์ ๋ ํฌ๋ฆฝํ ํคํฐ ๋ฐ์ดํฐ๊ฐ ๋ธ๋ก์ฒด์ธ ์์ ๊ณต๊ฐ์ ์ผ๋ก ์ ์ฅ๋์ด ์๊ธฐ ๋๋ฌธ์ด์ง. ๋ธ๋ก์ฒด์ธ์ด ํ์์ ์ด์ง ์๋?! | ||
|
||
๊ฑฑ์ ๋ง๊ฒ - ์ฐ๋ฆฌ ๊ฒ์์ด ์ด๋ ๋๊ตฌ์ ํฌ๋ฆฝํ ํคํฐ์๊ฒ๋ ์ค์ ํด๋ฅผ ๋ผ์น์ง ์์ ๊ฒ์ด๋ ๋ง์ผ์ธ. ์ฐ๋ฆฐ ๋จ์ง ํฌ๋ฆฝํ ํคํฐ ๋ฐ์ดํฐ๋ฅผ *์ฝ์ด ์ฌ* ๋ฟ์ด์ง. ์ค์ ๋ก ์ด ๋ฐ์ดํฐ๋ฅผ ์ง์ธ ์๋ ์๋ค๋ค. ๐ | ||
|
||
## ๋ค๋ฅธ ์ปจํธ๋ ํธ์ ์ํธ์์ฉํ๊ธฐ | ||
|
||
๋ธ๋ก์ฒด์ธ ์์ ์์ผ๋ฉด์ ์ฐ๋ฆฌ๊ฐ ์์ ํ์ง ์์ ์ปจํธ๋ ํธ์ ์ฐ๋ฆฌ ์ปจํธ๋ ํธ๊ฐ ์ํธ์์ฉ์ ํ๋ ค๋ฉด ์ฐ์ **_์ธํฐํ์ด์ค_**๋ฅผ ์ ์ํด์ผ ํ๋ค. | ||
|
||
๊ฐ๋จํ ์์๋ฅผ ์ดํด ๋ณด๋๋ก ํ์ง. ๋ค์๊ณผ ๊ฐ์ ๋ธ๋ก์ฒด์ธ ์ปจํธ๋ ํธ๊ฐ ์๋ค๊ณ ํด ๋ณด์ธ: | ||
|
||
``` | ||
contract LuckyNumber { | ||
mapping(address => uint) numbers; | ||
function setNum(uint _num) public { | ||
numbers[msg.sender] = _num; | ||
} | ||
function getNum(address _myAddress) public view returns (uint) { | ||
return numbers[_myAddress]; | ||
} | ||
} | ||
``` | ||
|
||
์ด ์ปจํธ๋ ํธ๋ ์๋ฌด๋ ์์ ์ ํ์ด์ ์๋ฅผ ์ ์ฅํ ์ ์๋ ๊ฐ๋จํ ์ปจํธ๋ ํธ์ด๊ณ , ๊ฐ์์ ์ด๋๋ฆฌ์ ์ฃผ์์ ์ฐ๊ด์ด ์์ ๊ฒ์ด๋ค. ์ด ์ฃผ์๋ฅผ ์ด์ฉํด์ ๋๊ตฌ๋ ๊ทธ ์ฌ๋์ ํ์ด์ ์๋ฅผ ์ฐพ์ ๋ณผ ์ ์์ง. | ||
|
||
์ด์ `getNum` ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ด ์ปจํธ๋ ํธ์ ์๋ ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ ์ ํ๋ external ํจ์๊ฐ ์๋ค๊ณ ํด ๋ณด์ธ. | ||
|
||
๋จผ์ , `LuckyNumber` ์ปจํธ๋ ํธ์ **_์ธํฐํ์ด์ค_**๋ฅผ ์ ์ํ ํ์๊ฐ ์๋ค: | ||
|
||
``` | ||
contract NumberInterface { | ||
function getNum(address _myAddress) public view returns (uint); | ||
} | ||
``` | ||
|
||
์ฝ๊ฐ ๋ค๋ฅด์ง๋ง, ์ธํฐํ์ด์ค๋ฅผ ์ ์ํ๋ ๊ฒ์ด ์ปจํธ๋ ํธ๋ฅผ ์ ์ํ๋ ๊ฒ๊ณผ ์ ์ฌํ๋ค๋ ๊ฑธ ์ฐธ๊ณ ํ๊ฒ. ๋จผ์ , ๋ค๋ฅธ ์ปจํธ๋ ํธ์ ์ํธ์์ฉํ๊ณ ์ ํ๋ ํจ์๋ง์ ์ ์ธํ ๋ฟ(์ด ๊ฒฝ์ฐ, `getNum`์ด ๋ฐ๋ก ๊ทธ๋ฌํ ํจ์์ด์ง) ๋ค๋ฅธ ํจ์๋ ์ํ ๋ณ์๋ฅผ ์ธ๊ธํ์ง ์๋ค. . | ||
|
||
๋ค์์ผ๋ก, ํจ์ ๋ชธ์ฒด๋ฅผ ์ ์ํ์ง ์์ง. ์ค๊ดํธ `{`, `}`๋ฅผ ์ฐ์ง ์๊ณ ํจ์ ์ ์ธ์ ์ธ๋ฏธ์ฝ๋ก (`;`)์ผ๋ก ๊ฐ๋จํ๊ฒ ๋๋ด์ง. | ||
|
||
๊ทธ๋ฌ๋ ์ธํฐํ์ด์ค๋ ์ปจํธ๋ ํธ ๋ผ๋์ฒ๋ผ ๋ณด์ธ๋ค๊ณ ํ ์ ์์ง. ์ปดํ์ผ๋ฌ๋ ๊ทธ๋ ๊ฒ ์ธํฐํ์ด์ค๋ฅผ ์ธ์ํ์ง. | ||
|
||
์ฐ๋ฆฌ์ ๋ ์ฝ๋์ ์ด๋ฐ ์ธํฐํ์ด์ค๋ฅผ ํฌํจํ๋ฉด ์ปจํธ๋ ํธ๋ ๋ค๋ฅธ ์ปจํธ๋ ํธ์ ์ ์๋ ํจ์์ ํน์ฑ, ํธ์ถ ๋ฐฉ๋ฒ, ์์๋๋ ์๋ต ๋ด์ฉ์ ๋ํด ์ ์ ์๊ฒ ๋์ง. | ||
|
||
๋ค์ ๋ ์จ์์ ๋ค๋ฅธ ์ปจํธ๋ ํธ์ ํจ์๋ฅผ ์ค์ ๋ก ํธ์ถํ ๊ฒ์ผ์ธ. ์ง๊ธ์ ํฌ๋ฆฝํ ํคํฐ ์ปจํธ๋ ํธ๋ฅผ ์ํ ์ธํฐํ์ด์ค๋ฅผ ์ ์ธํด ๋ณด์ธ. | ||
|
||
# ์ง์ ํด๋ณด๊ธฐ | ||
|
||
์๋ค๋ฅผ ์ํด ํฌ๋ฆฝํ ํคํฐ ์์ค ์ฝ๋๋ฅผ ์ฐพ์ ๋ดค๋ค. ๊ฑฐ๊ธฐ์, (์ฐ๋ฆฌ ์ข๋น ๊ฒ์์์ ์๋ก์ด ์ข๋น๋ฅผ ์์ฑํ๋ ๋ฐ ํ์ํ!) "์ ์ ์"๋ฅผ ํฌํจํ ๋ชจ๋ ํคํฐ ๋ฐ์ดํฐ๋ฅผ ๋ฐํํ๋ `getKitty`๋ผ๋ ํจ์๋ฅผ ๋ฐ๊ฒฌํ๋ค. | ||
|
||
`getKitty` ํจ์๋ ๋ค์๊ณผ ๊ฐ๋ค: | ||
|
||
``` | ||
function getKitty(uint256 _id) external view returns ( | ||
bool isGestating, | ||
bool isReady, | ||
uint256 cooldownIndex, | ||
uint256 nextActionAt, | ||
uint256 siringWithId, | ||
uint256 birthTime, | ||
uint256 matronId, | ||
uint256 sireId, | ||
uint256 generation, | ||
uint256 genes | ||
) { | ||
Kitty storage kit = kitties[_id]; | ||
// if this variable is 0 then it's not gestating | ||
isGestating = (kit.siringWithId != 0); | ||
isReady = (kit.cooldownEndBlock <= block.number); | ||
cooldownIndex = uint256(kit.cooldownIndex); | ||
nextActionAt = uint256(kit.cooldownEndBlock); | ||
siringWithId = uint256(kit.siringWithId); | ||
birthTime = uint256(kit.birthTime); | ||
matronId = uint256(kit.matronId); | ||
sireId = uint256(kit.sireId); | ||
generation = uint256(kit.generation); | ||
genes = kit.genes; | ||
} | ||
``` | ||
|
||
์ด ํจ์๋ ์ฐ๋ฆฌ์๊ฒ ์ต์ํ ํจ์๋ค๊ณผ๋ ๋ฌ๋ผ ๋ณด์ด์ง. ํจ์๊ฐ ๋ค์ํ ๊ฐ๋ค์ ๋ฐํํ๊ณ ์์ง... ์๋ค๊ฐ ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ฅผ ์ด์ฉํด ๋ณธ ์ ์ด ์๋ค๋ฉด ์ด ์ ์ด ๋ค๋ฅด๋ค๋ ๊ฑธ ์ ์ ์์ ๊ฑฐ๋ค. ์๋ฆฌ๋ํฐ์์๋ ํจ์๊ฐ ํ๋ ์ด์์ ๊ฐ์ ๋ฐํํ ์ ์์ง. | ||
|
||
`getKitty` ํจ์๊ฐ ์ด๋ค ํจ์์ธ์ง ์์ ๋ณด์์ผ๋, ์ด๋ฅผ ์ด์ฉํ์ฌ ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค์ด ๋ณผ ์ ์์ ๊ฑธ์ธ: | ||
|
||
1. `KittyInterface`๋ผ๋ ์ธํฐํ์ด์ค๋ฅผ ์ ์ํ๋ค. ์ธํฐํ์ด์ค ์ ์๊ฐ `contract` ํค์๋๋ฅผ ์ด์ฉํ์ฌ ์๋ก์ด ์ปจํธ๋ ํธ๋ฅผ ์์ฑํ๋ ๊ฒ๊ณผ ๊ฐ๋ค๋ ์ ์ ๊ธฐ์ตํ ๊ฒ. | ||
|
||
2. ์ธํฐํ์ด์ค ๋ด์ `getKitty` ํจ์๋ฅผ ์ ์ธํ๋ค (์์ ํจ์์์ ์ค๊ดํธ ์์ ๋ชจ๋ ๋ด์ฉ์ ์ ์ธํ๊ณ `return` ํค์๋ ๋ฐ ๋ฐํ ๊ฐ ์ข ๋ฅ๊น์ง๋ง ๋ณต์ฌ/๋ถ์ฌ๋ฃ๊ธฐ ํ๊ณ ๊ทธ ๋ค์์ ์ธ๋ฏธ์ฝ๋ก ์ ๋ฃ์ด์ผ ํ๋ค). |
Oops, something went wrong.