Hyperledger Fabric維護的實際上是一個區(qū)塊鏈網(wǎng)絡胆剧。為了能夠直觀的觀察網(wǎng)絡上的節(jié)點奴紧,交易等行為诽偷,Hyperledger Explore隨之誕生。
本文講述如何搭建 Hyperledger Explore皱坛。
Hyperledger Explorer
源代碼鏈接: https://github.com/hyperledger/blockchain-explorer
目錄結(jié)構(gòu)
├── app Application backend root, Explorer configuration
├── rest REST API
├── persistence Persistence layer
├── fabric Persistence API (Hyperledger Fabric)
├── platform Platforms
├── fabric Explorer API (Hyperledger Fabric)
├── test Application backend test
├── client Web UI
├── public Assets
├── src Front end source code
├── components React framework
├── services Request library for API calls
├── state Redux framework
├── static Custom and Assets
瀏覽器的目的是為了維護網(wǎng)絡,所以默認要啟動一個fabric網(wǎng)絡豆巨。默認讀者已經(jīng)部署了一個BYFN網(wǎng)絡剩辟,如果沒有,參考https://hyperledger-fabric.readthedocs.io/en/latest/build_network.html往扔。
準備
首先需要安裝:
- nodejs 8.11.x (Note that v9.x is not yet supported)
- PostgreSQL 9.5 or greater
- Jq [https://stedolan.github.io/jq/]
注意對應安裝的版本贩猎。一般構(gòu)建完BYFN下面這兩個應該都安裝了:
- docker 17.06.2-ce [https://www.docker.com/community-edition]
- docker-compose 1.14.0 [https://docs.docker.com/compose/]
下載源碼
git上下載源碼
-
git clone https://github.com/hyperledger/blockchain-explorer.git
. -
cd blockchain-explorer
.
配置/初始化數(shù)據(jù)庫
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cd blockchain-explorer/app</pre>
這個文件夾下有一個 explorerconfig.json 里面可以配置數(shù)據(jù)庫。
[](javascript:void(0); "復制代碼")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">{ "persistence": "postgreSQL", "platforms": ["fabric"], "postgreSQL": { "host": "127.0.0.1", "port": "5432", "database": "fabricexplorer", //數(shù)據(jù)庫名稱 "username": "admin123", //用戶名 "passwd": "admin123" //密碼 }, "sync": { "type": "local", "platform": "fabric", "blocksSyncTime": "3" }
}</pre>
](javascript:void(0); "復制代碼")
后續(xù)的初始化腳本會讀取這個文件萍膛,根據(jù)配置的信息登錄數(shù)據(jù)庫吭服,執(zhí)行初始化的創(chuàng)建語句。
執(zhí)行初始化:
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
./createdb.sh</pre>
這個過程如果報錯蝗罗,需要用戶自己登錄postgresql 創(chuàng)建對應的數(shù)據(jù)庫 fabricexplorer艇棕,用戶名 admin123,密碼 admin123.
如果出現(xiàn) Ident authentication failed for user XX錯誤串塑,修改一下pg_hdconfig的配置就可以了沼琉。
執(zhí)行createdb.sh會執(zhí)行同一個文件夾的 explorerpg.sql updatepg.sql
設置fabric網(wǎng)絡
需要配置瀏覽器能找到當前fabric網(wǎng)絡。
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cd blockchain-explorer/app/platform/fabric
vi config.json</pre>
搜索config.json中的所有fabric-path桩匪。我的fabric-sample安裝目錄是 /mnt/fabric-samples/ 打瘪。所以把fabric-path改成 /mnt/fabric-samples/ 。這樣瀏覽器就能夠憑借配置傻昙,找到tlsCACerts adminPrivateKey signedCert 來執(zhí)行網(wǎng)絡的查詢瑟慈。
構(gòu)建Hyperledger Explore
[](javascript:void(0); "復制代碼")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cd blockchain-explorer
npm install
cd blockchain-explorer/app/test
npm install
npm run test
cd client/ npm install
npm test -- -u --coverage
npm run build</pre>
](javascript:void(0); "復制代碼")
在運行test的時候要注意觀察是不是所有的mocha的用例都通過了。
啟動 Hyperledger Explorer
cd blockchain-explorer/
./start.sh
啟動瀏覽器屋匕。這個目錄下的腳本 ./stop.sh 用來關閉葛碧。 默認的端口是8080
訪問對應端口: