1
1

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.

Docker内のUbuntu上のHyperLedger Fabric 1.1 Composerでチュートリアルを実施&REST APIで公開してみた。

Last updated at Posted at 2018-06-23

概要

https://qiita.com/mogiken/items/be2317b07a41f494a494 で構築したDocker環境のHyperLedgerでチュートリアルを実施しました。
そのあとREST APIで公開するまでの手順です。
タイムアウトが出るときはEXPORT設定やインスタンスの状態をチェック。
yoコマンドはrootでは動かないので注意。

PlaygroundのConnection: Web Browserのチュートリアル

参考:https://hyperledger.github.io/composer/latest/tutorials/playground-tutorial.html
Playgroundを起動してブラウザからhttp://localhost:8080/ でアクセスします。
「Connection: Web Browser」の「Deploy a new business network」からチュートリアルの通り作成します。特に問題なく動作します。
この環境はブラウザ上で実行しているだけ。デバッグ用です。ここで開発・動作確認します。

Playgroundで動作完了したらサーバー環境にDeployします。

参考:https://hyperledger.github.io/composer/latest/tutorials/developer-tutorial.html
基本、コマンドラインで実行しまう。PlaygroundにそれらしいUIはありますが、動きが不安定です。Web BrowserでExportしたカードもインポートできません。

yoコマンドがrootで実行できないのでfabricアカウントでテンプレートを作成したあとrootにコピーして使います。
$ adduser fabric パスワードもfabric
$ su fabric
$ cd
$ yo hyperledger-composer:businessnetwork #下記のように入力
? Business network name: tutorial-network
? Description: test
? Author name: mogi
? Author email: mogi@gashfara.com
? License: Apache-2.0
? Namespace: org.example.mynetwork
$ exit #rootにもどって作成したテンプレートを編集する。
$ cd ~/fabric
$ mv /home/faric/tutorial-network .
$ vim tutorial-network/models/org.example.mynetwork.cto
チュートリアルのようにモデルを編集します。
vim tutorial-network/lib/logic.js
チュートリアルのようにスクリプトを編集します。
vim tutorial-network/permissions.acl
チュートリアルのようにアクセス権を編集します。
$ cd tutorial-network
$ composer archive create -t dir -n .
ファイル tutorial-network@0.0.1.bna が作成される。
このカードをサーバーにdeployします。
$ composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna
$ composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card
このタイミングでDockerのインスタンスが1つ増えます。
$ composer card import --file networkadmin.card
$ composer network ping --card admin@tutorial-network
playgroundで登録が確認できます。

REST APIの公開

$ cd ~/fabric
$ composer-rest-server  #下記のように入力
? Enter the name of the business network card to use: admin@tutorial-network
? Specify if you want namespaces in the generated REST API: never use namespaces
? Specify if you want to use an API key to secure the REST API: No
? Specify if you want to enable authentication for the REST API using Passport: No
? Specify if you want to enable event publication over WebSockets: Yes
? Specify if you want to enable TLS security for the REST API: No

ブラウザから http://localhost:3000/explorer で表示できます。

スクリーンショット 2018-06-23 19.11.03.png
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?