kharukaのブログ~お金と技術とキャリア~

Edu Fin~金融×教育~若いうちからお金について学ぶってだいじ!学んだテクノロジーはみんなの財産。過去、現在、将来の人生についてのブログ

【Libra】Libraをさわってみた

エンジニアスクールFLOC

Pythonで動かして学ぶ!あたらしいブロックチェーンの教科書 (AI & TECHNOLOGY)

Pythonで動かして学ぶ!あたらしいブロックチェーンの教科書 (AI & TECHNOLOGY)

Libra

Facebookの独自ブロックチェーンLibra

Libraのミッション

Libraのミッションは「多くの人びとに力を与える、シンプルで国境のないグローバルな通貨と金融インフラになる」ことです。

FBは世界通貨をつくろうとしているようです。

Libraとは

Libra通貨

通貨の単位は「Libra」です。

Libraリザーブ

Libraは、「Libraリザーブ」と呼ばれる実在の資産のリザーブによる十分な裏付けと、Libraを売買する取引所の競争力のあるネットワークによるサポートを有する、安定性のあるデジタル暗号通貨としてデザインされています。

Tether(USDT)などは価格の安定を目的にUSDにペッグ(連動)させています。

LibraはUSD、EUR、JPY、GBPの4法定通貨を裏付けとしたLibraリザーブで価格安定を図ります。

Libraブロックチェーン

Libra通貨の基盤は「Libraブロックチェーン」です。

「Move」は、Libraブロックチェーンに独自の取引ロジックや「スマートコントラクト」を実装するための新しいプログラミング言語です。

EthereumのSolidityに相当する、MoveがLibraブロックチェーンで採用されています。

Libra(testnet)インストール

前提条件

All commands in this document assume that:

  • You are running on a Linux (Red Hat or Debian-based) or macOS system.

  • You have a stable connection to the internet.

  • git is installed on your system.

  • Homebrew is installed on a macOS system.

  • yumor apt-get is installed on a Linux system.

1.Clone Libra:

$ git clone https://github.com/libra/libra.git && cd libra

or Download Libra:

$ unzip libra-master.zip

2.Install Dependencies:

$ cd libra-master
$ ./scripts/dev_setup.sh
Welcome to Libra!

This script will download and install the necessary dependencies needed to
build Libra Core. This includes:
        * Rust (and the necessary components, e.g. rust-fmt, clippy)
        * CMake, protobuf, go (for building protobuf)

If you'd prefer to install these dependencies yourself, please exit this script
now with Ctrl-C.

Proceed with installing necessary dependencies? (y/N) > y
...

Ubuntuだとうまくいかず、macOSで検証。

前提条件をみたしてないから?やっぱり?

Ubuntuも対応して欲しいなー。

...
Proceed with installing necessary dependencies? (y/N) > y
Installing Rust......
Rust is already installed
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-updates

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.35.0 (3c235d560 2019-05-20)

info: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is up to date
info: component 'clippy' for target 'x86_64-unknown-linux-gnu' is up to date
Installing CMake......
有効なリポジトリーがありません。
 「yum repolist all」を実行し、所持するリポジトリーを参照してください。
 「yum-config-manager --enable <repo>」でリポジトリーを有効にできます。

3.Run the CLI:

$ ./scripts/cli/start_cli_testnet.sh
...
Connected to validator at: ac.testnet.libra.org:8000
usage: <command> <args>

Use the following commands:

account | a 
    Account operations
query | q 
    Query operations
transfer | transferb | t | tb 
    <sender_account_address>|<sender_account_ref_id> <receiver_account_address>|<receiver_account_ref_id> <number_of_coins> [gas_unit_price_in_micro_libras (default=0)] [max_gas_amount_in_micro_libras (default 10000)] Suffix 'b' is for blocking. 
    Transfer coins (in libra) from account to another.
help | h 
    Prints this help
quit | q! 
    Exit this client


Please, input commands: 

libra%

4.Run Your First Transaction:

Libra(testnet)送金

the CLI ClientのRunningチェック

libra% account
usage: account <arg>

Use the following args for this command:

create | c
    Create an account. Returns reference ID to use in other operations
list | la
    Print all accounts that were created or loaded
recover | r <file_path>
    Recover Libra wallet from the file path
write | w <file_path>
    Save Libra wallet mnemonic recovery seed to disk
mint | mintb | m | mb <receiver_account_ref_id>|<receiver_account_address> <number_of_coins>
    Mint coins to the account. Suffix 'b' is for blocking

AliceとBobのアカウント作成

Aliceのアカウント作成

libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #0 address 9c1f5e284fefd637769c87fd75f9facc5f0ab3f535fb3a7db899dcdd3f5a00dc

Bobのアカウント作成

libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #1 address 69642b7691a5c8f675b9e126ad055f959994a9edc80324e29059885e9523a43f
libra% account list

List Accounts

libra% account list
User account index: 0, address: 9c1f5e284fefd637769c87fd75f9facc5f0ab3f535fb3a7db899dcdd3f5a00dc, sequence number: 0, status: Local
User account index: 1, address: 69642b7691a5c8f675b9e126ad055f959994a9edc80324e29059885e9523a43f, sequence number: 0, status: Local

Libra CoinsをAliceとBobのアカウントに追加

Libra CoinsをAliceのアカウントに追加

libra% account mint 0 110
>> Minting coins
Mint request submitted

Libra CoinsをBobのアカウントに追加

libra% account mint 1 52
>> Minting coins
Mint request submitted

残高チェック

Aliceの残高チェック

libra% query balance 0
Balance is: 110.000000

Bobの残高チェック

libra% query balance 1
Balance is: 52.000000

Submit a Transaction

アカウントのシーケンスをクエリ

libra% query sequence 0
>> Getting current sequence number
Sequence number is: 0
libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0

AliceからBobへ10Libra送金

libra% transfer 0 1 10
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>

transaction statusをクエリ

libra% query txn_acc_seq 0 0 true
>> Getting committed transaction by account and sequence number
Committed transaction: SignedTransaction { 
 raw_txn: RawTransaction { 
    sender: 9c1f5e284fefd637769c87fd75f9facc5f0ab3f535fb3a7db899dcdd3f5a00dc, 
    sequence_number: 0, 
    payload: {, 
        transaction: peer_to_peer_transaction, 
        args: [ 
            {ADDRESS: 69642b7691a5c8f675b9e126ad055f959994a9edc80324e29059885e9523a43f},
            {U64: 10000000}, 
        ]
    }, 
    max_gas_amount: 10000, 
    gas_unit_price: 0, 
    expiration_time: 1561453406s, 
}, 
 public_key: 5329bd75b441232fd25b8a1c69da9252ffa4c4eb123ece3fe9255aa40f1f3481, 
 signature: Signature( R: CompressedEdwardsY: [234, 122, 132, 248, 8, 38, 17, 244, 250, 159, 53, 8, 138, 251, 180, 34, 162, 112, 211, 95, 63, 12, 10, 41, 166, 172, 252, 106, 12, 197, 202, 213], s: Scalar{
    bytes: [229, 182, 23, 26, 48, 128, 241, 38, 230, 4, 122, 175, 60, 89, 118, 110, 98, 98, 39, 58, 141, 236, 32, 72, 60, 254, 114, 154, 43, 238, 134, 10],
} ), 
 }
Events: 
ContractEvent { access_path: AccessPath { address: 9c1f5e284fefd637769c87fd75f9facc5f0ab3f535fb3a7db899dcdd3f5a00dc, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: 69642b7691a5c8f675b9e126ad055f959994a9edc80324e29059885e9523a43f, amount: 10000000 } }
ContractEvent { access_path: AccessPath { address: 69642b7691a5c8f675b9e126ad055f959994a9edc80324e29059885e9523a43f, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/received_events_count/" } , index: 0, event_data: AccountEvent { account: 9c1f5e284fefd637769c87fd75f9facc5f0ab3f535fb3a7db899dcdd3f5a00dc, amount: 10000000 } }

AliceからBobへ10Libra送金

これはチュートリアルから少し脱線した作業でした。。。

libra% transferb 0 1 10
>> Transferring
[waiting Transaction completed, found sequence number 2]
Finished transaction!
To query for transaction status, run: query txn_acc_seq 0 1 <fetch_events=true|false>

送金後のSequence Numberをクエリ

libra% query sequence 0
>> Getting current sequence number
Sequence number is: 2
libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0

送金後のアカウントの残高チェック

libra% query balance 0
Balance is: 90.000000
libra% query balance 1
Balance is: 72.000000

AliceからBobへ20Libra送金完了!

仮想通貨取引所

Liquid by Quoine

ウォレット

▼記事の続きは以下へ。

執筆中です。

参考

ビットコインとブロックチェーン

ビットコインとブロックチェーン