Facebook LibraのTestnetにおいて(正確にはリブラ協会のLibra)、アカウントの作成、送金(トランザクション生成)、ニーモニックによるアカウントのリカバリーを試してみます。
開発環境
macOS Mojave
バージョン10.14
Libra Coreのプロジェクトをクローンします。
1 |
$ git clone https://github.com/libra/libra.git && cd libra |
Libra Coreをインストールします。
1 |
$ ./scripts/dev_setup.sh |
Libra CLIをコンパイルしTestnetに接続します。
1 |
$ ./scripts/cli/start_cli_testnet.sh |
接続に成功すると下記のように表示されます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Building and running client in debug mode. Finished dev [unoptimized + debuginfo] target(s) in 1.89s Running `target/debug/client --host ac.testnet.libra.org --port 8000 -s ./scripts/cli/trusted_peers.config.toml` 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% |
ヘルプを見ます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
libra% help 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 |
アカウントに関するコマンド一覧です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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 |
アカウント、ニーモニックファイルの作成
「account create」でアカウントを作成します。
1 2 3 |
libra% account create >> Creating/retrieving next account from wallet Created/retrieved account #0 address f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607 |
送金するためにもう一つのアカウントを作成します。
1 2 3 |
libra% account create >> Creating/retrieving next account from wallet Created/retrieved account #1 address ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a |
作成したアカウントのリストを見ます。index 0と1のアカウントとそれぞれのアドレスが確認できます。
1 2 3 |
libra% account list User account index: 0, address: f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607, sequence number: 0, status: Local User account index: 1, address: ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a, sequence number: 0, status: Local |
「account write」でニーモニックファイルを作成します。今回はmnemonic.txtという名前にしました。
1 2 3 |
libra% account write mnemonic.txt >> Saving Libra wallet mnemonic recovery seed to disk Saved mnemonic seed to disk |
成功するとlibraディレクトリ内にmnemonic.txtが作成され、24個のワードが生成されているのが確認できます。
1 2 |
$ cat mnemonic.txt subject bike item sudden sound across milk vanish weird near wrap float glare garbage color heavy grant cricket month shield sleep spider violin popular;2 |
送金する
index 0のアカウントに100リブラ生成(発行)し、index 1のアカウントに対して10リブラ送ってみます。
まず「account mint」でindex 0のアカウントに100リブラ生成します。
1 2 3 |
libra% account mint 0 100 >> Minting coins Mint request submitted |
「query balance」でindex 0のアカウントの残高を確認します。
1 2 |
libra% query balance 0 Balance is: 100 |
「transfer」で index 0から1のアカウントへ10リブラ送ります。
1 2 3 4 |
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> |
それぞれのアカウントの残高を確認します。
1 2 |
libra% query balance 0 Balance is: 90 |
1 2 |
libra% query balance 1 Balance is: 10 |
トランザクションのステータスを確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
libra% query txn_acc_seq 0 0 true >> Getting committed transaction by account and sequence number Committed transaction: SignedTransaction { raw_txn: RawTransaction { sender: f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607, sequence_number: 0, payload: {, transaction: peer_to_peer_transaction, args: [ {ADDRESS: ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a}, {U64: 10000000}, ] }, max_gas_amount: 10000, gas_unit_price: 0, expiration_time: 1561075568s, }, public_key: 90359fde2f5343799d722ea70b5fa06003ff11200cdf5d8007c7166fbcab04c8, signature: Signature( R: CompressedEdwardsY: [205, 75, 137, 212, 128, 63, 117, 157, 17, 158, 118, 237, 9, 159, 59, 161, 200, 168, 182, 122, 233, 50, 141, 202, 184, 64, 17, 40, 34, 41, 48, 229], s: Scalar{ bytes: [23, 98, 204, 64, 222, 30, 18, 233, 66, 142, 36, 251, 121, 255, 82, 205, 84, 9, 21, 8, 33, 109, 92, 31, 61, 249, 99, 182, 39, 200, 155, 3], } ), } Events: ContractEvent { access_path: AccessPath { address: f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a, amount: 10000000 } } ContractEvent { access_path: AccessPath { address: ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/received_events_count/" } , index: 0, event_data: AccountEvent { account: f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607, amount: 10000000 } } |
「query sequence」でindex 0から送金したトランザクションの回数が確認できます。
1 2 3 |
libra% query sequence 0 >> Getting current sequence number Sequence number is: 1 |
index 1のアカウントからのトランザクションは0回です。
1 2 3 |
libra% query sequence 1 >> Getting current sequence number Sequence number is: 0 |
あと2回 index 0から送金してみます。これで合計3回送金(3回のトランザクション)したことになります。
1 2 3 4 |
libra% transfer 0 1 10 >> Transferring Transaction submitted to validator To query for transaction status, run: query txn_acc_seq 0 1 <fetch_events=true|false> |
1 2 3 4 |
libra% transfer 0 1 10 >> Transferring Transaction submitted to validator To query for transaction status, run: query txn_acc_seq 0 2 <fetch_events=true|false> |
実際にindex 0アカウントのsequenceを確認すると3であることが確認できました。
1 2 3 |
libra% query sequence 0 >> Getting current sequence number Sequence number is: 3 |
受け取った側のindex 1のsequenceは0のままです。
1 2 3 |
libra% query sequence 1 >> Getting current sequence number Sequence number is: 0 |
これまでのindex 0のアカウントの状態を確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
libra% query account_state 0 >> Getting latest account state Latest account state is: Account: f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607 State: Some( AccountStateBlob { Raw: 0x010000002100000001217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc974400000020000000f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607801d2c0400000000000000000000000003000000000000000300000000000000 Decoded: Ok( AccountResource { balance: 70000000, sequence_number: 3, authentication_key: 0xf7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607, sent_events_count: 3, received_events_count: 0, }, ) }, ) Blockchain Version: 62053 |
index 1のアカウントの状態です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
libra% query account_state 1 >> Getting latest account state Latest account state is: Account: ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a State: Some( AccountStateBlob { Raw: 0x010000002100000001217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc974400000020000000ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a80c3c90100000000030000000000000000000000000000000000000000000000 Decoded: Ok( AccountResource { balance: 30000000, sequence_number: 0, authentication_key: 0xac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a, sent_events_count: 0, received_events_count: 3, }, ) }, ) Blockchain Version: 62082 |
アカウントのリカバリー
上述において、libraディレクトリ内に「mnemonic.txt」という名前のアカウントに紐付いたニーモニックファイルを作成しました。このファイルを利用して作成したアカウントのリカバリーをすることができます。
仮にこれを別のlibraプロジェクトを立ち上げ、そのディレクトリ内に「mnemonic.txt」を配置し、下記のように「account recover」を実行します。作成したアカウントがリカバリーされるのが確認できます。送金したリブラなども保存されていることが確認できます。
1 2 3 4 5 |
libra% account recover mnemonic.txt >> Recovering Wallet Wallet recovered and the first 2 child accounts were derived #0 address f7550da222f45c7d83da1d7b1417e6aa7d265ee75a9cd4c3ef8a6a975536b607 #1 address ac812a26e926dd518769c78236d01e57ed03b278de1c9a4a69fc22487b8be24a |
1 2 |
libra% query balance 0 Balance is: 70 |
本記事作成時点では、以上までの機能が実装されているようです。
関連ページ
LibraVistaのlibra-vista-apiとLibra CoreのgRPC概要
参照ページ
libra