Hyperledger Explorer
Hyperledger Explorer is a simple, powerful, easy-to-use, highly maintainable, open source browser for viewing activity on the underlying blockchain network.
Directory Structure
├── app fabric GRPC interface
├── db the mysql script and help class
├── explorer_client Web Ui
├── first-network Basic fabric network setup
├── listener websocket listener
├── metrics metrics about tx count per minute and block count per minute
├── service the service
├── socket push real time data to front end
├── timer Timer to post information periodically
└── utils Various utility scripts
Requirements
Following are the software dependencies required to install and run hyperledger explorer
- nodejs 6.9.x (Note that v7.x is not yet supported)
- mysql 5.7 or greater
Hyperledger Explorer works with Hyperledger Fabric 1.0. Install the following software dependencies to manage fabric network.
- docker 17.06.2-ce [https://www.docker.com/community-edition]
- docker-compose 1.14.0 [https://docs.docker.com/compose/]
Clone Repository
Clone this repository to get the latest using the following command.
- git clone https://github.com/hyperledger/blockchain-explorer.git
- cd blockchain-explorer
Database setup
Run the database setup scripts located under db/fabricexplorer.sql
mysql -u -p < db/fabricexplorer.sql
Fabric network setup
Setup your own network using Build your network tutorial from Fabric. Once you setup the network, please modify the values in config.json accordingly.
Running blockchain-explorer
On another terminal,
- cd blockchain-explorer
- Modify config.json to update network-config
Change “fabric-path” to your fabric network path, example “/home/user1/workspace/fabric-samples” for the following keys: “tls_cacerts”, “key”, “cert”.
Final path for key “tls_cacerts” will be “/home/user1/workspace/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt” Modify config.json to update one of the channel
mysql host, username, password details
“channel”: “mychannel”,
“mysql”:{
“host”:”127.0.0.1”,
“database”:”fabricexplorer”,
“username”:”root”,
“passwd”:”123456”
}
If you are connecting to a non TLS fabric peer, please modify the
protocol (grpcs->grpc) and port (9051-> 9050) in the peer url and remove the tls_cacerts. Depending on this key, the application decides whether to go TLS or non TLS route.
- npm install
- ./start.sh
Launch the URL http://localhost:8080 on a browser.
重要的要修改第二步,在config.json中fabric-path改為實際的路徑
常見問題集
在ubuntu18下運行正常的blockchain-explorer 可以 通過打包復制到新機器centos7下 避免容易出問題npm install 的地方
TypeError: Cannot read property ‘on’ of undefined 問題
[root@localhost blockchain-explorer]# ./start.sh
/opt/gopath/src/github.com/hyperledger/blockchain-explorer/main.js:74
server.on('connection', connection => {
^
TypeError: Cannot read property 'on' of undefined
at Object.<anonymous> (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/main.js:74:8)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
暫時沒找到原因 npm install 通過淘寶鏡像 安裝 的正常,初步猜測1.npm install 淘寶 的問題,2.fabric的config.json配置問題,再看看
運行在 fabric-samples下的fabcar上引起的問題
[root@localhost blockchain-explorer]# ./start.sh
postgres://hppoc:password@127.0.0.1:5432/fabricexplorer
(node:4774) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, scandir '/opt/gopath/src/github.com/hyperledger/fabric-samples/basic-network/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore'
at Object.fs.readdirSync (fs.js:904:18)
at Object.readAllFiles (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/helper.js:25:18)
at Platform.setAdminForClient (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric/Platform.js:78:37)
at Platform.initialize (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric/Platform.js:146:18)
at <anonymous>
(node:4774) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (node:4774) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^CReceived kill signal, shutting down gracefully
Closed out remaining connections
刪除fabric的config.json中多余的證書,主意標點符號,別刪多了少了,不然會出現 TypeError: Cannot read property ‘on’ of undefined 問題
[root@localhost blockchain-explorer]# ./start.sh /opt/gopath/src/github.com/hyperledger/blockchain-explorer/main.js:74 server.on('connection', connection => { ^ TypeError: Cannot read property 'on' of undefined at Object.<anonymous> (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/main.js:74:8) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3
forEach 問題(https://github.com/hyperledger/blockchain-explorer/blob/release-3.5/TROUBLESHOOT.md)
[root@localhost blockchain-explorer]# ./start.sh postgres://hppoc:password@127.0.0.1:5432/fabricexplorer E0903 03:29:13.267101332 4851 ssl_transport_security.cc:989] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number. E0903 03:29:14.269565151 4851 ssl_transport_security.cc:989] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number. E0903 03:29:16.173519478 4851 ssl_transport_security.cc:989] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number. error: [Remote.js]: Error: Failed to connect before the deadline error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: Failed to connect before the deadline at checkState (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/grpc/src/client.js:838:16) (node:4851) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined at Platform.setChannels (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric/Platform.js:192:26) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) (node:4851) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:4851) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. E0903 03:29:18.679853789 4851 ssl_transport_security.cc:989] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number. ^CReceived kill signal, shutting down gracefully Closed out remaining connections
參考官方的說明,大概就是把config.json中的grpcs 改為grpc就行
最后,版本容易引起問題,release-3.5 使用postgrsql db
db error { error: Ident authentication failed for user “hppoc”
1). 運行下面的命令編輯pg_hba.conf文件 sudo vim /etc/postgresql/9.1/main/pg_hba.conf
2). 將
# Database administrative login by Unix domain socket
local all postgres peer
改為
# Database administrative login by Unix domain socket
local all postgres trust
入鄉隨俗
初步修改為中文,注意事項:
修改文件為blockchain-explorer\client\src\components\Header 和blockchain-explorer\client\src\components\View 等其它的
修改后在blockchain-explorer/client 執行npm run build 才行
斷斷續續兩天, 終於完成了blockchain-explorer 90%的漢化,大致效果如下:
使用的版本是release-3.5,其它的沒有測試,總結起來沒什么技術含量,需要注意的一點是修改后需要編譯才能起作用
漢化代碼
還有個事svg文件編譯,自行百度Adobe Illustrator吧
如果有翻譯的不合適或者有更好的表述,歡迎留言