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

イーサリアム実習 II / Ethereum Practice 2

イーサリアム実習 II / Ethereum Practice 2

2018年7月25日(水)、ブロックチェーンハブ主催で開催されたブロックチェーンアカデミー「イーサリアム実習 II」(【ハンズオン】スマートコントラクトプログラミング (3)) にて使用したスライドです。

Kenji Saito

July 25, 2018
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. II
    (3)
    CSO / SFC
    ( https://speakerdeck.com/ks91 )
    [email protected]
    II — (3) — 2018-07-25 – p.1/55

    View full-size slide

  2. 1. : ERC20
    2. ∼ ∼
    II — (3) — 2018-07-25 – p.2/55

    View full-size slide

  3. 1. :
    2. :
    3. /
    II — (3) — 2018-07-25 – p.3/55

    View full-size slide

  4. 1.
    II — (3) — 2018-07-25 – p.4/55

    View full-size slide

  5. (m2 )
    1 1
    II — (3) — 2018-07-25 – p.5/55

    View full-size slide

  6. IndivisibleAsset
    string public _name;
    string public _symbol;
    uint256 public _quantity;
    address public _owner;
    _name ( )
    _symbol _quantity (m2 )
    _owner
    _
    Solidity . . .
    II — (3) — 2018-07-25 – p.6/55

    View full-size slide

  7. IndivisibleAsset
    event Transfer(address indexed from, address indexed to);
    from to
    II — (3) — 2018-07-25 – p.7/55

    View full-size slide

  8. IndivisibleAsset
    constructor (string name, string symbol, uint256 quantity) public {
    _name = name;
    _symbol = symbol;
    _quantity = quantity;
    _owner = msg.sender;
    }
    II — (3) — 2018-07-25 – p.8/55

    View full-size slide

  9. IndivisibleAsset getOwner()
    function getOwner() external view returns (address) {
    return (_owner);
    }
    II — (3) — 2018-07-25 – p.9/55

    View full-size slide

  10. IndivisibleAsset transfer()
    function transfer(address to) external returns (bool) {
    require(_owner == msg.sender);
    _owner = to;
    Transfer(msg.sender, to);
    return true;
    }
    ( / )
    $ populus compile
    II — (3) — 2018-07-25 – p.10/55

    View full-size slide

  11. (1)
    import pytest
    @pytest.fixture()
    def asset_contract(chain):
    AssetFactory = chain.provider.get_contract_factory(’IndivisibleAsset’)
    deploy_txid = AssetFactory.deploy(args=[
    "5322 Endo, Fujisawa",
    "mˆ2",
    300,
    ])
    contract_address = chain.wait.for_contract_address(deploy_txid)
    return AssetFactory(address=contract_address)
    SFC (300m2 )
    II — (3) — 2018-07-25 – p.11/55

    View full-size slide

  12. (2)
    def test_indivisible_assset(asset_contract, chain):
    account0 = chain.web3.eth.accounts[0]
    account1 = chain.web3.eth.accounts[1]
    assert asset_contract.call().getOwner() == account0
    txid = asset_contract.transact().transfer(account1)
    chain.wait.for_receipt(txid)
    assert asset_contract.call().getOwner() == account1
    account0 account1
    II — (3) — 2018-07-25 – p.12/55

    View full-size slide

  13. $ py.test -k test_indivisible_asset.py
    II — (3) — 2018-07-25 – p.13/55

    View full-size slide

  14. 2.
    II — (3) — 2018-07-25 – p.14/55

    View full-size slide

  15. transfer
    settle, retrieve asset, retrieve token 3
    II — (3) — 2018-07-25 – p.15/55

    View full-size slide

  16. 1. ( )
    2. ( )
    3. ( )
    II — (3) — 2018-07-25 – p.16/55

    View full-size slide

  17. OneTimeEscrow settle()
    function settle() public returns (bool) {
    require(_token.balanceOf(this) >= _price); /* this */
    require(_asset.getOwner() == address(this));
    _token.transfer(_seller , _price);
    _asset.transfer(_buyer);
    Settled(); /* */
    return true;
    }
    settle()
    transfer
    ( / )
    $ populus compile
    solidity 0.4.21
    II — (3) — 2018-07-25 – p.17/55

    View full-size slide

  18. (1)
    import pytest
    @pytest.fixture()
    def token_contract(chain):
    .
    .
    .
    @pytest.fixture()
    def asset_contract(chain):
    .
    .
    .
    II — (3) — 2018-07-25 – p.18/55

    View full-size slide

  19. (2)
    def test_one_time_escrow(token_contract, asset_contract, chain):
    account0 = chain.web3.eth.accounts[0]
    account1 = chain.web3.eth.accounts[1]
    txid = chain.web3.eth.sendTransaction({
    ’from’: account0,
    ’to’: account1,
    ’value’: chain.web3.toWei(1, "ether")
    })
    chain.wait.for_receipt(txid)
    txid = token_contract.transact().transfer(account1, 300)
    chain.wait.for_receipt(txid)
    account0 account1 1Ether
    300BcH
    300BcH TX
    II — (3) — 2018-07-25 – p.19/55

    View full-size slide

  20. (3)
    EscrowFactory = chain.provider.get_contract_factory(’OneTimeEscrow’)
    txid = EscrowFactory.deploy(args=[
    token_contract.address,
    account1,
    asset_contract.address,
    account0,
    300,
    ])
    contract_address = chain.wait.for_contract_address(txid)
    EscrowFactory.address = contract_address;
    account1 account0 300BcH
    II — (3) — 2018-07-25 – p.20/55

    View full-size slide

  21. (4)
    txid = token_contract.transact({
    ’from’: account1
    }).transfer(contract_address, 300)
    chain.wait.for_receipt(txid)
    txid = asset_contract.transact().transfer(contract_address)
    chain.wait.for_receipt(txid)
    assert token_contract.call().balanceOf(account0) == 999700
    assert token_contract.call().balanceOf(account1) == 0
    assert token_contract.call().balanceOf(contract_address) == 300
    assert asset_contract.call().getOwner() == contract_address
    account1 300BcH
    account0
    II — (3) — 2018-07-25 – p.21/55

    View full-size slide

  22. (5)
    txid = EscrowFactory.transact().settle();
    chain.wait.for_receipt(txid)
    assert token_contract.call().balanceOf(account0) == 1000000
    assert token_contract.call().balanceOf(account1) == 0
    assert token_contract.call().balanceOf(contract_address) == 0
    assert asset_contract.call().getOwner() == account1
    settle()
    II — (3) — 2018-07-25 – p.22/55

    View full-size slide

  23. $ py.test -k test_one_time_escrow.py
    :
    settle()
    II — (3) — 2018-07-25 – p.23/55

    View full-size slide

  24. 3. /
    II — (3) — 2018-07-25 – p.24/55

    View full-size slide

  25. /DLT
    ਖ਼౰ੑͷอূ
    ྫ6590ߏ଄ͱσδλϧॺ໊
    ଘࡏੑͷূ໌
    ྫ࡞ۀূ໌෇͖ϋογϡνΣʔϯ
    །Ұੑͷ߹ҙ
    ྫφΧϞτɾίϯηϯαε
    ϧʔϧͷهड़
    ྫ#5$ͷҠస
    ɾ
    τϥϯβΫγϣϯͷ಺༰͕վ͟ΜͰ͖ͣɺ
    ɾ
    ͦͷΞηοτʹؔ͢ΔաڈͷτϥϯβΫγϣϯྻʹরΒͯ͠ໃ६͕ͳ͘ɺ
    ɾ
    ͔ͭɺਖ਼౰ͳϢʔβʹΑΓ౤ೖ͞Ε͍ͯΔ͜ͱΛอূ͢Δ
    ɾաڈʹ͋ͬͨτϥϯβΫγϣϯͷূڌΛຣফͰ͖ͣɺ
    ɾ
    ͔ͭɺաڈʹͳ͔ͬͨτϥϯβΫγϣϯͷূڌΛ፻଄Ͱ͖ͳ͍
    ɾໃ६͢Δ;ͨͭͷτϥϯβΫγϣϯ͕౤ೖ͞Εͨ৔߹ɺ
    ɹ ͍ͣΕ
    ؔ༩͢Δશһ͕ಉ͡ยํΛબΜͰྺ࢙ͷதʹҐஔ͚ͮΔ
    ɾΞϓϦέʔγϣϯϩδοΫ Կ͕ਖ਼͍͠τϥϯβΫγϣϯ͔ΛܾΊΔ

    II — (3) — 2018-07-25 – p.25/55

    View full-size slide

  26. (Linux Foundation)
    https://www.hyperledger.org
    Apache License, Version 2.0
    II — (3) — 2018-07-25 – p.26/55

    View full-size slide

  27. /
    :
    Proposal → Incubation → Active → Deprecated → End of Life
    II — (3) — 2018-07-25 – p.27/55

    View full-size slide

  28. ( https://www.hyperledger.org/about/members )
    II — (3) — 2018-07-25 – p.28/55

    View full-size slide

  29. Fabric (IBM)
    IBM Digital Asset Holdings
    http://hyperledger-fabric.readthedocs.io/en/latest/
    State : Active
    II — (3) — 2018-07-25 – p.29/55

    View full-size slide

  30. ( )
    ( )
    II — (3) — 2018-07-25 – p.30/55

    View full-size slide

  31. Fabric –
    (Docker) (chaincode)
    PBFT (Practical BFT) ( )
    RocksDB CA PKI
    v1.0 DB CA
    BFT : Byzantine Fault Tolerance ( )
    CA : Certificate Authority ( )
    PKI : Public Key Infrastructure ( )
    II — (3) — 2018-07-25 – p.31/55

    View full-size slide

  32. Sawtooth (Intel)
    https://github.com/hyperledger/sawtooth-core
    State : Active
    II — (3) — 2018-07-25 – p.32/55

    View full-size slide

  33. ( )
    (permissioned) (permissionless)
    Proof of Elapsed Time (PoET)
    Proof of Work ( )
    (Intel )
    /
    Transaction Families
    II — (3) — 2018-07-25 – p.33/55

    View full-size slide

  34. Sawtooth –
    (transaction families)
    (PoET )
    PoET ( )
    (transaction families)
    II — (3) — 2018-07-25 – p.34/55

    View full-size slide

  35. Iroha ( )
    https://github.com/hyperledger/iroha
    State : Active
    II — (3) — 2018-07-25 – p.35/55

    View full-size slide

  36. ( )
    DLT
    :
    C++
    Sumeragi
    Whitepaper : https://github.com/hyperledger/iroha/blob/master/docs/iroha_whitepaper.md
    II — (3) — 2018-07-25 – p.36/55

    View full-size slide

  37. Iroha –
    JVM (chaincode)
    Sumeragi (BFT) → YAC?
    JVM : Java Virtual Machine (Java )
    II — (3) — 2018-07-25 – p.37/55

    View full-size slide

  38. Corda (R3), Tangle (IOTA), BBc-1 ( )
    II — (3) — 2018-07-25 – p.38/55

    View full-size slide

  39. Corda (R3)
    R3
    https://github.com/corda/corda
    II — (3) — 2018-07-25 – p.39/55

    View full-size slide

  40. R3
    R3CEV
    77 (2017 2 )
    3 SBI
    R3Net( )
    Corda
    II — (3) — 2018-07-25 – p.40/55

    View full-size slide

  41. Corda
    Corda :
    :
    II — (3) — 2018-07-25 – p.41/55

    View full-size slide

  42. ( )
    +
    CAP
    ( DLT )
    II — (3) — 2018-07-25 – p.42/55

    View full-size slide

  43. Corda –
    JVM
    ( )
    (Uniqueness Services)
    UTXO X.509 PKI
    ( )
    X.509 : PKI
    II — (3) — 2018-07-25 – p.43/55

    View full-size slide

  44. Tangle (IOTA)
    IoT IOTA
    https://iota.readme.io
    II — (3) — 2018-07-25 – p.44/55

    View full-size slide

  45. IoT
    TX TX (DAG)
    ( DAG )
    TX
    Tangle
    II — (3) — 2018-07-25 – p.45/55

    View full-size slide

  46. Tangle –
    IoT (IOTA)
    DAG ( )
    DAG
    II — (3) — 2018-07-25 – p.46/55

    View full-size slide

  47. BBc-1 (Beyond Blockchain One)
    https://github.com/beyond-blockchain
    https://beyond-blockchain.org
    II — (3) — 2018-07-25 – p.47/55

    View full-size slide

  48. Proof of Work
    Bitcoin ( )
    BBc Trust ( )
    https://beyond-blockchain.org/public/bbc-trust.pdf ( )
    https://beyond-blockchain.org/public/bbc-trust_ja.pdf ( )
    Design Paper (white paper)
    https://beyond-blockchain.org/public/bbc1-design-paper.pdf
    II — (3) — 2018-07-25 – p.48/55

    View full-size slide

  49. BBc-1
    II — (3) — 2018-07-25 – p.49/55

    View full-size slide

  50. BBc-1 –
    ( Python)
    ( DAG)
    ( )
    UTXO
    II — (3) — 2018-07-25 – p.50/55

    View full-size slide

  51. DLT
    II — (3) — 2018-07-25 – p.51/55

    View full-size slide

  52. ( )
    (1)
    (2)
    (3)
    (4) ( )

    II — (3) — 2018-07-25 – p.52/55

    View full-size slide

  53. ( )
    (by ) (since 1984) ( ) ( )
    ( )
    . . .
    ( )
    ⇒ state machine replication
    II — (3) — 2018-07-25 – p.53/55

    View full-size slide

  54. ( )
    ( ) ( ) ( ) ( )
    ( )
    (by )
    II — (3) — 2018-07-25 – p.54/55

    View full-size slide

  55. BBc-1
    1. BBc-1
    2. BBc-1
    3.
    4. Ethereum ( )
    II — (3) — 2018-07-25 – p.55/55

    View full-size slide