Share
Embed
イーサリアム実習 II / Ethereum Practice 2
2018年7月25日(水)、ブロックチェーンハブ主催で開催されたブロックチェーンアカデミー「イーサリアム実習 II」(【ハンズオン】スマートコントラクトプログラミング (3)) にて使用したスライドです。
Kenji Saito PRO
July 25, 2018
Transcript
55 slides
-
II (3) CSO / SFC ( https://speakerdeck.com/ks91 ) [email protected] II
— (3) — 2018-07-25 – p.1/55 -
1. : ERC20 2. ∼ ∼ II — (3) —
2018-07-25 – p.2/55 -
1. : 2. : 3. / II — (3) —
2018-07-25 – p.3/55 -
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 -
IndivisibleAsset event Transfer(address indexed from, address indexed to); from to
II — (3) — 2018-07-25 – p.7/55 -
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 -
IndivisibleAsset getOwner() function getOwner() external view returns (address) { return
(_owner); } II — (3) — 2018-07-25 – p.9/55 -
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 -
(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 -
(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 -
transfer settle, retrieve asset, retrieve token 3 II — (3)
— 2018-07-25 – p.15/55 -
1. ( ) 2. ( ) 3. ( ) II
— (3) — 2018-07-25 – p.16/55 -
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 -
(1) import pytest @pytest.fixture() def token_contract(chain): . . . @pytest.fixture()
def asset_contract(chain): . . . II — (3) — 2018-07-25 – p.18/55 -
(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 -
(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 -
(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 -
(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 -
$ py.test -k test_one_time_escrow.py : settle() II — (3) —
2018-07-25 – p.23/55 -
/DLT ਖ਼ੑͷอূ ྫ6590ߏͱσδλϧॺ໊ ଘࡏੑͷূ໌ ྫ࡞ۀূ໌͖ϋογϡνΣʔϯ །Ұੑͷ߹ҙ ྫφΧϞτɾίϯηϯαε ϧʔϧͷهड़ ྫ#5$ͷҠస ɾ
τϥϯβΫγϣϯͷ༰͕վ͟ΜͰ͖ͣɺ ɾ ͦͷΞηοτʹؔ͢ΔաڈͷτϥϯβΫγϣϯྻʹরΒͯ͠ໃ६͕ͳ͘ɺ ɾ ͔ͭɺਖ਼ͳϢʔβʹΑΓೖ͞Ε͍ͯΔ͜ͱΛอূ͢Δ ɾաڈʹ͋ͬͨτϥϯβΫγϣϯͷূڌΛຣফͰ͖ͣɺ ɾ ͔ͭɺաڈʹͳ͔ͬͨτϥϯβΫγϣϯͷূڌΛ፻Ͱ͖ͳ͍ ɾໃ६͢Δ;ͨͭͷτϥϯβΫγϣϯ͕ೖ͞Εͨ߹ɺ ɹ ͍ͣΕ ؔ༩͢Δશһ͕ಉ͡ยํΛબΜͰྺ࢙ͷதʹҐஔ͚ͮΔ ɾΞϓϦέʔγϣϯϩδοΫ Կ͕ਖ਼͍͠τϥϯβΫγϣϯ͔ΛܾΊΔ II — (3) — 2018-07-25 – p.25/55 -
(Linux Foundation) https://www.hyperledger.org Apache License, Version 2.0 II — (3)
— 2018-07-25 – p.26/55 -
/ : Proposal → Incubation → Active → Deprecated →
End of Life II — (3) — 2018-07-25 – p.27/55 -
Fabric (IBM) IBM Digital Asset Holdings http://hyperledger-fabric.readthedocs.io/en/latest/ State : Active
II — (3) — 2018-07-25 – p.29/55 -
( ) ( ) II — (3) — 2018-07-25 –
p.30/55 -
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 -
( ) (permissioned) (permissionless) Proof of Elapsed Time (PoET) Proof
of Work ( ) (Intel ) / Transaction Families II — (3) — 2018-07-25 – p.33/55 -
Sawtooth – (transaction families) (PoET ) PoET ( ) (transaction
families) II — (3) — 2018-07-25 – p.34/55 -
Iroha ( ) https://github.com/hyperledger/iroha State : Active II — (3)
— 2018-07-25 – p.35/55 -
( ) DLT : C++ Sumeragi Whitepaper : https://github.com/hyperledger/iroha/blob/master/docs/iroha_whitepaper.md II
— (3) — 2018-07-25 – p.36/55 -
Iroha – JVM (chaincode) Sumeragi (BFT) → YAC? JVM :
Java Virtual Machine (Java ) II — (3) — 2018-07-25 – p.37/55 -
Corda (R3), Tangle (IOTA), BBc-1 ( ) II — (3)
— 2018-07-25 – p.38/55 -
R3 R3CEV 77 (2017 2 ) 3 SBI R3Net( )
Corda II — (3) — 2018-07-25 – p.40/55 -
( ) + CAP ( DLT ) II — (3)
— 2018-07-25 – p.42/55 -
Corda – JVM ( ) (Uniqueness Services) UTXO X.509 PKI
( ) X.509 : PKI II — (3) — 2018-07-25 – p.43/55 -
IoT TX TX (DAG) ( DAG ) TX Tangle II
— (3) — 2018-07-25 – p.45/55 -
Tangle – IoT (IOTA) DAG ( ) DAG II —
(3) — 2018-07-25 – p.46/55 -
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 -
BBc-1 – ( Python) ( DAG) ( ) UTXO II
— (3) — 2018-07-25 – p.50/55 -
( ) (1) (2) (3) (4) ( ) ⇒ II
— (3) — 2018-07-25 – p.52/55 -
( ) (by ) (since 1984) ( ) ( )
( ) . . . ( ) ⇒ state machine replication II — (3) — 2018-07-25 – p.53/55 -
( ) ( ) ( ) ( ) ( )
( ) (by ) II — (3) — 2018-07-25 – p.54/55 -
BBc-1 1. BBc-1 2. BBc-1 3. 4. Ethereum ( )
II — (3) — 2018-07-25 – p.55/55