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. 1. : ERC20 2. ∼ ∼ II — (3) —

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

    2018-07-25 – p.3/55
  3. 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
  4. 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
  5. 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
  6. (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
  7. (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
  8. 1. ( ) 2. ( ) 3. ( ) II

    — (3) — 2018-07-25 – p.16/55
  9. 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
  10. (1) import pytest @pytest.fixture() def token_contract(chain): . . . @pytest.fixture()

    def asset_contract(chain): . . . II — (3) — 2018-07-25 – p.18/55
  11. (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
  12. (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
  13. (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
  14. (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
  15. /DLT ਖ਼౰ੑͷอূ ྫ6590ߏ଄ͱσδλϧॺ໊ ଘࡏੑͷূ໌ ྫ࡞ۀূ໌෇͖ϋογϡνΣʔϯ །Ұੑͷ߹ҙ ྫφΧϞτɾίϯηϯαε ϧʔϧͷهड़ ྫ#5$ͷҠస ɾ

    τϥϯβΫγϣϯͷ಺༰͕վ͟ΜͰ͖ͣɺ ɾ ͦͷΞηοτʹؔ͢ΔաڈͷτϥϯβΫγϣϯྻʹরΒͯ͠ໃ६͕ͳ͘ɺ ɾ ͔ͭɺਖ਼౰ͳϢʔβʹΑΓ౤ೖ͞Ε͍ͯΔ͜ͱΛอূ͢Δ ɾաڈʹ͋ͬͨτϥϯβΫγϣϯͷূڌΛຣফͰ͖ͣɺ ɾ ͔ͭɺաڈʹͳ͔ͬͨτϥϯβΫγϣϯͷূڌΛ፻଄Ͱ͖ͳ͍ ɾໃ६͢Δ;ͨͭͷτϥϯβΫγϣϯ͕౤ೖ͞Εͨ৔߹ɺ ɹ ͍ͣΕ ؔ༩͢Δશһ͕ಉ͡ยํΛબΜͰྺ࢙ͷதʹҐஔ͚ͮΔ ɾΞϓϦέʔγϣϯϩδοΫ Կ͕ਖ਼͍͠τϥϯβΫγϣϯ͔ΛܾΊΔ II — (3) — 2018-07-25 – p.25/55
  16. / : Proposal → Incubation → Active → Deprecated →

    End of Life II — (3) — 2018-07-25 – p.27/55
  17. 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
  18. ( ) (permissioned) (permissionless) Proof of Elapsed Time (PoET) Proof

    of Work ( ) (Intel ) / Transaction Families II — (3) — 2018-07-25 – p.33/55
  19. Sawtooth – (transaction families) (PoET ) PoET ( ) (transaction

    families) II — (3) — 2018-07-25 – p.34/55
  20. Iroha – JVM (chaincode) Sumeragi (BFT) → YAC? JVM :

    Java Virtual Machine (Java ) II — (3) — 2018-07-25 – p.37/55
  21. R3 R3CEV 77 (2017 2 ) 3 SBI R3Net( )

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

    — 2018-07-25 – p.42/55
  23. Corda – JVM ( ) (Uniqueness Services) UTXO X.509 PKI

    ( ) X.509 : PKI II — (3) — 2018-07-25 – p.43/55
  24. IoT TX TX (DAG) ( DAG ) TX Tangle II

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

    (3) — 2018-07-25 – p.46/55
  26. 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
  27. BBc-1 – ( Python) ( DAG) ( ) UTXO II

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

    — (3) — 2018-07-25 – p.52/55
  29. ( ) (by ) (since 1984) ( ) ( )

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

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

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