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

ビットコインとか勉強会#14 openassets-rubyで学ぶOpen Assets Pr...

Shu Kobuchi
February 01, 2018

ビットコインとか勉強会#14 openassets-rubyで学ぶOpen Assets Protocol

2018年2月1日ビットコインとか勉強会#14「openassets-rubyで学ぶOpen Assets Protocol」の資料です。
https://cryptocurrency.connpass.com/event/76801/

Shu Kobuchi

February 01, 2018
Tweet

More Decks by Shu Kobuchi

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ w খᔹप 4IV,PCVDIJ  w ೥ྸɿY'ࡀʢࠓ೥ͰYࡀʂʂʣ w ࠷ऴֶྺɿϒϩοΫνΣʔϯେֶߍΤϯδχΞ ϒϩϯζίʔε

    ̐ظੜ  w ΩϡʔϒγεςϜͷاը෦໳ w ϒϩοΫνΣʔϯਪਐڠձ #$$$ ձһ w #$$$Ծ૝௨՟;&/ࣾձ࣮ݧʹࢀՃ w ϒϩοΫνΣʔϯϋϒίʔϙϨʔτձһ w ϏϤϯυϒϩοΫνΣʔϯਖ਼ձһ
  2. $PMPSFE$PJOT w #JUDPJOτϥϯβΫγϣϯʹσʔλΛॻ͖ࠐΉ͜ͱͰ#5$Ҏ֎ͷτʔΫ ϯΛදݱ͢Δٕज़ͷ૯শ w ओʹͭͷن֨ʢ0QFO"TTFUT1SPUPDPM $PMV $PJO4QBSL  $ISPNB8BMMFU

    $ISPNBXBZ ʣ͕͋ΓɺͦΕͧΕޓ׵ੑ͸ͳ͍ w ಠࣗ௨՟͕ඞཁͳ$PVOUFS1BSUZ 9$1 ɺ0NOJͱ͸ҟͳΓɺ#5$ͷΈ ͰτʔΫϯൃߦ͕Մೳ w ޿ٛͷҙຯͰɺϒϩοΫνΣʔϯϓϥοτϑΥʔϜ্ʹൃߦ͢Δಠࣗτʔ ΫϯΛ$PMPSFE$PJOͱݺͿ͜ͱ͕͋Δʢ&UIFSFVN্ͷτʔΫϯͳͲʣ w ࢀߟʣIUUQTKQCJUDPJODPNCJUDPJODPMPSFEDPJO
  3. 0QFO"TTFUT1SPUPDPM w 8IJUFQFQBSʣIUUQTHJUIVCDPN0QFO"TTFUTPQFOBTTFUT QSPUPDPMCMPCNBTUFSBEESFTTGPSNBUNFEJBXJLJ w ҆౔ໜږࢯʹΑΔ೔ຊޠ༁ʣIUUQUFDINFEJBUIJOLIBUFOBCMPHDPN FOUSZ w $PMPSFE$PJOTͷதͰ୅දతͳ࣮૷ن֨ w

    #JUDPJOωοτϫʔΫ্ʹ୭Ͱ΋ಠࣗτʔΫϯΛൃߦɾҠసͰ͖Δ w /BTEBR͕ະެ։גऔҾͷ࣮ݧʹ࢖༻ w 7"-6ͷτʔΫϯʹར༻ʢͨͩ͠ɺϒϩοΫνΣʔϯ্ͰൃߦͷΈͰҠస͠ ͍ͯͳ͍ʣ
  4. 0QFO"TTFUTͷϥΠϒϥϦ w #JUDPJO$PSF CJUDPJOE ʹ͸0QFO"TTFUTΛѻ͏ػೳ͸ͳ͍ͷͰϥΠϒϥϦΛ༻͍Δ w IUUQTHJUIVCDPN0QFO"TTFUTPQFOBTTFUTQSPUPDPM w PQFOBTTFUT 1ZUIPONPEVMF

    ϦϑΝϨϯε࣮૷ w $PMPSDPSF 1ZUIPO 31$JOUFSGBDF w /#JUDPJO $/&5 5SBOTBDUJPO#VJMEFS w #5$3VCZ SVCZ 5SBOTBDUJPO#VJMEFS w $PSF#JUDPJO 0CKFDUJWF$  w PQFOBTTFUTSVCZ SVCZ 31$JOUFSGBDF
  5. PQFOBTTFUTSVCZ w IUUQTHJUIVCDPNIBXJUOPQFOBTTFUTSVCZ w גࣜձࣾϋ΢Πϯλʔφγϣφϧऔక໾҆౔ໜږࢯ͕ɹ։ ൃ w #JUDPJO$PSF CJUDPJOE ͱซ༻ͯ͠0QFO"TTFUTΛऔΓѻ

    ͏ w ϒϩοΫνΣʔϯɾϓϩάϥϛϯάԾ૝௨՟ೖ໳ɹɹʢࢁ ࡚ॏҰ࿠ɾ҆౔ໜږɾాதढ़ଠ࿠ஶɹߨஊࣾग़൛ʣʹ࢖༻ ๏͕هࡌ
  6. PQFOBTTFUTSVCZͷઃఆ w 1PSU͸.BJOOFU͕ 5FTUOFUͱ3FH5FTU͕ require ‘openassets' Bitcoin.network = :testnet3 api

    = OpenAssets::Api.new({ network: ‘testnet', rpc: { user: ‘user', password: ‘password’, schema: ‘http', port: 18332, host: ‘localhost' } })
  7. ൃߦՄೳͳΞυϨεͷ֬ೝ w ΢ΥϨοτ಺ͷ6590ͷ֬ೝ utxo_list = api.list_unspent puts JSON.pretty_generate(utxo_list) w ൃߦͰ͖Δ#5$Λ͍࣋ͬͯΔΞυϨεͷऔಘ

    $ ruby utxo_list.rb [ { "txid": "6737e6d435a2a1066c7b0800175aa94c756e4c0757b60e86c52d199fd5009cce", "vout": 0, "confirmations": 1, "address": "mkdPS159HV6Jfuk7nUH7aKTh4hqmFPqY4n", "oa_address": "bWvbGgAtUkxyzY9uUq6PJEBNGQK1wH3Dqt2", "script": "76a91438101ba7d5652130645bce0d73da9a86b10309da88ac", "script_type": "pubkeyhash", "amount": "1.30000000", "asset_id": null, "asset_quantity": "0", "asset_amount": "0", "account": "openassets", "asset_definition_url": "", "proof_of_authenticity": false, "output_type": "uncolored", "solvable": true, "spendable": true } ]
  8. "TTFU*%ͷऔಘ w "TTFU*%ΛಘΔͨΊͷ3VCZϓϩάϥϜΛ࡞੒ # Bitcoin Address btc_address = 'mkdPS159HV6Jfuk7nUH7aKTh4hqmFPqY4n' #

    Bitcoin Address͔Βެ։伴ͷHash160Λܭࢉ hash160 = Bitcoin.hash160_from_address(btc_address) # ެ։伴ͷHash160͔ΒAsset IDΛܭࢉ asset_id = OpenAssets.pubkey_hash_to_asset_id(hash160) puts asset_id w ࣮ߦ݁Ռʢ"TTFU*%ΛಘΒΕͨʣ $ ruby get_assetid.rb ogCpkuknNNnusz8CN817QNkEezBNAT5qgL
  9. #5$͸ൃߦओମ͕ͳ͍ w #5$ʹ͸ൃߦओମ͕ͳ͍ */ 065 59 */ 065 59 */

    065 59 */ 065 59 */ 065 59 DPJOCBTF 065 $PJOCBTF59 ϚΠφʔใुͰ৽نੜ੒ ೖྗͷిࢠॺ໊͕ͳ͍
  10. τʔΫϯͷൃߦओମ w #5$ʹ͸ൃߦओମ͕ͳ͍͕ɺ0QFO"TTFUT1SPUPDPMʹ͸ ൃߦओମ͕ଘࡏ͢Δ */ 065 59 */ 065 59

    */ 065 59 */ 065 59 065 59 ൃߦ࣌ʹ59࡞੒ऀ ૹۚऀ ͷ ిࢠॺ໊͕ඞཁ */ */ 065 59 */ 065 59 .BSLFS 0VUQVU
  11. "TTFUͷఆٛ w BTTFU@EFpOJUJPOKTPO { "asset_ids": [ “ogCpkuknNNnusz8CN817QNkEezBNAT5qgL" ], "contract_url": “",

    "name_short": “ORB", "name": “ORANGEBEAM", "issuer": "Shu Kobuchi”, "description": "Lightning NetworkϊʔυՔಇه೦”, "description_mime": "text/x-markdown; charset=UTF-8", "type": “Currency", "divisibility": 1, "link_to_website": false, "image_url": “", "version": “1.0" }
  12. Ξηοτͷൃߦ w Ξηοτൃߦͷ3VCZϓϩάϥϜ ઃఆΛॻ͔͘ݺͼग़͢  # Bitcoin Address btc_address =

    ‘mkdPS159HV6Jfuk7nUH7aKTh4hqmFPqY4n' # Bitcoin Address͔Βެ։伴ͷHash160Λܭࢉ hash160 = Bitcoin.hash160_from_address(btc_address) # ެ։伴ͷHash160͔ΒAsset IDΛܭࢉ asset_id = OpenAssets.pubkey_hash_to_asset_id(hash160) # Bitcoin Address͔ΒOpen Assets Addressʹม׵ oa_address = OpenAssets.address_to_oa_address(btc_address) puts "oa_address: " + oa_address # metadata metadata = 'u=https://goo.gl/BDbKJo' tx = api.issue_asset(oa_address, 100000000, metadata) w ࣮ߦ݁Ռʢߦ໨͕τϥϯβΫγϣϯ*%ʣ $ ruby issue.rb oa_address: bWvbGgAtUkxyzY9uUq6PJEBNGQK1wH3Dqt2 f110ec2d5511bbbe0b38f77a72cdb49ef152b15ed2c7b2d5c02904c681c08c94
  13. -&# -JUUMF&OEJBO#BTF w ˣ̎ਐ਺ w ˣԼͷҐ͔ΒCJUͣͭ۠੾Γɺ಄͸ͰຒΊΔ w  w ˣઌ಄ͷΈ಄ʹ̌Λ͚ͭɺଞ͸಄ʹ̍Λ͚ͭΔ

    w ˣਐ਺ w YGYEYDYˣϦτϧΤϯσΟΞϯ w YYDYEYGʢ࠷ޙҎ֎ͷόΠτ͸಄͕ʙGɺ࠷ޙͷόΠτ͸಄͕ʙʣ w DEGʢ%FDPEF͸͜ͷٯΛߦ͏ʣ
  14. Մม௕σʔλͷ෼͚ํ w G DEGEBGGGGFDG CBG w DEGՄม௕Ͱͷ෼ׂՕॴ͕Θ͔Δʂ EBGGGGFDGCBG w όΠτ͋Γɺ࠷ॳͷόΠτͰ۠੾ΔͱY

    ਐ਺Ͱ ࢒Γ όΠτɹϝλσʔλͷ௕͞͸YͰɺ࢒Γ͸ϝλσʔλ EBGGGGFDGCBG w ϝλσʔλ͸ɹVIUUQTHPPHM#%C,+PΛ"4$**ม׵ͨ͠΋ͷ
  15. ΞηοτͷҠస w ΞηοτҠసͷ3VCZϓϩάϥϜ oa_address = 'bWvbGgAtUkxyzY9uUq6PJEBNGQK1wH3Dqt2' asset_id = 'ogCpkuknNNnusz8CN817QNkEezBNAT5qgL' #

    ૹ෇ઌͷAddress to_oa_address = OpenAssets.address_to_oa_address(‘mgQE57qY9Wg1VC1RLrAZ26iFpyvXiEhB8b') tx = api.send_asset(oa_address, asset_id, 10000000, to_oa_address) w ࣮ߦ݁Ռʢ໭Γ஋ɿτϥϯβΫγϣϯ*%ʣ $ ruby send_asset.rb dba232a49167eba5dadf5369d1b1db3e45b2c8810508f773763dc6a238e41173
  16. Ξηοτͷম٫ w Ξηοτম٫ͷ3VCZϓϩάϥϜ # ઃఆΛ͓ͯ͘͠ oa_address = OpenAssets.address_to_oa_address(‘mstcr1gSQ49ZdCj3VjLZiwFMT3T95eqkov') asset_id =

    ‘ogCpkuknNNnusz8CN817QNkEezBNAT5qgL' tx = api.burn_asset(oa_address, asset_id) w ࣮ߦ݁Ռ $ ruby burn_asset.rb fe4f4538999ebefc579cc79d321e476d8b7bd53bb0ec5f92237e18429f41851d
  17. 04$౦ژʹߦ͜͏ʂ w ݄೔ ۚ ೔ ౔ 04$౦ژ!໌੕େֶ w ೔ຊ҉߸௨՟Ϣʔβձ͕ϒʔεग़ల w

    04$ͱ͍͑͹ɺϥζϕϦʔύΠʂϥζϕϦʔύΠͰ#JUDPJOϊʔυ ಈ͔͢σϞ΍Γ·͢ʂ w -JHIUOJOH/FUXPSLͷσϞ΋ʂ