Upgrade to Pro — share decks privately, control downloads, hide ads and more …

スマートコントラクトプログラミング(3) イーサリアム実習 I / Ethereum Exercise I, Smart Contract Programming 3

Kenji Saito
October 21, 2016

スマートコントラクトプログラミング(3) イーサリアム実習 I / Ethereum Exercise I, Smart Contract Programming 3

ブロックチェーンハブ主催で開催しているブロックチェーン連続講義シリーズ「スマートコントラクトプログラミング」の第3回「イーサリアム実習 I」のスライドです。2016年10月21日(金) に使用しました。

Kenji Saito

October 21, 2016
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. ( ) $ geth --networkid 12345678 --port 50303 --maxpeers 0

    --nodiscover console 2>> node.log > > exit $ tail -f node.log (Mac OS X, Linux) > Get-Content node.log -Wait -Tail 10 (Windows PowerShell) I — (3) – 2016-10-21 – p.5/39
  2. ( ) geth > miner.start(2) true ‘2’ ( CPU )

    > miner.stop() I — (3) – 2016-10-21 – p.6/39
  3. Solidity JavaScript ( , ) (constructor) ( ) ( )

    Ether I — (3) – 2016-10-21 – p.10/39
  4. pragma solidity ˆ0.4.2; contract MyToken { ( ) : (EVM

    ) : function MyToken(...) { /* */ : } : } function C (/* */ // ) I — (3) – 2016-10-21 – p.11/39
  5. MyToken string public name; string public symbol; uint8 public decimals;

    mapping (address => uint256) public balanceOf; name, symbol decimals : 2 100 1.00 mapping balanceOf I — (3) – 2016-10-21 – p.12/39
  6. MyToken event Transfer(address indexed from, address indexed to, uint256 value);

    indexed (3 ) MyToken function Transfer() Ethereum-Wallet I — (3) – 2016-10-21 – p.13/39
  7. MyToken function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals)

    { if (_supply == 0) { _supply = 1000000; /* _supply 1,000,000 */ } balanceOf[msg.sender] = _supply; name = _name; symbol = _symbol; decimals = _decimals; } msg.sender _supply C++ _ I — (3) – 2016-10-21 – p.14/39
  8. MyToken transfer() function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender]

    < _value) { /* */ throw; } if (balanceOf[_to] + _value < balanceOf[_to]) { /* */ throw; } balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; Transfer(msg.sender, _to, _value); } throw (function ) catch I — (3) – 2016-10-21 – p.15/39
  9. Ether (1) Account 2 BcH Ether 1 Ether Account 2

    BcH I — (3) – 2016-10-21 – p.20/39
  10. A, B A-B m A B A B A B

    . . . I — (3) – 2016-10-21 – p.22/39
  11. 1. X 2. X C 3. C 1. 2. 3.

    reliable multicast I — (3) – 2016-10-21 – p.23/39
  12. (safety) (liveness) ( ) ( = ) I — (3)

    – 2016-10-21 – p.25/39
  13. CAP Consistency ( ) Availability ( ) Partition tolerance (

    ) ⇒ 3 C Eventual consistency ( ) . . . I — (3) – 2016-10-21 – p.28/39
  14. Consistency ( ) Strong consistency ( ) (safety) Eventual consistency

    ( ) (liveness) ↑ Weak consistency ( ) ← ( ) I — (3) – 2016-10-21 – p.29/39
  15. 1 1, 2 n ≤ 3f I — (3) –

    2016-10-21 – p.31/39
  16. CS1 : CS2 : CS3 : CL1 : CL2 :

    : : (e.g. ) I — (3) – 2016-10-21 – p.32/39
  17. (B)FT-CUP (Consensus with Unknown Participants) ( / ) : FT

    (Fault-Tolerant) : BFT (Byzantine Fault-Tolerant) P2P n FT/BFT I — (3) – 2016-10-21 – p.33/39
  18. again n > 3f R F R > 2F ⇒

    I — (3) – 2016-10-21 – p.36/39
  19. ( ) f = 1 ⇒ R I — (3)

    – 2016-10-21 – p.37/39
  20. ( ) 3 1. ( ) ⇒ 2. ( )

    ⇒ 3. ( ) TX ⇒ I — (3) – 2016-10-21 – p.38/39