fabric1.1 搭建Hyperledger Explorer

目录

环境

搭建过程

下载项目

创建用户

进入数据库

fabric网络部署

修改config.json 

构建Hyperledger Explorer

npm install

npm install

npm run test

npm install

npm test -- u --coverage

npm run build

运行hyperledger-explorer

总结

参考文献

环境

这几个软件版本很关键,要对应好,否则后面进行npm install的时候会出现很多问题:

  1. fabric    v1.1
  2. fabric-explorer     v3.5
  3. node    v8.11.2
  4. npm    v5.10.0

搭建过程

下载项目

首先是git clone https://github.com/hyperledger/blockchain-explorer.git到你指定的项目存储目录,比如我是在/opt/gopath/src/github.com/hyperledger目录下进行git的。在git的时候可能会很慢,网上找到一个方法不错,可以看这里。

下载后进入blockchain-exploer目录,运行git checkout -b release-3.5 origin/release-3.5将版本切换到3.5版本。

创建用户

在blockchain-explorer/app/persistence/postgreSQL/db目录下执行./createdb.sh

[root@slave3 db]# ./createdb.sh 
USER="hppoc"
DATABASE="fabricexplorer"
PASSWD='password'
Creating Default user...
错误:  选项冲突或过多
psql:./explorerpg.sql:5: 错误:  角色"hppoc" 已经存在
DROP DATABASE
CREATE DATABASE
您现在已经连接到数据库 "fabricexplorer",用户 "postgres".
psql:./explorerpg.sql:14: 注意:  表 "blocks" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:33: 注意:  表 "chaincodes" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:51: 注意:  表 "peer_ref_chaincode" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:66: 注意:  表 "channel" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:89: 注意:  表 "peer" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:108: 注意:  表 "peer_ref_channel" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:123: 注意:  表 "orderer" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
psql:./explorerpg.sql:139: 注意:  表 "transactions" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:169: 注意:  表 "write_lock" 不存在
DROP TABLE
CREATE TABLE
ALTER TABLE
ALTER SEQUENCE
psql:./explorerpg.sql:177: 注意:  索引 "blocks_blocknum_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:180: 注意:  索引 "blocks_channel_genesis_hash_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:183: 注意:  索引 "blocks_createdt_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:186: 注意:  索引 "transaction_txhash_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:189: 注意:  索引 "transaction_channel_genesis_hash_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:192: 注意:  索引 "transaction_createdt_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:195: 注意:  索引 "transaction_blockid_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:198: 注意:  索引 "transaction_chaincode_proposal_input_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:201: 注意:  索引 "channel_channel_genesis_hash_idx" 不存在
DROP INDEX
CREATE INDEX
psql:./explorerpg.sql:204: 注意:  索引 "channel_channel_hash_idx" 不存在
DROP INDEX
CREATE INDEX
GRANT
您现在已经连接到数据库 "fabricexplorer",用户 "postgres".

进入数据库

[root@slave3 db]# sudo -u postgres psql
psql (9.6.12)
输入 "help" 来获取帮助信息.

postgres=# 

fabric网络部署

修改config.json 

根据你已经部署好的fabric网络更改配置文件:blockchain-explorer/app/platform/fabric/config.json 

{
  "network-config": {
    "org1": {
      "name": "peerOrg1",
      "mspid": "CoreOrg1MSP",
      "peer0": {
        "requests": "grpc://192.168.89.131:7051",
        "events": "grpc://192.168.89.131:7053",
        "server-hostname": "peer0.org1.scf.com",
        "tls_cacerts":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org1.scf.com/peers/peer0.org1.scf.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org1.scf.com/users/[email protected]/msp/keystore",
        "cert":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org1.scf.com/users/[email protected]/msp/signcerts"
      }
    },
    "org2": {
      "name": "peerOrg2",
      "mspid": "SupplyOrg2MSP",
      "peer0": {
        "requests": "grpc://192.168.89.131:8051",
        "events": "grpc://192.168.89.131:8053",
        "server-hostname": "peer0.org2.scf.com",
        "tls_cacerts":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org2.scf.com/peers/peer0.org2.scf.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org2.scf.com/users/[email protected]/msp/keystore",
        "cert":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org2.scf.com/users/[email protected]/msp/signcerts"
      }
    },
    "org3": {
      "name": "peerOrg3",
      "mspid": "BankOrg3MSP",
      "peer0": {
        "requests": "grpc://192.168.89.131:9051",
        "events": "grpc://192.168.89.131:9053",
        "server-hostname": "peer0.org3.scf.com",
        "tls_cacerts":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org3.scf.com/peers/peer0.org3.scf.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org3.scf.com/users/[email protected]/msp/keystore",
        "cert":
          "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/peerOrganizations/org3.scf.com/users/[email protected]/msp/signcerts"
      }
    }
  },
  "channel": "mychannel",
  "orderers": [
    {
      "mspid": "OrdererMSP",
      "server-hostname": "orderer.scf.com",
      "requests": "grpc://192.168.89.131:7050",
      "tls_cacerts":
        "/opt/gopath/src/github.com/hyperledger/fabric/scf/crypto-config/ordererOrganizations/scf.com/orderers/orderer.scf.com/tls/ca.crt"
    }
  ],
  "keyValueStore": "/tmp/fabric-client-kvs",
  "configtxgenToolPath": "/opt/gopath/src/github.com/hyperledger/fabric/scf/bin",
  "SYNC_START_DATE_FORMAT": "YYYY/MM/DD",
  "syncStartDate": "2019/04/05",
  "eventWaitTime": "30000",
  "license": "Apache-2.0",
  "version": "1.1"
}

 可以看到我在org1组织中只配置了peer0一个节点,如果需要在浏览器中显示多个,可以在此配置文件中添加peer1,peer2等,如:

"org1": {
      "name": "peerOrg1",
      "mspid": "Org1MSP",
      "peer0": {
        "requests": "grpcs://127.0.0.1:7051",
        "events": "grpcs://127.0.0.1:7053",
        "server-hostname": "peer0.org1.example.com",
        "tls_cacerts":
          "/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
      },
	  "peer1": {
        "requests": "grpcs://127.0.0.1:8051",
        "events": "grpcs://127.0.0.1:8053",
        "server-hostname": "peer1.org1.example.com",
        "tls_cacerts":
          "/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
      },
      "admin": {
        "key":
          "/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore",
        "cert":
          "/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts"
      }
    },

构建Hyperledger Explorer

npm install

首先进入blockchain-explorer目录,执行npm install --unsafe-perm下载依赖文件夹node_modules(官方没有--unsafe-perm,可能会导致下载失败):

[root@slave3 blockchain-explorer]# npm install --unsafe-perm

> [email protected] install /opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

make: 进入目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/dtrace-provider/build”
  TOUCH Release/obj.target/DTraceProviderStub.stamp
make: 离开目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/dtrace-provider/build”

> [email protected] install /opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/pkcs11js
> node-gyp rebuild

make: 进入目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/pkcs11js/build”
  CXX(target) Release/obj.target/pkcs11/src/main.o
  CXX(target) Release/obj.target/pkcs11/src/dl.o
  CXX(target) Release/obj.target/pkcs11/src/const.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/error.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/v8_convert.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/template.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/mech.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/param.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/param_aes.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/param_rsa.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/param_ecdh.o
  CXX(target) Release/obj.target/pkcs11/src/pkcs11/pkcs11.o
  CXX(target) Release/obj.target/pkcs11/src/async.o
  CXX(target) Release/obj.target/pkcs11/src/node.o
  SOLINK_MODULE(target) Release/obj.target/pkcs11.node
  COPY Release/pkcs11.node
make: 离开目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/pkcs11js/build”

> [email protected] install /opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: 进入目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/websocket/build”
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node
  COPY Release/bufferutil.node
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/obj.target/validation.node
  COPY Release/validation.node
make: 离开目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/websocket/build”

> [email protected] install /opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library

[grpc] Success: "/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node" is installed via remote

> [email protected] install /opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/husky
> node ./bin/install.js

husky
setting up Git hooks
done

added 787 packages in 141.554s

npm install

接下来进入blockchain-explorer/cd app/test/ 目录下执行npm install下载对应的依赖模块:

[root@slave3 test]# npm install
npm WARN [email protected] No repository field.

added 413 packages in 61.059s

npm run test

紧接着还是在这个test目录下执行npm run test:

[root@slave3 test]# npm run test

> [email protected] test /opt/gopath/src/github.com/hyperledger/blockchain-explorer/app/test
> mocha *.js  --exit



  GET /api/blockAndTxList/:channel/:blocknum
    ✓ should return blockandtx 

  GET /api/blocksByHour/:channel/:day
    ✓ should return blockbyhour 

  GET /api/blocksByMinute/:channel/:hour
    ✓ should return blockbyminute 

  GET /api/block/transactions/:channel/:number
    ✓ should return currentchannel 

  GET /api/chaincode/:channel
    ✓ should return chaincode 

  GET /api/channels/info
    ✓ should return channelsinfo 

  GET /api/changeChannel/:channelName
    ✓ should return currentchannel 

  config.json should contain properties
    ✓ should contain configtxgenToolPath property
    ✓ should contain syncStartDate property

  getDefaultOrg()
    ✓ should return String Org
    ✓ should return same org

  getDefaultPeer()
peer0
    ✓ should return String peer
    ✓ should return same peer

  getOrgAdmin()
    ✓ should return admin obj

  GET /api/curChannel
    ✓ should return currentchannel 

  dateUtils().toUTCmilliseconds
    ✓ dateUtils.toUTCmilliseconds should be not null

  GET /api/peer/channel
    ✓ should return peers 

  Test explorerpg.sql for DDL statements syntax verification
    ✓ should read the file explorerpg.sql for ddl statements 
TAP version 13
# Test Results
ok 1 DROP USER IF EXISTS testuser;
# Test completed and Temporary database deleted
    ✓ should execute statements successfully in  explorerpg.sql file  (5026ms)

  GET /api/status
    ✓ should return channel status

  getLogger()
    ✓ should getLogger()

  GET /api/transaction/:channel/:id
    ✓ should return currentchannel 

  GET /api/txByHour/:channel/:day
    ✓ should return blockandtx 

  GET /api/txByMinute/:channel/:hour
    ✓ should return blockandtx  (40ms)

  GET /api/txByOrg/:channe
    ✓ should return blockandtx 


  25 passing (5s)


1..1
# tests 1
# pass  1

# ok

npm install

接下来进入blockchain-explorer/client目录,执行npm install下载相关依赖模块:

[root@slave3 client]# npm install

> [email protected] postinstall /opt/gopath/src/github.com/hyperledger/blockchain-explorer/client/node_modules/jss
> node -e "console.log('\u001b[35m\u001b[1mLove JSS? You can now support us on open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/jss/donate\u001b[0m')"

Love JSS? You can now support us on open collective:
 > https://opencollective.com/jss/donate

> [email protected] postinstall /opt/gopath/src/github.com/hyperledger/blockchain-explorer/client/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1652 packages in 378.708s

npm test -- u --coverage

在当前目录下执行npm test -- -u --coverage:

fabric1.1 搭建Hyperledger Explorer_第1张图片

报错了。。。。报错文件的路径和位置都给出来了,因此找到这个文件报错的代码位置,看到这段代码的意思是如果有未处理的rejection则结束脚本。因此先把这段代码注释掉,让脚本继续执行:

要注释的代码:

fabric1.1 搭建Hyperledger Explorer_第2张图片

注释掉之后再次执行 npm test -- -u --coverage:

[root@slave3 client]# npm test -- -u --coverage

> [email protected] test /opt/gopath/src/github.com/hyperledger/blockchain-explorer/client
> react-scripts test --env=jsdom "-u" "--coverage"

 PASS  src/state/redux/charts/tests.spec.js (6.024s)
 PASS  src/components/Lists/Blocks.spec.js (7.051s)
 PASS  src/components/Charts/ChartStats.spec.js
 PASS  src/components/Lists/Transactions.spec.js
 PASS  src/state/redux/tables/tests.spec.js
 PASS  src/components/Header/HeaderView.spec.js
 PASS  src/components/View/DashboardView.spec.js
 PASS  src/components/Lists/Chaincodes.spec.js
  ● Console

    console.error node_modules/@material-ui/core/node_modules/warning/warning.js:36
      Warning: Material-UI: the key `hash` provided to the classes property is not implemented in ChaincodeModal.
      You can only override one of the following: code,cubeIcon,source
    console.error node_modules/@material-ui/core/node_modules/warning/warning.js:36
      Warning: Material-UI: the key `hash` provided to the classes property is not implemented in ChaincodeModal.
      You can only override one of the following: code,cubeIcon,source

 PASS  src/components/Main.spec.js
 PASS  src/components/View/BlocksView.spec.js
 PASS  src/components/View/TransactionView.spec.js
 PASS  src/components/View/TransactionsView.spec.js
 PASS  src/components/Lists/TimelineStream.spec.js
 PASS  src/components/Lists/Peers.spec.js
 PASS  src/components/Lists/Channels.spec.js

 RUNS  src/components/View/LandingPage.spec.js
/opt/gopath/src/github.com/hyperledger/blockchain-explorer/client/node_modules/react-scripts/scripts/test.js:20
  throw err;
  ^

TypeError: getBlockActivity is not a function
    at LandingPage.componentDidMount (/opt/gopath/src/github.com/hyperledger/blockchain-explorer/client/src/components/View/LandingPage.js:136:5)
    at 
npm ERR! Test failed.  See above for more details.
[root@slave3 client]# ll
总用量 688
drwxr-xr-x 1189 root root  36864 4月   4 10:49 node_modules
-rw-r--r--    1 root root   3076 4月   4 10:27 package.json
-rw-r--r--    1 root root 516036 4月   4 10:27 package-lock.json
drwxr-xr-x    2 root root     64 4月   4 10:24 public
-rw-r--r--    1 root root 119291 4月   4 10:24 README.md
drwxr-xr-x    6 root root    177 4月   4 10:27 src
[root@slave3 client]# ll src/components/View/
总用量 112
-rw-r--r-- 1 root root 1002 4月   4 10:27 BlocksView.js
-rw-r--r-- 1 root root 4533 4月   4 10:27 BlocksView.spec.js
-rw-r--r-- 1 root root 4790 4月   4 10:27 BlockView.js
-rw-r--r-- 1 root root 2691 4月   4 10:27 ChaincodeModal.js
-rw-r--r-- 1 root root  740 4月   4 10:27 ChaincodeModal.spec.js
-rw-r--r-- 1 root root  440 4月   4 10:27 ChaincodeView.js
-rw-r--r-- 1 root root  674 4月   4 10:27 ChaincodeView.spec.js
-rw-r--r-- 1 root root  401 4月   4 10:27 ChannelsView.js
-rw-r--r-- 1 root root  722 4月   4 10:27 ChannelsView.spec.js
-rw-r--r-- 1 root root 8167 4月   4 10:27 DashboardView.js
-rw-r--r-- 1 root root 6246 4月   4 10:27 DashboardView.spec.js
-rw-r--r-- 1 root root 5880 4月   4 10:27 LandingPage.js
-rw-r--r-- 1 root root 2663 4月   4 10:27 LandingPage.spec.js
-rw-r--r-- 1 root root  389 4月   4 10:27 NetworkView.js
-rw-r--r-- 1 root root  429 4月   4 10:27 NetworkView.spec.js
-rw-r--r-- 1 root root 1293 4月   4 10:27 PageNotFound.js
-rw-r--r-- 1 root root 1371 4月   4 10:27 TransactionsView.js
-rw-r--r-- 1 root root 4266 4月   4 10:27 TransactionsView.spec.js
-rw-r--r-- 1 root root 7255 4月   4 10:27 TransactionView.js
-rw-r--r-- 1 root root 4456 4月   4 10:27 TransactionView.spec.js
[root@slave3 client]# npm test -- -u --coverage

> [email protected] test /opt/gopath/src/github.com/hyperledger/blockchain-explorer/client
> react-scripts test --env=jsdom "-u" "--coverage"

 PASS  src/state/redux/charts/tests.spec.js
 PASS  src/components/Lists/Blocks.spec.js
 PASS  src/components/Charts/ChartStats.spec.js
 PASS  src/components/Lists/Transactions.spec.js
 PASS  src/state/redux/tables/tests.spec.js
 PASS  src/components/Header/HeaderView.spec.js
 PASS  src/components/View/DashboardView.spec.js
 PASS  src/components/Lists/Chaincodes.spec.js
  ● Console

    console.error node_modules/@material-ui/core/node_modules/warning/warning.js:36
      Warning: Material-UI: the key `hash` provided to the classes property is not implemented in ChaincodeModal.
      You can only override one of the following: code,cubeIcon,source
    console.error node_modules/@material-ui/core/node_modules/warning/warning.js:36
      Warning: Material-UI: the key `hash` provided to the classes property is not implemented in ChaincodeModal.
      You can only override one of the following: code,cubeIcon,source

 PASS  src/components/Main.spec.js
 PASS  src/components/View/BlocksView.spec.js
 PASS  src/components/View/TransactionView.spec.js
 PASS  src/components/View/TransactionsView.spec.js
 PASS  src/components/Lists/TimelineStream.spec.js
 PASS  src/components/Lists/Peers.spec.js
 PASS  src/components/Lists/Channels.spec.js
(node:43432) UnhandledPromiseRejectionWarning: TypeError: getBlockActivity is not a function
(node:43432) 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:43432) [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.
 PASS  src/components/View/LandingPage.spec.js
 PASS  src/components/Charts/TimeChart.spec.js
 PASS  src/components/Panels/NotificationsPanel.spec.js
  ● Console

    console.error node_modules/fbjs/lib/warning.js:33
      Warning: Each child in an array or iterator should have a unique "key" prop.
      
      Check the top-level render call using . See https://fb.me/react-warning-keys for more information.
          in div (at NotificationsPanel.js:85)

 PASS  src/components/Charts/OrgPieChart.spec.js
 PASS  src/components/Lists/PeersHealth.spec.js
 PASS  src/components/App/App.spec.js (5.699s)
 PASS  src/components/View/ChaincodeModal.spec.js
 PASS  src/components/View/ChannelsView.spec.js
 PASS  src/components/View/ChaincodeView.spec.js
 PASS  src/components/View/NetworkView.spec.js
 PASS  src/components/Forms/ChannelForm.spec.js

Test Suites: 26 passed, 26 total
Tests:       171 passed, 171 total
Snapshots:   0 total
Time:        30.432s
Ran all test suites.
------------------------|----------|----------|----------|----------|-------------------|
File                    |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------|----------|----------|----------|----------|-------------------|
All files               |    70.13 |    37.28 |    68.93 |    72.29 |                   |
 src                    |      100 |      100 |      100 |      100 |                   |
  FabricVerison.js      |      100 |      100 |      100 |      100 |                   |
 src/components         |    53.57 |        0 |     8.33 |    53.57 |                   |
  ErrorMesage.js        |       50 |      100 |        0 |       50 |              6,18 |
  Main.js               |    54.17 |        0 |       10 |    54.17 |... 50,155,157,181 |
 src/components/App     |    52.17 |    33.33 |    28.57 |    63.16 |                   |
  App.js                |    66.67 |       50 |    33.33 |    66.67 | 19,20,21,45,49,77 |
  index.js              |        0 |        0 |        0 |        0 |                 1 |
 src/components/Charts  |    82.26 |    11.11 |    79.17 |    82.26 |                   |
  ChartStats.js         |    84.85 |    28.57 |       80 |    84.85 |   35,36,37,61,203 |
  OrgPieChart.js        |    86.36 |       10 |    85.71 |    86.36 |          13,14,15 |
  TimeChart.js          |    57.14 |        0 |       50 |    57.14 |          21,22,23 |
 src/components/Footer  |    28.57 |        0 |        0 |    28.57 |                   |
  FooterView.js         |    28.57 |        0 |        0 |    28.57 |    11,12,13,30,37 |
  index.js              |        0 |        0 |        0 |        0 |                   |
 src/components/Forms   |       80 |       50 |       75 |    77.78 |                   |
  ChaincodeForm.js      |      100 |       50 |      100 |      100 |       40,41,44,45 |
  ChannelForm.js        |       50 |      100 |       50 |    33.33 |             35,37 |
 src/components/Header  |    84.95 |       38 |    81.48 |    84.95 |                   |
  HeaderView.js         |    84.95 |       38 |    81.48 |    84.95 |... 78,351,352,566 |
  index.js              |        0 |        0 |        0 |        0 |                   |
 src/components/Lists   |    59.91 |    20.24 |    66.67 |    59.56 |                   |
  Blocks.js             |    52.81 |    23.91 |    62.22 |    52.27 |... 66,477,487,501 |
  Chaincodes.js         |    90.48 |      100 |    86.67 |    90.48 |             15,60 |
  Channels.js           |      100 |      100 |      100 |      100 |                   |
  Peers.js              |       75 |      100 |       60 |       75 |             40,52 |
  PeersHealth.js        |      100 |      100 |      100 |      100 |                   |
  TimelineStream.js     |    82.35 |        0 |     87.5 |    81.25 |          19,20,21 |
  Transactions.js       |    44.74 |       20 |       50 |    44.74 |... 60,371,381,395 |
 src/components/Panels  |    52.63 |    18.18 |     37.5 |    52.63 |                   |
  AdminPanel.js         |    14.29 |        0 |        0 |    14.29 |22,23,24,42,43,123 |
  NotificationsPanel.js |       75 |       25 |       75 |       75 |          17,18,19 |
 src/components/Styled  |    76.74 |    36.75 |    69.23 |    76.74 |                   |
  DatePicker.js         |      100 |       50 |      100 |      100 |    35,38,41,44,45 |
  Modal.js              |      100 |    54.17 |      100 |      100 |... 35,42,46,51,56 |
  MultiSelect.js        |      100 |       50 |      100 |      100 |... 33,36,39,43,46 |
  Select.js             |       25 |        0 |        0 |       25 | 12,13,14,61,62,63 |
  Table.js              |      100 |    59.09 |      100 |      100 |... 45,50,51,54,55 |
  View.js               |    33.33 |        0 |        0 |    33.33 |       10,11,12,33 |
 src/components/Theme   |        0 |        0 |        0 |        0 |                   |
  Theme.js              |        0 |        0 |        0 |        0 |... 31,32,41,58,60 |
  index.js              |        0 |        0 |        0 |        0 |                 1 |
 src/components/View    |    76.27 |    31.94 |    68.57 |    76.27 |                   |
  BlockView.js          |    63.64 |       50 |       60 |    63.64 |       24,25,31,34 |
  BlocksView.js         |      100 |      100 |      100 |      100 |                   |
  ChaincodeModal.js     |    84.62 |       50 |       75 |    84.62 |             48,49 |
  ChaincodeView.js      |      100 |      100 |      100 |      100 |                   |
  ChannelsView.js       |      100 |      100 |      100 |      100 |                   |
  DashboardView.js      |    81.48 |    23.91 |    85.71 |    81.48 |  23,24,25,122,165 |
  LandingPage.js        |    65.38 |       25 |       50 |    65.38 |... 42,143,149,212 |
  NetworkView.js        |      100 |      100 |      100 |      100 |                   |
  PageNotFound.js       |    33.33 |        0 |        0 |    33.33 |          6,7,8,37 |
  TransactionView.js    |    78.95 |    83.33 |    66.67 |    78.95 |     75,76,203,206 |
  TransactionsView.js   |      100 |      100 |      100 |      100 |                   |
 src/components/types   |      100 |      100 |      100 |      100 |                   |
  index.js              |      100 |      100 |      100 |      100 |                   |
 src/services           |    66.67 |      100 |       40 |    64.71 |                   |
  request.js            |    66.67 |      100 |       40 |    64.71 |   7,8,22,23,30,31 |
 src/state              |        0 |        0 |        0 |        0 |                   |
  store.js              |        0 |        0 |        0 |        0 |         1,9,10,12 |
 src/state/redux        |        0 |        0 |        0 |        0 |                   |
  index.js              |        0 |        0 |        0 |        0 |        1,5,6,7,11 |
 src/state/redux/charts |     84.4 |     67.9 |    90.36 |    84.32 |                   |
  actions.js            |    92.31 |      100 |    84.62 |      100 |                   |
  index.js              |        0 |        0 |        0 |        0 |                   |
  operations.js         |    72.82 |    45.45 |     91.3 |    70.33 |... 87,193,206,212 |
  reducers.js           |    96.08 |    94.59 |      100 |    96.08 |             28,95 |
  selectors.js          |    91.67 |      100 |    83.33 |      100 |                   |
  types.js              |      100 |      100 |      100 |      100 |                   |
 src/state/redux/tables |    81.43 |    70.83 |    78.57 |    81.67 |                   |
  actions.js            |     87.5 |      100 |       75 |      100 |                   |
  index.js              |        0 |        0 |        0 |        0 |                   |
  operations.js         |    68.75 |       50 |       75 |    67.86 |... 13,116,123,129 |
  reducers.js           |    94.12 |    91.67 |      100 |    94.12 |            28,118 |
  selectors.js          |     87.5 |      100 |       75 |    83.33 |             14,16 |
  types.js              |      100 |      100 |      100 |      100 |                   |
 src/state/redux/theme  |       50 |        0 |        0 |     62.5 |                   |
  actions.js            |       50 |      100 |        0 |      100 |                   |
  index.js              |        0 |        0 |        0 |        0 |                   |
  reducers.js           |       25 |        0 |        0 |       25 |           9,11,17 |
  selectors.js          |       50 |      100 |        0 |      100 |                   |
  types.js              |      100 |      100 |      100 |      100 |                   |
------------------------|----------|----------|----------|----------|-------------------|

npm run build

可以看到所有的测试都通过了。接下来运行 npm run build命令,这一步用时超长,我的虚拟机要一个半小时左右。。。

运行结果如下:

[root@slave3 client]# npm run build

> [email protected] build /opt/gopath/src/github.com/hyperledger/blockchain-explorer/client
> react-scripts build

Creating an optimized production build...

Compiled successfully.

File sizes after gzip:

  443.99 KB  build/static/js/main.901d226b.js
  37.62 KB   build/static/css/main.217e16aa.css

The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:

  "homepage" : "http://myname.github.io/myapp",

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  http://bit.ly/2vY88Kr

运行完会在当前目录下生成build和coverage两个文件夹:

fabric1.1 搭建Hyperledger Explorer_第3张图片

运行hyperledger-explorer

接下来就是最激动人心的时刻了,启动服务./start.sh,之后在Chrome浏览器打开网址http://xxx:8080即可看到页面(注意,在360浏览器可能会显示不出来):

fabric1.1 搭建Hyperledger Explorer_第4张图片

查看pg数据库,可以看到存储的channel、peer等信息:

postgres=# \l      #查看所有数据库
                                        数据库列表
      名称      |  拥有者  | 字元编码 |  校对规则   |    Ctype    |       存取权限        
----------------+----------+----------+-------------+-------------+-----------------------
 fabricexplorer | hppoc    | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 postgres       | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0      | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
                |          |          |             |             | postgres=CTc/postgres
 template1      | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
                |          |          |             |             | postgres=CTc/postgres
(4 行记录)

postgres=# \c fabricexplorer       #进入fabricexplorer数据库
您现在已经连接到数据库 "fabricexplorer",用户 "postgres".
fabricexplorer=# \d                #查看有哪些表
                        关联列表
 架构模式 |           名称            |  类型  | 拥有者 
----------+---------------------------+--------+--------
 public   | blocks                    | 数据表 | hppoc
 public   | blocks_id_seq             | 序列数 | hppoc
 public   | chaincodes                | 数据表 | hppoc
 public   | chaincodes_id_seq         | 序列数 | hppoc
 public   | channel                   | 数据表 | hppoc
 public   | channel_id_seq            | 序列数 | hppoc
 public   | orderer                   | 数据表 | hppoc
 public   | orderer_id_seq            | 序列数 | hppoc
 public   | peer                      | 数据表 | hppoc
 public   | peer_id_seq               | 序列数 | hppoc
 public   | peer_ref_chaincode        | 数据表 | hppoc
 public   | peer_ref_chaincode_id_seq | 序列数 | hppoc
 public   | peer_ref_channel          | 数据表 | hppoc
 public   | peer_ref_channel_id_seq   | 序列数 | hppoc
 public   | transactions              | 数据表 | hppoc
 public   | transactions_id_seq       | 序列数 | hppoc
 public   | write_lock                | 数据表 | hppoc
 public   | write_lock_write_lock_seq | 序列数 | hppoc
(18 行记录)

fabricexplorer=# select * from channel 
fabricexplorer-# 
fabricexplorer-# \g                 #查看channel表数据
 id |   name    | blocks | trans |      createdt       |                       channel_genesis_hash                       | channel_hash | channel_config | channel
_block | channel_tx | channel_version 
----+-----------+--------+-------+---------------------+------------------------------------------------------------------+--------------+----------------+--------
-------+------------+-----------------
  3 | mychannel |      1 |     1 | 2019-04-04 09:59:18 | 419f73669d2904199095e5d378845047d014ce94b1a0628c32d17648bc680218 |              |                |        
       |            | 
(1 行记录)

fabricexplorer=# select * from peer \g       #查看peer表数据
 id | org |                       channel_genesis_hash                       | mspid |          requests          | events |  server_hostname   | createdt | peer_t
ype 
----+-----+------------------------------------------------------------------+-------+----------------------------+--------+--------------------+----------+-------
----
  1 |     | 419f73669d2904199095e5d378845047d014ce94b1a0628c32d17648bc680218 |       | grpc://192.168.89.131:7051 |        | peer0.org1.scf.com |          | 
(1 行记录)

fabricexplorer=#

总结

不得不感慨一下,fabric坑很多,但这个hyperledger-explorer项目坑更多。前后弄了很久,身心俱疲。跟着网上的一些资料还是会出错。现在看来,关键问题是版本问题,我这里的fabric是1.1版本,匹配的explorer版本是3.5,npm之前是5.6.0,node是8.11.1,之导致一直报各种错。后来无意中看到blockchain-explorer/package.json文件中要求的node版本是8.11.2,npm版本是5.10.0,因此把版本修改后,成功了。

参考文献

官网文档:https://github.com/hyperledger/blockchain-explorer/tree/release-3.5

https://www.jianshu.com/p/58ade73fc68c

https://blog.csdn.net/baidu_37379451/article/details/81385068

g++: error trying to exec 'cc1plus': execvp: 没有那个文件或目录
make: *** [Release/obj.target/pkcs11/src/main.o] 错误 1
make: 离开目录“/opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/pkcs11js/build”
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/node-v8.11.2-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.20.12-1.el7.elrepo.x86_64
gyp ERR! command "/usr/local/node-v8.11.2-linux-x64/bin/node" "/usr/local/node-v8.11.2-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /opt/gopath/src/github.com/hyperledger/blockchain-explorer/node_modules/pkcs11js
gyp ERR! node -v v8.11.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-29T02_12_54_703Z-debug.log

 

你可能感兴趣的:(区块链,hyperleger,fabric)