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

BlockchainTokyo23.pdf

822a7ca9bc8e5fb40911b82bcc9f39d5?s=47 biga816
November 29, 2019

 BlockchainTokyo23.pdf

822a7ca9bc8e5fb40911b82bcc9f39d5?s=128

biga816

November 29, 2019
Tweet

Transcript

  1. %BQQTʹ͓͚Δ ΞʔΩςΫνϟͱͭΒΈ BLJIJSP UBOBLB

  2. %BQQ։ൃ4QFDJBMʂ

  3. %BQQ։ൃ4QFDJBMʂ

  4. %BQQ։ൃ4QFDJBMʂ

  5. αϒίϯςϯπ࢝·Γ·͢

  6. ࣗݾ঺հాதতത !CJHB #6*%-ϒϩοΫνΣʔϯΤϯδχΞɻ ৽ଔͰΞΫηϯνϡΞʹೖࣾޙɺ4*΍8&#ϞόΠϧΞϓϦͷ։ ൃϦʔυΛ୲౰ɻ ೥ʹ.U(09Ͱશࣦͯͬͨ͜ͱ͔ΒϒϩοΫνΣʔϯʹ໨ ֮Ίɺ஍ԼΞΠυϧ޲͚%"QQTͳͲΛख͕͚ͨɻ ݱࡏ͸#6*%-ʹͯ4)*&%-ͷ։ൃΛ୲౰͍ͯ͠Δɻ 5ZQF4DSJQU͕޷͖ɻ

  7. ։ൃͨ͠ΞϓϦέʔγϣϯͨͪ

  8. اۀ޲͚ͷίϯαϧɾ։ൃ΋ଟ਺࣮ࢪத

  9. ΞʔΩςΫνϟΛߟ͑Δ 

  10. %"QQTΞʔΩςΫνϟͷλΠϓ ϑϩϯτ׬݁ܕ Ψε୅ߦܕ ΧετσΟܕ Φʔφʔϑϧݖݶܕ

  11. ϑϩϯτ׬݁ܕ .FUB.BTLͳͲͷϒϥ΢β΢ΥϨοτΛ༻͍ͯΫϥΠΞϯτଆ ͔ΒτϥϯβΫγϣϯΛൃߦ͠ɺαʔόʔଆॲཧΛඞཁͱ͠ͳ͍ λΠϓ Front Node Server DB Tx

  12. Ψε୅ߦܕ .FUB.BTLͳͲͷϒϥ΢β΢ΥϨοτΛ༻͍ͯΫϥΠΞϯτଆ Ͱॺ໊͠ɺτϥϯβΫγϣϯͷൃߦΛαʔόʔଆͰ࣮ߦ͢ΔλΠ ϓ Front Node Server DB 署名付 Tx

  13. ΧετσΟܕ Ϣʔβʔͷݤอ؅ɺॺ໊ɺτϥϯβΫγϣϯͷൃߦΛશͯαʔ όʔଆͰ࣮ߦ͢ΔλΠϓ Front Node Server DB Tx

  14. Φʔφʔϑϧݖݶܕ Ϣʔβʔͷݤ͸อ؅ͤͣɺΦʔφݖݶΛ࣋ͬͨΞυϨεΛ༻͍ͯ αʔόʔଆͰτϥϯβΫγϣϯͷൃߦΛ࣮ߦ͢ΔλΠϓ ˞Ϣʔβʔͷ΢ΥϨοτΞυϨεͱΞΧ΢ϯτ৘ใͷඥ෇͚ΛαʔόʔଆͰ͓࣋ͬͯ͘έʔε΋͋Δ Front Node Server DB Tx PXOFS

    VTFS
  15. ͲͷΞʔΩςΫνϟʹ͢Δ΂͖͔ λʔήοτ͕ҰൠϢʔβʔͷ৔߹͸ɺΧετσΟܕPSΦʔφʔϑ ϧݖݶܕʹ͢Δ # ϚωʔδυαʔϏε͕࢖͑ΔέʔεͰ͸ɺ,BMFJEPΛ࢖͏ͷ͕Ұ൪ָ ݤ؅ཧ΍τϥϯβΫγϣϯཤྺ؅ཧ͕ෆཁɺ"1*ͰίϯτϥΫτ͕ίʔϧͰ͖Δ౳ ݤฆࣦ࣌ʹϦΧόϦʔͰ͖Δ%*%ͳͲΛಋೖͰ͖Δ৔߹͸ϑϩϯ τ׬݁ܕΨε୅ߦܕ΋༗ޮ # ͨͩ͠ɺΞʔΩςΫνϟͱͯ͠͸ෳࡶʹͳΔ

  16. ৭ʑͳͭΒΈ

  17. τϥϯβΫγϣϯཤྺͷ؅ཧ લఏ # αʔόʔαΠυͰτϥϯβΫγϣϯΛൃߦ͢Δ # ύϒϦοΫνΣʔϯ ͭΒΈͱରԠ # ϢʔβʔʹτϥϯβΫγϣϯ͕֬ఆͨ͠ͷ͔Ͳ͏͔௨஌͢ΔͨΊʹτ ϥϯβΫγϣϯͷཤྺͱεςʔλεΛ%#ʹอ࣋͢Δඞཁ͕͋ΔͨΊɺ

    ఆظతʹτϥϯβΫγϣϯΛ؂ࢹ͢Δඞཁ͕͋Δɻ # ޮ཰Λߟ͑ͯશτϥϯβΫγϣϯͷεςʔλεΛ؂ࢹ͸ͤͣΠϕϯτ ͷ؂ࢹΛߦ͏͜ͱ͕ଟ͍͕ɺXFCKTͷXFCTPDLFUͷίωΫγϣϯ͸ ͨ·ʹ੾ΕΔ͠ɺର৅Πϕϯτ͕૿͑ΔͱΧΦεʹͳΓ͕ͪɻ
  18. τϥϯβΫγϣϯཤྺͷ؅ཧ export class HogeService { : connect(): void { const

    provider = new Web3.providers.WebsocketProvider(GETH.HOST); const reconnect = () => { const interval = this.isReconnection ? 1000 : 0; setTimeout(() => { this.isReconnection = true; this.connect(); this.observer.next(false); }, interval); }; provider.on("error", () => reconnect()); provider.on("end", () => reconnect()); provider.on("connect", () => { this.isReconnection = false; this.observer.next(true); }); this.web3 = new Web3(provider); } on(): Observable<any> { const observable = new Observable((observer: Subscriber<any>) => { this.observer = observer; return; }); return observable; } : } export class Hoge { : async run(): Promise<void> { this.hogeService.on().subscribe(async (isConnected: boolean) => { if (isConnected) { this.watchEvents(); this.fetchPastBlocks(); } }); this.web3Service.connect(); } : }
  19. %#ͱετϨʔδͷ࿈ܞ લఏ # ύϒϦοΫνΣʔϯϓϥΠϕʔτνΣʔϯ ͭΒΈͱରԠ # ݕࡧ΍Ұཡςʔϒϧͷදࣔ࣌ͷརศੑ޲্ͷͨΊʹɺετϨʔδʹॻ ͖ࠐΜͩσʔλΛ%#ʹ΋࿈ܞ͢Δඞཁ͕͋Δɻ # %#΁ͷॻ͖ࠐΈΛτϥϯβΫγϣϯͷൃߦΛಉ࣌ʹ͢Δ৔߹͸ɺΤ

    ϥʔϋϯυϦϯά͕೉͍͠ɻ # ΠϕϯτΛ؂ࢹͯ͠%#ʹॻ͖ࠐΉ৔߹͸ɺڞ௨ԽͰ͖ͳ͍ͱ؂ࢹର৅ ͕૿͑ͯॲཧ͕ΧΦεʹͳΓ͕ͪɻͲ͏͠Α͏΋ͳ͍ɻ
  20. (BT-JNJU લఏ # αʔόʔαΠυͰτϥϯβΫγϣϯΛൃߦ͢Δ # ύϒϦοΫνΣʔϯ ͭΒΈͱରԠ # 8FCKTͷFTUJNBUF(BTΛ༻͍ͯHBT-JNJUΛઃఆ͍͕ͨ͠ɺ࣮ࡍͷফ අHBTΛԼճͬͨΓɺ#MPDLͷHBT-JNJUΛ௒͑ͯΤϥʔΛు͍ͨΓͯ͠

    ҆ఆ͠ͳ͍͜ͱ͕ͨ·ʹ͋Δɻ # ݁ہ࣮ࡍͷফඅHBTʹগ͠ΛόοϑΝΛ࣋ͨͨ͠ݻఆ஋ͱ͢Δͷ͕҆ ఆͦ͠͏ɻͨͩ౎౓ফඅHBTΛࢉग़͢Δͷ͕໘౗ɻ
  21. /PODF໰୊ લఏ # αʔόʔαΠυͰτϥϯβΫγϣϯΛൃߦ͢Δ # ύϒϦοΫνΣʔϯϓϥΠϕʔτνΣʔϯ ͭΒΈͱରԠ # ͭͷϓϩηεͰෳ਺ͷίϯτϥΫτͷϝιουΛಉ࣌ʹ࣮ߦ͢Δ৔ ߹ɺ/PODFΛਖ਼͘͠ΠϯΫϦϝϯτ͠ͳ͍ͱΤϥʔʹɻ

    # ͨͩͭͣͭ͠ॲཧ͕ऴΘΔͷΛ଴͍ͬͯͯ͸ͱͯ΋ඇޮ཰ɻ # ಉ࣮࣌ߦ࣌͸ΠϯΫϦ͢ΔλΠϛϯάΛ޻෉͢Δඞཁ͕͋Δɻ
  22. /PODF໰୊ export class SampleService { : call(): void { const

    provider = new Web3.providers.WebsocketProvider(GETH.HOST); : let nonce = await this.web3Service.getPendingTxCount(ADDRESS); const getNonce = () => { const rv = nonce; nonce += 1; return rv; }; await Promise.all([ this.web3Service.send( contract, ‘setFoo’, { foo: 'bar' }, getNonce() ), this.web3Service.send( contract, 'setHage’, { hage: true }, getNonce() ), ]); } : }
  23. ίϯτϥΫτංେԽ໰୊ લఏ # ύϒϦοΫνΣʔϯ ͭΒΈͱରԠ # &3$΍ɺͳͲΛࢀরΛ͢ΔΑ͏ͳίϯτϥΫτΛ࡞੒͢ Δ৔߹ɺ୯७ʹJNQPSU͢ΔͱJNQPSUͨ͠෼ίϯτϥΫταΠζ͕ංେ Խͯ͠͠·͏ɻ #

    ΠϯλʔϑΣʔε͚ͩJNQPSUͯ͠ΠϯελϯεԽͯ͠͠·͑͹ղܾʂ
  24. ίϯτϥΫτංେԽ໰୊ pragma solidity ^0.5.0; : contract IERC20 { function balanceOf(address

    address) public returns (uint256); } contract HogeContract { function balanceOf(address token, address holder) external { return IERC20(token).balanceOf(holder); } : }
  25. ಈ࡞֬ೝਏ͗͢໰୊ લఏ # ͳ͠ ͭΒΈͱରԠ # ґଘ͢ΔίϯτϥΫτ͕૿͑Δͱɺ3FNJYͩͱಈ࡞͢Δঢ়ଶ͍࣋ͬͯ ͘ͷ͕େมɻ # ͞ΒʹίϯτϥΫτΛԿ౓΋ίʔϧ͍ͯ͠ΔͱϑϦʔζͯ͠ಈ͔ͳ͘

    ͳΔ͜ͱ΋ɻɻ # ͦ͜Ͱ4PMJEJUZͦ͜ςετۦಈ։ൃɻςετΛॻ͍͔ͯΒಈ͘Α͏ʹί ϯτϥΫτΛमਖ਼͠Α͏ʂ
  26. ಈ࡞֬ೝਏ͗͢໰୊ const FooMarket = artifacts.require('FooMarket'); const HogeToken = artifacts.require('HogeToken'); :

    contract('FooMarket', function ([owner, alice]) { beforeEach(async function () { this.HodeToken = await HogeToken.new(); this.FooMarket = await FooMarket.new(this.HodeToken.address, { from: owner }); await this.FooMarket.setWhitelisted(owner, true, { from: owner }); await this.FooMarket.setWhitelisted(alice, true, { from: owner }); }); describe('transfer hoge token', function () { it('token balance should be changed', async function () { await this.HogeToken.mint(alice, 100, { from: owner }); assert(await this.FooMarket.transfer(alice, bob, 100, { from: owner })); const aliceBalance = await this.HogeToken.balanceOf(alice); const bobBalance = await this.HogeToken.balanceOf(bob); assert.equal(aliceBalance, 0); assert.equal(bobBalance, 100); }); }); : });
  27. 4PMJEJUZͷ͕ͤ͘ڧ͗͢໰୊ લఏ # ͳ͠ ͨͩͷͭΒΈ # جຊGPS෼͸࢖͑ͳ͍ɻͦͷͨΊಾͷঢ়ଶΛ؅ཧ͢Δม਺͕૿͑ͯ͠· ͏͜ͱ͕ଟʑ͋Δɻ # ഑ྻͷ࡟আͷ࢓༷͕͍·͍ͪͰਏ͍ɻ഑ྻͷॱ൪͕୲อ͞Εͳ͍ಾͷ

    ํ๏͕ඞཁʹͳΔͷͰɺ·ͨঢ়ଶΛ؅ཧ͢Δม਺͕૿͑ͯ͠·͏ɻ # ͦͯ͠TUBDLUPPEFFQɻɻɻ
  28. 4PMJEJUZͷ͕ͤ͘ڧ͗͢໰୊ contract Hoge { uint256[] private targetValues; mapping(uint256 => uint256)

    private targetValuesIndex; mapping(uint256 => bool) private valueStatus; function add(uint256 _targetId) public { require(!exists(_targetId)); targetValuesIndex[_targetId] = targetValues.push(_targetId) - 1; valueStatus[_targetId] = true; } function remove(uint256 _targetId) public { require(exists(_targetId)); uint256 targetIndex = targetValuesIndex[_targetId]; uint256 lastIndex = targetValues.length - 1; uint256 lastTargetId = targetValues[lastIndex]; valueStatus[_targetId] = false; targetValues[targetIndex] = lastTargetId; targetValues.length--; targetValuesIndex[lastTargetId] = targetIndex; targetValuesIndex[_targetId] = 0; } function exists(uint256 _targetId) public view returns (bool) { return valueStatus[_targetId]; } }
  29. ݁ہҰ൪ͷղܾࡦ͸

  30. ίϯτϥΫτΛॻ͔ͳ͍

  31. !CJHB