HyperLedger Explore 浏览器配置启动教程

Hyperledger Fabric维护的实际上是一个区块链网络。为了能够直观的观察网络上的节点,交易等行为,Hyperledger Explore随之诞生。

本文讲述如何搭建 Hyperledger Explore。

Hyperledger Explorer

源代码链接: https://github.com/hyperledger/blockchain-explorer

目录结构

├── 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

浏览器的目的是为了维护网络,所以默认要启动一个fabric网络。默认读者已经部署了一个BYFN网络,如果没有,参考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/]

注意对应安装的版本。一般构建完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.

配置/初始化数据库

cd blockchain-explorer/app

这个文件夹下有一个 explorerconfig.json   里面可以配置数据库。

{
  "persistence": "postgreSQL",
  "platforms": ["fabric"],
  "postgreSQL": {
    "host": "127.0.0.1",
    "port": "5432",
    "database": "fabricexplorer", //数据库名称
    "username": "admin123",      //用户名
    "passwd": "admin123"         //密码
  },
  "sync": {
    "type": "local",
    "platform": "fabric",
    "blocksSyncTime": "3"
  }
}

后续的初始化脚本会读取这个文件,根据配置的信息登录数据库,执行初始化的创建语句。

执行初始化:

cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
./createdb.sh

这个过程如果报错,需要用户自己登录postgresql  创建对应的数据库 fabricexplorer,用户名 admin123,密码 admin123.

如果出现 Ident authentication failed for user XX错误,修改一下pg_hdconfig的配置就可以了。

执行createdb.sh会执行同一个文件夹的 explorerpg.sql  updatepg.sql

设置fabric网络

需要配置浏览器能找到当前fabric网络。

cd blockchain-explorer/app/platform/fabric
vi config.json

搜索config.json中的所有fabric-path。我的fabric-sample安装目录是  /mnt/fabric-samples/ 。所以把fabric-path改成   /mnt/fabric-samples/  。这样浏览器就能够凭借配置,找到tlsCACerts adminPrivateKey signedCert 来执行网络的查询。

构建Hyperledger Explore

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

在运行test的时候要注意观察是不是所有的mocha的用例都通过了。

启动 Hyperledger Explorer

  • cd blockchain-explorer/
  • ./start.sh

启动浏览器。这个目录下的脚本 ./stop.sh 用来关闭。 默认的端口是8080

访问对应端口:

原文地址:https://www.cnblogs.com/gzhlt/p/10142203.html