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

イーサリアム実習 II / Practicing Ethereum II

Kenji Saito
November 08, 2017

イーサリアム実習 II / Practicing Ethereum II

2017年11月8日(水)、ブロックチェーンアカデミー「スマートコントラクトプログラミング講座(4)」にて使用のスライドです。

Kenji Saito

November 08, 2017
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. 1. : 2. : 3. / II – (4) –

    2017-05-31 – p.3/54
  2. IndivisibleAsset string public _name; string public _symbol; uint256 public _quantity;

    address public _owner; _name ( ) _symbol _quantity (m2 ) _owner _ Solidity . . . II – (4) – 2017-05-31 – p.6/54
  3. IndivisibleAsset function IndivisibleAsset(string name, string symbol, uint256 quantity) { _name

    = name; _symbol = symbol; _quantity = quantity; _owner = msg.sender; } II – (4) – 2017-05-31 – p.8/54
  4. IndivisibleAsset transfer() function transfer(address to) { if (_owner != msg.sender)

    { throw; } _owner = to; Transfer(msg.sender, to); } ( / ) $ populus compile II – (4) – 2017-05-31 – p.10/54
  5. (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 – (4) – 2017-05-31 – p.11/54
  6. (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 – (4) – 2017-05-31 – p.12/54
  7. 1. ( ) 2. ( ) 3. ( ) II

    – (4) – 2017-05-31 – p.16/54
  8. OneTimeEscrow settle() function settle() { address addr = this; /*

    this */ if (_token.getBalanceOf(this) < _price || _asset.getOwner() != addr) { throw; } _token.transfer(_seller , _price); _asset.transfer(_buyer); Settled(); /* */ } settle() transfer ( / ) $ populus compile II – (4) – 2017-05-31 – p.17/54
  9. (1) import pytest @pytest.fixture() def token_contract(chain): . . . @pytest.fixture()

    def asset_contract(chain): . . . II – (4) – 2017-05-31 – p.18/54
  10. (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 – (4) – 2017-05-31 – p.19/54
  11. (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 – (4) – 2017-05-31 – p.20/54
  12. (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().getBalanceOf(account0) == 999700 assert token_contract.call().getBalanceOf(account1) == 0 assert token_contract.call().getBalanceOf(contract_address) == 300 assert asset_contract.call().getOwner() == contract_address account1 300BcH account0 II – (4) – 2017-05-31 – p.21/54
  13. (5) txid = EscrowFactory.transact().settle(); chain.wait.for_receipt(txid) assert token_contract.call().getBalanceOf(account0) == 1000000 assert

    token_contract.call().getBalanceOf(account1) == 0 assert token_contract.call().getBalanceOf(contract_address) == 0 assert asset_contract.call().getOwner() == account1 settle() II – (4) – 2017-05-31 – p.22/54
  14. 3. / Hyperledger (Fabric, Sawtooth, Iroha, Burrow, Indy) R3 Corda

    Enterprise Ethereum Alliance Tangle (IOTA) BBc-1 II – (4) – 2017-05-31 – p.24/54
  15. ( ) ( ) ( ) IoT / / (

    ) II – (4) – 2017-05-31 – p.25/54
  16. ( = ) ( ) ( ) ↑ II –

    (4) – 2017-05-31 – p.26/54
  17. / : Proposal → Incubation → Active → Deprecated →

    End of Life II – (4) – 2017-05-31 – p.28/54
  18. (Docker) (chaincode) PBFT (Practical BFT) RocksDB CA PKI v1.0 DB

    CA BFT : Byzantine Fault Tolerance ( ) CA : Certificate Authority ( ) PKI : Public Key Infrastructure ( ) II – (4) – 2017-05-31 – p.32/54
  19. ( ) (permissioned) (permissionless) Proof of Elapsed Time (PoET) Proof

    of Work ( ) (Intel ) / Transaction Families II – (4) – 2017-05-31 – p.34/54
  20. JVM (chaincode) Sumeragi (BFT) JVM : Java Virtual Machine (Java

    ) II – (4) – 2017-05-31 – p.38/54
  21. R3 R3CEV 77 (2017 2 ) 3 SBI R3Net( )

    Corda II – (4) – 2017-05-31 – p.41/54
  22. ( ) + CAP ( DLT ) II – (4)

    – 2017-05-31 – p.43/54
  23. JVM ( ) (Uniqueness Services) UTXO X.509 PKI ( )

    UTXO : Unspent TX (transaction) Output ( ) X.509 : PKI II – (4) – 2017-05-31 – p.44/54
  24. IoT TX TX (DAG) ( ) TX Tangle II –

    (4) – 2017-05-31 – p.46/54
  25. IoT (IOTA) DAG ( ) DAG II – (4) –

    2017-05-31 – p.47/54
  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 – (4) – 2017-05-31 – p.49/54
  27. ( Python) ( DAG) ( ) UTXO II – (4)

    – 2017-05-31 – p.50/54
  28. ( ) (by ) (since 1984) ( ) ( )

    ( ) . . . ( ) ⇒ . . . II – (4) – 2017-05-31 – p.52/54
  29. ( ) ( ) ( ) ( ) ( )

    ( ) (by ) ⇒ DLT II – (4) – 2017-05-31 – p.53/54