9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Hyperledger Iroha v0.95 preview-2 版を動かしてみた

Last updated at Posted at 2017-12-01

Hyperledger Iroha v0.95 preview-2 版が出たので、Macで動かしてみました。
バイナリも提供されている様ですが、ここでは dockerの開発環境でビルドして動かしています。
アセット usd の作成から、aliceからbobへの送金までをしてみました。
以下URLを参考にしています。
https://hyperledger.github.io/iroha-api/#overview
https://github.com/hyperledger/iroha/releases/tag/v0.95_preview-2
ブロックチェーンの勉強の参考になればと思います。

ちなみに、Irohaのデータモデルは以下の様になってます。
+--- Domain ---+
|   Account  |
|    |    |
|   Asset   |
+--------------------+
(例) testドメインの中に aliceアカウントとusdアセットがある場合
+--- test ---+
|   alice  |
|    |   |
|   usd   |
+----------------+

##(1) Iroha v0.95 preview-2 を git clone する
$ git clone -b v0.95_preview-2 --depth=1 https://github.com/hyperledger/iroha.git
##(2) 開発用コンテナ起動
$ ./iroha/scripts/run-iroha-dev.sh
※ 3つのdockerコンテナ(iroha502_node_1, iroha502_redis_1, iroha502_postgres_1)が
  起動するとともに、iroha502_node_1の中に入る。
##(3) ビルド
iroha@XXXXX:/opt/iroha$ cmake -H. -Bbuild; cmake --build build -- -j$(nproc)
##(4) テストしてみる
iroha@XXXXX:/opt/iroha$ cd build
iroha@XXXXX:/opt/iroha/build$ ctest .
##(5) genesisブロックを作成
iroha@XXXXX:/opt/iroha/build$ cd bin
iroha@XXXXX:/opt/iroha/build/bin$ echo 'localhost:10001' > peers.list
iroha@XXXXX:/opt/iroha/build/bin$ ./iroha-cli --genesis_block --peers_address peers.list
※ node0, admin@test, test.testの鍵、genesis.block が作成される。
##(6) 設定ファイルを作成
iroha@XXXXX:/opt/iroha/build/bin$ cp ../../example/config.sample .
※ config.sample 内の redis_host を localhost から iroha502_redis_1 に変更。
 pg_opt の host も localhost から iroha502_postgres_1 に変更。
 また、block_store_path が /tmp/block_store/ となっているが、tmp の下だと
 OS再起動時に削除されてしまうので、/opt/iroha/block_store/ などの様にしておいた方が
 良いと思われる。
##(7) irohad の起動
iroha@XXXXX:/opt/iroha/build/bin$ ./irohad --config ./config.sample --genesis_block ./genesis.block --keypair_name ./node0
※ 初回の起動は上で良いが、2回目以降の起動の際は、--genesis_block オプションは付けない。
 付けてしまうと、/tmp/block_store/以下のブロックが初期化されてしまう。
##(8) 別のターミナルからコンテナに入る
$ ./iroha/scripts/run-iroha-dev.sh
##(9) admin@testでusdアセットを作成
iroha@XXXXX:/opt/iroha$ cd build/bin
iroha@XXXXX:/opt/iroha/build/bin$ ./iroha-cli --interactive --name admin@test
1/12/usd/test/2/2/localhost/50051
(確認)
2/2/usd#test/1/localhost/50051
[08:51:47][th: 2915][info] [QueryResponseHandler] << [Asset]
[08:51:47][th: 2915][info] [QueryResponseHandler] << -Asset Id- usd#test
[08:51:47][th: 2915][info] [QueryResponseHandler] << -Domain Id- test
[08:51:47][th: 2915][info] [QueryResponseHandler] << -Precision- 2
※ 一旦、Ctrl+C で iroha-cli から抜ける

##(10) test ドメインにアカウント alice を作成し、署名(公開鍵)を登録
iroha@XXXXX:/opt/iroha/build/bin$ ./iroha-cli --new_account --name alice@test --pass_phrase alicepass
iroha@XXXXX:/opt/iroha/build/bin$ cat alice@test.pub
(alice@test の public key)
iroha@XXXXX:/opt/iroha/build/bin$ ./iroha-cli --interactive --name admin@test
1/10/alice/test/(public key)/2/localhost/50051
(確認)
2/7/alice@test/1/localhost/50051
[09:04:43][th: 3045][info] [QueryResponseHandler] << [Account]:
[09:04:43][th: 3045][info] [QueryResponseHandler] << -Id:- alice@test
[09:04:43][th: 3045][info] [QueryResponseHandler] << -Domain- test
[09:04:43][th: 3045][info] [QueryResponseHandler] << -Roles-:
user
(確認)
2/5/alice@test/1/localhost/50051
[09:06:26][th: 3045][info] [QueryResponseHandler] << [Signatories]
[09:06:26][th: 3045][info] [QueryResponseHandler] << -Signatory- ??
?ʘ'?B?
?>??6>f{?a?rY?u

##(11) 同様に アカウント bob を登録
(確認)
2/7/bob@test/1/localhost/50051
[09:17:41][th: 3231][info] [QueryResponseHandler] << [Account]:
[09:17:41][th: 3231][info] [QueryResponseHandler] << -Id:- bob@test
[09:17:41][th: 3231][info] [QueryResponseHandler] << -Domain- test
[09:17:41][th: 3231][info] [QueryResponseHandler] << -Roles-:
user
(確認)
2/5/bob@test/1/localhost/50051
[09:19:42][th: 3231][info] [QueryResponseHandler] << [Signatories]
[09:19:42][th: 3231][info] [QueryResponseHandler] << -Signatory- OJ??*7(???z?I?ͨ?ٛ?L?g?f?Ο

##(12) admin@testに1000usd設定
iroha@XXXXX:/opt/iroha/build/bin$ ./iroha-cli --interactive --name admin@test
1/14/admin@test/usd#test/100000/2/2/localhost/50051
(確認)
2/6/admin@test/usd#test/1/localhost/50051
[03:11:10][th: 3041][info] [QueryResponseHandler] << [Account Assets]
[03:11:10][th: 3041][info] [QueryResponseHandler] << -Account Id- admin@test
[03:11:10][th: 3041][info] [QueryResponseHandler] << -Asset Id- usd#test
[03:11:10][th: 3041][info] [QueryResponseHandler] << -Balance- 1000.00

##(13) admin から alice に 200usd 転送
1/3/admin@test/alice@test/usd#test/20000/2/2/localhost/50051
[04:24:33][th: 3041][info] [TransactionResponseHandler] << Transaction successfully sent
Congratulation, your transaction was accepted for processing.
Its hash is f9b914e86aa0bf0d0e05741b7a75fbb155585fb73751046ec3c32c27102e13b1

(確認)
2/6/admin@test/usd#test/1/localhost/50051
[04:25:26][th: 3041][info] [QueryResponseHandler] << [Account Assets]
[04:25:26][th: 3041][info] [QueryResponseHandler] << -Account Id- admin@test
[04:25:26][th: 3041][info] [QueryResponseHandler] << -Asset Id- usd#test
[04:25:26][th: 3041][info] [QueryResponseHandler] << -Balance- 800.00

(確認)
3/1/f9b914e86aa0bf0d0e05741b7a75fbb155585fb73751046ec3c32c27102e13b1/1/localhost/50051
Transaction was successfully committed.

(確認)
2/6/alice@test/usd#test/1/localhost/50051
[04:40:21][th: 3041][info] [QueryResponseHandler] << [Account Assets]
[04:40:21][th: 3041][info] [QueryResponseHandler] << -Account Id- alice@test
[04:40:21][th: 3041][info] [QueryResponseHandler] << -Asset Id- usd#test
[04:40:21][th: 3041][info] [QueryResponseHandler] << -Balance- 200.00

##(14) 同様に admin から bob に100usd 転送

##(15) alice から bob に 10usd 転送
iroha@XXXXX:/opt/iroha/build/bin$ ./iroha-cli --interactive --name alice@test
1/3/alice@test/bob@test/usd#test/10000/2/2/localhost/50051
[04:52:37][th: 4142][info] [TransactionResponseHandler] << Transaction successfully sent
Congratulation, your transaction was accepted for processing.
Its hash is ecc36a3ff54c8c8c21d2233c2ca270dbe0e923977c421a730c4c94f3bcbdf59c

##(16) ブロックの確認
/tmp/block_stores/ の下の最後のブロックを見てみる。
{
"signatures": [
{
"pubkey": "19f5bf5dec59a7ee40e3e609b9d54a0f048633a6db42f27b1609d2d06aa9234e",
"signature": "8bcf30825ad7f709ea20195734d8c18838018f3429cc17b2153a7892bb302ddf6e6c647d6d94a0ae99e740d7d53eb59be4f2f6f432cffbe75be31b78776df507"
}
],
"created_ts": 0,
"hash": "dc372e56fb27c25568522a71097103b41f5b6aa48302bcc62adfab09b547a525",
"prev_hash": "151bef4900ba5164338f2762c3c8cd99d11532b5c2798f26bde8371f6d42c239",
"height": 10,
"txs_number": 1,
"merkle_root": "0000000000000000000000000000000000000000000000000000000000000000",
"transactions": [
{
"signatures": [
{
"pubkey": "9de90ccbca9827b042930ad93e94d5363eff08667b01eebb61ae725903d9750f",
"signature": "ef61b4a21ae767ca7301eb9b6389d1f7d63db5befa457147a471299967b3211224c6614aafe6c90c7af64a2ff2437b45d7ef6fd52d75dab0b76260d2436c780b"
}
],
"created_ts": 1511758357155,
"creator_account_id": "alice@test",
"tx_counter": 1,
"commands": [
{
"command_type": "TransferAsset",
"src_account_id": "alice@test",
"dest_account_id": "bob@test",
"asset_id": "usd#test",
"description": "",
"amount": {
"value": "1000",
"precision": 2
}
}
]
}
]
}

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?