Hyperledger Fabric入門1:快速上手

Hyperledger Fabric入門1:快速上手

jasonruan 2018.11.17

0. 前言

本文是自己學習超級賬本Fabric的第一篇文章,主要是體驗了下基本功能——快速搭建起網絡環境,并利用自帶sample,體會了一下鏈碼的部署與調用,為后續逐步深入其內部原理和鏈碼開發做一個鋪墊。

1. 名詞解釋

自己初學超級賬本Fabric,其眾多的術語確實弄得有些蒙圈,以下摘記部分術語。

術語 含義
Anchor Peer(錨節點) 通道中能被所有對等節點探測,并能與之進行通信的一種對等節點。
通道中的每個成員都有一個或多個錨節點,允許屬于不同身份的節點來發現通道中存在的其他節點。
Block(區塊) 區塊是一組有序的交易集合,在通道中經過哈希加密后與前序區塊連接。
Chaincode(鏈碼) 區塊鏈上的應用代碼,擴展自“智能合約”概念。
Channel(通道) Fabric 網絡上的私有隔離。通道中的鏈碼和交易只有加入該通道的節點可見。
Consensus (共識) 共識是貫穿整個交易流程, 對包含塊的一組交易的正確性的全面驗證。
Endorser(背書節點) 負責檢驗某個交易是否合法,是否愿意為之擔保、簽名。
Fabric-CA(證書節點) 默認的證書管理組件,它向網絡成員及其用戶頒發基于PKI的證書。
CA為每個成員頒發一個根證書,為沒有授權用戶頒發一個注冊證書,為每個注冊證書頒發大量交易證書。
Genesis Block(創世區塊) 是區塊鏈上的第一個區塊,是初始化區塊鏈網絡或通道的配置區塊
Ledger(賬本) 賬本是由通道中每個peer維護的數據庫。
MSP(Member Service Provider,成員服務提供者) 抽象的實現成員服務(身份驗證,證書管理等)的組件,實現對不同類型的成員服務的可拔插支持。
Orderer Peer(排序節點) 負責排序看到的交易,提供全局確認的順序。
Ordering Service(排序服務) 將交易排序放入block的節點的集合。排序服務獨立與peer流程之外,并以先到先服務的方式為網絡上所有的通道做交易排序。
State Database(狀態數據庫) 當前狀態數據存儲在狀態數據庫中,以便從chaincode進行有效讀取和查詢。這些數據庫包括levelDB和couchDB。
Transaction(交易) 執行賬本上的某個函數調用或者部署 chaincode。調用的具體函數在 chaincode 中實現。
Validating Peer(驗證節點) 維護賬本的核心節點,參與一致性維護、對交易的驗證和執行。
World State(世界狀態) 即最新的全局賬本狀態。Fabric 用它來存儲歷史交易發生后產生的最新的狀態,可以用鍵值或文檔數據庫實現。

2. 環境搭建

2.1 前置依賴

省略具體安裝步驟

  • ubuntu 18.04

  • go 1.11.2

  • docker-ce 18.09

  • docker-compose 1.23.1

2.2 fabric下載

下載地址:https://github.com/hyperledger/fabric

$ git clone https://github.com/hyperledger/fabric.git
Cloning into 'fabric'...
remote: Enumerating objects: 183, done.
remote: Counting objects: 100% (183/183), done.
remote: Compressing objects: 100% (164/164), done.
remote: Total 81151 (delta 64), reused 135 (delta 18), pack-reused 80968
Receiving objects: 100% (81151/81151), 77.50 MiB | 440.00 KiB/s, done.
Resolving deltas: 100% (51831/51831), done.

2.3 fabric安裝

步驟:

  • 進入clone好的源碼目錄fabric/scripts

  • 執行bootstrap.sh腳本,該腳本將執行如下操作:

    首先是安裝fabric-samples

    (1)下載hyperledger/fabric-samples

    Installing hyperledger/fabric-samples repo
    ===> Cloning hyperledger/fabric-samples repo and checkout v1.3.0
    

    (2)下載當前平臺的fabric二進制包

    ===> Downloading version 1.3.0 platform specific fabric binaries
    ===> Downloading:  https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.3.0/hyperledger-fabric-linux-amd64-1.3.0.tar.gz
    

    (3)下載當前平臺的CA客戶端

    ===> Downloading version 1.3.0 platform specific fabric-ca-client binary
    ===> Downloading:  https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.3.0/hyperledger-fabric-ca-linux-amd64-1.3.0.tar.gz
    

    接下來拉取fabric鏡像

    (4)peer節點鏡像

    ==> FABRIC IMAGE: peer
    1.3.0: Pulling from hyperledger/fabric-peer
    Digest: sha256:6756c7c48234ae6b0a8822a378681017cf6dbfeadfbf1f8a528ee6c4db343621
    Status: Image is up to date for hyperledger/fabric-peer:1.3.0
    

    (5)排序節點鏡像

    ==> FABRIC IMAGE: orderer
    1.3.0: Pulling from hyperledger/fabric-orderer
    Digest: sha256:6ee1abcfd84031765d67544e5d6b4f3af08c3f064312c65715587d392fe7c3eb
    Status: Image is up to date for hyperledger/fabric-orderer:1.3.0
    

    (6)CC環境鏡像

    ==> FABRIC IMAGE: ccenv
    1.3.0: Pulling from hyperledger/fabric-ccenv
    Digest: sha256:05fce5513fcae3110ac041469ed9e0e4c9661f44782f52ef5d8930eb416c2197
    Status: Image is up to date for hyperledger/fabric-ccenv:1.3.0
    

    (7)工具鏡像

    ==> FABRIC IMAGE: tools
    1.3.0: Pulling from hyperledger/fabric-tools
    Digest: sha256:058cff3b378c1f3ebe35d56deb7bf33171bf19b327d91b452991509b8e9c7870
    Status: Image is up to date for hyperledger/fabric-tools:1.3.0
    

    下面拉取fabric CA鏡像

    (8)CA鏡像

    ==> FABRIC CA IMAGE
    1.3.0: Pulling from hyperledger/fabric-ca
    Digest: sha256:83abc367c5273a12d59ef9777637eb6c1abf04a5d00d66a0bffc55c40075850e
    Status: Image is up to date for hyperledger/fabric-ca:1.3.0
    

    最后拉取第三方docker鏡像

    (9)couchdb鏡像

    ==> THIRDPARTY DOCKER IMAGE: couchdb
    0.4.13: Pulling from hyperledger/fabric-couchdb
    Digest: sha256:b26dfcf9abb466ffb60d0734d0c5c3bf1d4816c96e944ba69584d94681028cfd
    Status: Image is up to date for hyperledger/fabric-couchdb:0.4.13
    

    (10)kafka鏡像

    ==> THIRDPARTY DOCKER IMAGE: kafka
    0.4.13: Pulling from hyperledger/fabric-kafka
    Digest: sha256:7caa31210504bc99ae45d19d528671f238d25418d9433c42f8c582ba415703b4
    Status: Image is up to date for hyperledger/fabric-kafka:0.4.13
    

    (11)zookeeper鏡像

    ==> THIRDPARTY DOCKER IMAGE: zookeeper
    0.4.13: Pulling from hyperledger/fabric-zookeeper
    Digest: sha256:9fdff6aa2c086816ad693339c25f1e49ea4a0b6b7102c7342aff4137991a15a1
    Status: Image is up to date for hyperledger/fabric-zookeeper:0.4.13
    

    鏡像拉取完畢后,列出鏡像清單

    ===> List out hyperledger docker images                                       
    hyperledger/fabric-ca         1.3.0         5c6b20ba944f    4 weeks ago   244MB  
    hyperledger/fabric-ca         latest        5c6b20ba944f    4 weeks ago   244MB
    hyperledger/fabric-tools      1.3.0         c056cd9890e7    4 weeks ago   1.5GB
    hyperledger/fabric-tools      latest        c056cd9890e7    4 weeks ago   1.5GB
    hyperledger/fabric-ccenv      1.3.0         953124d80237    4 weeks ago   1.38GB
    hyperledger/fabric-ccenv      latest        953124d80237    4 weeks ago   1.38GB
    hyperledger/fabric-orderer    1.3.0         f430f581b46b    4 weeks ago   145MB
    hyperledger/fabric-orderer    latest        f430f581b46b    4 weeks ago   145MB
    hyperledger/fabric-peer       1.3.0         f3ea63abddaa    4 weeks ago   151MB
    hyperledger/fabric-peer       latest        f3ea63abddaa    4 weeks ago   151MB
    hyperledger/fabric-zookeeper  0.4.13        e62e0af39193    4 weeks ago   1.39GB
    hyperledger/fabric-zookeeper  latest        e62e0af39193    4 weeks ago   1.39GB
    hyperledger/fabric-kafka      0.4.13        4121ea662c47    4 weeks ago   1.4GB
    hyperledger/fabric-kafka      latest        4121ea662c47    4 weeks ago   1.4GB
    hyperledger/fabric-couchdb    0.4.13        1d3266e01e64    4 weeks ago   1.45GB
    hyperledger/fabric-couchdb    latest        1d3266e01e64    4 weeks ago   1.45GB
    hyperledger/fabric-baseos     amd64-0.4.13  f0fe49196c40    4 weeks ago   124MB
    

3. 構建網絡

下面基于fabric-samples提供的BYFN(build your first network),來快速的構建我們第一個超級賬本fabric網絡,以此來熟悉整個運行過程。

3.1 生成配置

3.1.1 執行命令

進入到:fabric/scripts/fabric-samples/first-network/,執行命令:

$ sudo ./byfn.sh -m generate -c jschannel

3.1.2 命令說明

  • 這條命令也可以不用執行,在使用up命令啟動網絡時,若發現未生成所需配置,會自動進行執行。

  • 該條命令將根據配置文件(crypto-config.yaml)生成初始化配置,包含Peer節點、排序服務節點的MSP證書

    # crypto-config.yaml
    OrdererOrgs:
      - Name: Orderer
        Domain: example.com
        Specs:
          - Hostname: orderer
    PeerOrgs:
      - Name: Org1
        Domain: org1.example.com
        EnableNodeOUs: true
        Template:
          Count: 2
        Users:
          Count: 1
      - Name: Org2
        Domain: org2.example.com
        EnableNodeOUs: true
        Template:
          Count: 2
        Users:
          Count: 1
    
  • 根據配置文件configtx.yaml生成創世區塊等

    # configtx.yaml
    Organizations:
        - &OrdererOrg
            Name: OrdererOrg
            ID: OrdererMSP
            MSPDir: crypto-config/ordererOrganizations/example.com/msp
            Policies:
              ......
        - &Org1
            Name: Org1MSP
            ID: Org1MSP
            MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
            Policies:
                Readers:
                    ......
            AnchorPeers:
                - Host: peer0.org1.example.com
                  Port: 7051
        - &Org2
              ......
    Capabilities:
        ......
    Application: &ApplicationDefaults
        Organizations:
        Policies:
            ......
    Orderer: &OrdererDefaults
        OrdererType: solo
        Addresses:
            - orderer.example.com:7050
        BatchTimeout: 2s
        BatchSize:
            ......
        Kafka:
            Brokers:
                - 127.0.0.1:9092
        Organizations:
        Policies:
            ......
    Channel: &ChannelDefaults
        ......
        Capabilities:
            <<: *ChannelCapabilities
    Profiles:
        ......
    

3.1.3 步驟說明

(1)生成證書

使用cryptogen工具為組織org1和org2生成MSP證書,MSP證書是超級賬本網絡實體的身份標識,實體在通信和交易時,使用證書進行簽名和驗證。成功執行后,證書文件將會放到crypto-config目錄中。

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
(2)創建創世塊

為排序服務生成創世區塊,成功執行后,會在channel-artifacts目錄下生成創世區塊文件:genesis.block

##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
+ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
(3)創建通道

生成通道配置文件channel.tx,成功執行后,會在channel-artifacts目錄下生成通道配置channel.tx

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID jschannel
(4)生成錨節點配置

生成Org1MSPOrg2MSP的錨節點配置,成功執行后,生成的錨點配置文件Org1MSPanchors.txOrg2MSPanchors.tx同樣位于目錄channel-artifacts中。

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID jschannel -asOrg Org1MSP

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID jschannel -asOrg Org2MSP

3.1.4 配置輸出

綜上,命令執行完后,將會在當前目錄生成兩個文件夾,內容分別如下:

  • 創世區塊目錄(channel-artifacts
$ tree channel-artifacts/
channel-artifacts/
├── channel.tx                          # 通道配置創世區塊
├── genesis.block                       # 排序服務創世區塊
├── Org1MSPanchors.tx                   # Org1錨節點配置
└── Org2MSPanchors.tx                   # Org2錨節點配置
  • 證書目錄(crypto-config

    該目錄存放生成排序服務節點和Peer節點的MSP證書文件

$ tree crypto-config
crypto-config
├── ordererOrganizations
│   └── example.com
│       ├── ca
│       │   ├── 2b749470c3d6cae6d63caa7b69ee9ebbc310ca68526521e444012f186e97bd92_sk
│       │   └── ca.example.com-cert.pem
│       ├── msp
│       │   ├── admincerts
│       │   │   └── Admin@example.com-cert.pem
│       │   ├── cacerts
│       │   │   └── ca.example.com-cert.pem
│       │   └── tlscacerts
│       │       └── tlsca.example.com-cert.pem
│       ├── orderers
│       │   └── orderer.example.com
│       │       ├── msp
│       │       └── tls
│       │           ├── ca.crt
│       │           ├── server.crt
│       │           └── server.key
│       ├── tlsca
│       │   ├── c79b35c1154c5377923a77dfa6036707652715671e2b1450e6313b64a65f238e_sk
│       │   └── tlsca.example.com-cert.pem
│       └── users
│           └── Admin@example.com
│               ├── msp
└── peerOrganizations
    ├── org1.example.com
    │   ├── ca
    │   ├── msp
    │   ├── peers
    │   ├── tlsca
    │   └── users
    └── org2.example.com

3.2 啟動網絡

3.2.1 執行命令

$ sudo ./byfn.sh -m up -c jschannel

3.2.2 命令說明

  • 執行該命令后,首先會根據docker-compose-cli.yaml配置文件啟動超級賬本fabric網絡

  • 其中包含了1個排序服務節點、4個Peer節點,以及1個命令行容器cli

    # docker-compose-cli.yaml 
    services:
      orderer.example.com:
        extends:
          file:   base/docker-compose-base.yaml
          service: orderer.example.com
        container_name: orderer.example.com
        networks:
          - byfn
    
      peer0.org1.example.com:
        container_name: peer0.org1.example.com
        extends:
          file:  base/docker-compose-base.yaml
          service: peer0.org1.example.com
        networks:
          - byfn
    
      peer1.org1.example.com:
      ......
    
      peer0.org2.example.com:
        container_name: peer0.org2.example.com
        extends:
          file:  base/docker-compose-base.yaml
          service: peer0.org2.example.com
        networks:
          - byfn
    
      peer1.org2.example.com:
      ......
    
      cli:
        container_name: cli
        image: hyperledger/fabric-tools:$IMAGE_TAG
        tty: true
        stdin_open: true
        environment:
          ......
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
        command: /bin/bash
        volumes:
            - ./../chaincode/:/opt/gopath/src/github.com/chaincode
            - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
          ......
        depends_on:
          - orderer.example.com
          - peer0.org1.example.com
          - peer1.org1.example.com
          - peer0.org2.example.com
          - peer1.org2.example.com
        networks:
          - byfn
    

3.2.3 命令輸出

看到下面信息,表明超級賬本Fabric網絡已經啟動完畢。

  Creating network "net_byfn" with the default driver
  Creating volume "net_orderer.example.com" with default driver
  Creating volume "net_peer0.org1.example.com" with default driver
  Creating volume "net_peer1.org1.example.com" with default driver
  Creating volume "net_peer0.org2.example.com" with default driver
  Creating volume "net_peer1.org2.example.com" with default driver
  Creating peer1.org2.example.com ... done
  Creating orderer.example.com    ... done
  Creating peer1.org1.example.com ... done
  Creating peer0.org2.example.com ... done
  Creating peer0.org1.example.com ... done
  Creating cli                    ... done

3.2.4 查看容器

使用docker ps命令查看容器啟動情況

$ sudo docker ps                                                      
CONTAINER ID IMAGE                             COMMAND            PORTS                                              NAMES
c32c37c5742f hyperledger/fabric-tools:latest   "/bin/bash"                                                           cli                         
dadda8aff9ae hyperledger/fabric-peer:latest    "peer node start"  0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
f35e303b931d hyperledger/fabric-peer:latest    "peer node start"  0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
5bf8fdf0f804 hyperledger/fabric-peer:latest    "peer node start"  0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.example.com
48c9b04f48db hyperledger/fabric-peer:latest    "peer node start"  0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
023b2fed2737 hyperledger/fabric-orderer:latest "orderer"          0.0.0.0:7050->7050/tcp                             orderer.example.com

3.3 鏈碼調用

3.3.1 執行命令

啟動網絡使用的$ sudo ./byfn.sh -m up -c jschannel中,啟動的cli容器會調用scripts/script.sh腳本,該腳本會進行通道創建、Peer節點加入通道、安裝和實例化鏈碼等,并進行鏈碼的調用和查詢。下面我們對命令進行進一步的說明。

3.3.2 命令說明

scripts/script.sh中執行的具體命令如下,每個命令都對應一個shell腳本函數

## Create channel                                     
createChannel
 
## Join all the peers to the channel
joinChannel
 
## Set the anchor peers for each org in the channel
updateAnchorPeers 0 1 
updateAnchorPeers 0 2 
 
## Install chaincode on peer0.org1 and peer0.org2
installChaincode 0 1 
installChaincode 0 2 
 
# Instantiate chaincode on peer0.org2
instantiateChaincode 0 2 
 
# Query chaincode on peer0.org1
chaincodeQuery 0 1 100 
 
# Invoke chaincode on peer0.org1 and peer0.org2
chaincodeInvoke 0 1 0 2 
 
## Install chaincode on peer1.org2
installChaincode 1 2 
 
# Query on chaincode on peer1.org2, check if the result is 90
chaincodeQuery 1 2 90

3.3.3 步驟說明

(1)創建通道

進入cli容器,執行創建通道命令。成功執行后,將在cli容器的當前路徑下生成通道配置jschannel.block,加入通道操作時需要使用。

Channel name : jschannel
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c jschannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
===================== Channel 'mychannel' created =====================
(2)4個peer節點依次加入通道

通過在cli容器中設置不同的環境變量,設置連接的Peer節點和MSP等,依次將4個Peer節點加入通道

+ peer channel join -b jschannel.block
Having all peers join the channel...
===================== peer0.org1 joined channel 'jschannel' ===================== 
+ peer channel join -b jschannel.block
===================== peer1.org1 joined channel 'jschannel' ===================== 
+ peer channel join -b jschannel.block
===================== peer0.org2 joined channel 'jschannel' ===================== 
+ peer channel join -b jschannel.block
===================== peer1.org2 joined channel 'jschannel' ===================== 
(3)更新組織的錨節點
Updating anchor peers for org1...
+ peer channel update -o orderer.example.com:7050 -c jschannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile 
========= Anchor peers updated for org 'Org1MSP' on channel 'jschannel' ========= 

Updating anchor peers for org2...
+ peer channel update -o orderer.example.com:7050 -c jschannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile 
========== Anchor peers updated for org 'Org2MSP' on channel 'jschannel' ========== 
(4)在Peer節點(peer0.org1peer0.org2)上安裝鏈碼

應用程序通過鏈碼執行智能合約的功能,需要先在Peer節點上安裝鏈碼,然后在通道上實例化鏈碼

Installing chaincode on peer0.org1...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
===================== Chaincode is installed on peer0.org1 ===================== 

Install chaincode on peer0.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
===================== Chaincode is installed on peer0.org2 ===================== 
(5)在Peer節點(peer0.org2)上實例化鏈碼

實例化鏈碼只需要執行一次,這條命令比較復雜,-c:指定初始化參數;-P:指定了背書策略,鏈碼的每個交易需要由Org1MSPOrg2MSP兩個組織都進行背書簽名,才能通過背書策略,繼續進入后續交易流程。成功執行后,會啟動鏈碼容器mycc

Instantiating chaincode on peer0.org2...
+ peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C jschannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
========= Chaincode is instantiated on peer0.org2 on channel 'jschannel' ========= 
(6)在Peer節點(peer0.org1)上執行鏈碼查詢a的值
Querying chaincode on peer0.org1...
========== Querying on peer0.org1 on channel 'jschannel'... ========== 
+ peer chaincode query -C jschannel -n mycc -c '{"Args":["query","a"]}'

100
========== Query successful on peer0.org1 on channel 'jschannel' ==========
(7)在Peer節點(peer0.org1)調用鏈碼,從a轉10到b
Sending invoke transaction on peer0.org1 peer0.org2...
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C jschannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'

==== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'jschannel' ====
(8)在Peer節點(peer1.org2)安裝鏈碼
Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
===================== Chaincode is installed on peer1.org2 ===================== 
(9)在Peer節點(peer1.org2)執行鏈碼查詢a的值
Querying chaincode on peer1.org2...
========== Querying on peer1.org2 on channel 'jschannel'... ========== 
+ peer chaincode query -C jschannel -n mycc -c '{"Args":["query","a"]}'

90
========= Query successful on peer1.org2 on channel 'jschannel' ========= 
========= All GOOD, BYFN execution completed =========== 

3.4 關閉網絡

3.4.1 執行命令

測試完成后,使用如下命令,關閉網絡

$ sudo ./byfn.sh -m down

4. 總結

本文通過分解的方式,逐步介紹了搭建超級賬本Fabric網絡的基本過程以及鏈碼部署和調用的方法,在理解和掌握了最基本的步驟后,也為后續自己深入學習超級賬本的原理和開發更為復雜的鏈碼應用打下基礎。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容