• VMware 中 Centos7 安装 Hyperledge Fabric v2.4.4 测试网络


    0、安装环境

    虚拟机:VMware Workstation 15 Pro

    虚拟机安装的操作系统:Centos7

    前提条件:

    (1)安装Git 参考 Centos7 安装 git_瘦身小蚂蚁的博客-CSDN博客_centos7 安装git

    (2)安装Go 1.18.2+  参考 Centos7 安装 Go_瘦身小蚂蚁的博客-CSDN博客_centos7安装go

    (3)安装Docker 参考 Centos7 安装 Docker_瘦身小蚂蚁的博客-CSDN博客

    (4)安装Docker-Compose 参考 Centos7 安装 Docker Compose_瘦身小蚂蚁的博客-CSDN博客

    (5)安装Nodejs 16.17.0  参考 安装 Nodejs (CentOS7 与 Windows)_瘦身小蚂蚁的博客-CSDN博客

    (6)安装JQ命令 参考 Centos7 安装完需要安装相关命令_瘦身小蚂蚁的博客-CSDN博客_centos7 安装命令

    1、下载Fabric(版本2.4.4)

    创建并进入Fabric目录

    1. mkdir -p $GOPATH/src/github.com/hyperledger # 创建下载目录

    2. cd $GOPATH/src/github.com/hyperledger #进入目录

    1. [root@localhost ~]# mkdir -p $GOPATH/src/github.com/hyperledger # 创建下载目录
    2. [root@localhost ~]# cd $GOPATH/src/github.com/hyperledger #进入目录

    官网提供的下载命令:

    curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh

    若下载命令正常执行,忽略下面步骤。若不能正常执行,则执行下面步骤:

    链接地址有时并不能有效的访问,即便能够访问,在执行命令时也会出现长时间没有反应,最终报错的问题。因此可以分析一下脚本,直接下载脚本中的文件。如脚本访问不了,可参见 HyperlegerFabric2.4.4安装下载示例时使用的脚本install-fabric.sh-Dapp文档类资源-CSDN下载

    将脚本文件install-fabric.sh下载,在下面第(4)步使用。

    (0)使用install-fabric.sh脚本下载组件

    可以通过install-fabric.sh脚本指定下载的组件

    docker    使用docker下载Fabric镜像(以下第(4)步使用)

    podman  使用podman下载Fabric镜像

    binary     下载Fabric二进制文件

    samples 下载fabric-samples示例

    示例:

    ./install-fabric.sh docker samples

    ./install-fabric.sh d s

    (1)下载fabric-sample

    使用git下载fabric-sample

    git clone -b main https://github.com/hyperledger/fabric-samples.git 

    1. [root@localhost hyperledger]# git clone -b main https://github.com/hyperledger/fabric-samples.git
    2. Cloning into 'fabric-samples'...
    3. remote: Enumerating objects: 10734, done.
    4. remote: Counting objects: 100% (75/75), done.
    5. remote: Compressing objects: 100% (64/64), done.
    6. remote: Total 10734 (delta 18), reused 52 (delta 9), pack-reused 10659
    7. Receiving objects: 100% (10734/10734), 19.14 MiB | 992.00 KiB/s, done.
    8. Resolving deltas: 100% (5769/5769), done.

    若多次执行报错后,可直接在windows中下载,然后上传到centos7对应的目录下。下载地址:GitHub - hyperledger/fabric-samples

    (2)下载并解压fabric二进制文件(版本2.4.4)

    下载fabric二进制文件

    使用wget报错,直接在windows下载,然后上传到centos7中解压。下载地址为:https://github.com/hyperledger/fabric/releases/download/v2.4.4/hyperledger-fabric-linux-amd64-2.4.4.tar.gz

    若github下载不了,可参见: 下载Fabric2.4.4二进制文件-Dapp文档类资源-CSDN下载

    解压fabric二进制文件

    将文件解压到fabric-sample目录中

    tar -zxvf hyperledger-fabric-linux-amd64-2.4.4.tar.gz -C fabric-samples/

    1. [root@localhost hyperledger]# tar -zxvf hyperledger-fabric-linux-amd64-2.4.4.tar.gz -C fabric-samples/
    2. bin/
    3. bin/peer
    4. bin/configtxlator
    5. bin/configtxgen
    6. bin/ledgerutil
    7. bin/ccaas_builder/
    8. bin/ccaas_builder/bin/
    9. bin/ccaas_builder/bin/build
    10. bin/ccaas_builder/bin/release
    11. bin/ccaas_builder/bin/detect
    12. bin/orderer
    13. bin/cryptogen
    14. bin/discover
    15. bin/osnadmin
    16. config/
    17. config/core.yaml
    18. config/orderer.yaml
    19. config/configtx.yaml

    (3)下载并解压fabric-ca二进制文件(版本1.5.5)

    下载fabric-ca二进制文件

    使用wget报错,直接在windows下载,然后上传到centos7中解压。下载地址为:https://github.com/hyperledger/fabric-ca/releases/download/v1.5.5/hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz

    若github下载不了,可参见: 下载Fabric2.4.4二进制文件fabric-ca-Dapp文档类资源-CSDN下载

    解压fabric-ca二进制文件

    将文件解压到fabric-sample目录中

    tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz -C fabric-samples/

    1. [root@localhost hyperledger]# tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz -C fabric-samples/
    2. bin/
    3. bin/fabric-ca-client
    4. bin/fabric-ca-server

    前3步都配置完成后,目录结构如下图所示:

    查看 fabric-sample/bin目录: 

     

    查看 fabric-sample/config 目录:

     

    (4)下载docker镜像

    1.4.1、执行脚本下载docker镜像

    通过执行install-fabric.sh脚本(参数为“docker”),下载docker镜像,若有下载失败的镜像,执行步骤1.4.2,否则执行步骤1.4.4:

    ./install-fabric.sh docker

    1. [root@localhost hyperledger]# ./install-fabric.sh docker
    2. Pull Hyperledger Fabric docker images
    3. FABRIC_IMAGES: peer orderer ccenv tools baseos
    4. ===> Pulling fabric Images
    5. ====> hyperledger/fabric-peer:2.4.4
    6. 2.4.4: Pulling from hyperledger/fabric-peer
    7. 2408cc74d12b: Already exists
    8. 6a3ced7e221e: Pull complete
    9. b9ff1df31cf9: Pull complete
    10. 78b77eac19b1: Pull complete
    11. 048204d9f4c2: Pull complete
    12. f4fcec0334ed: Pull complete
    13. cb845d51199e: Pull complete
    14. Digest: sha256:cb670c569d442dd42bab9d7fdb8cca8ae6e07326187e671d3d8041520fceac41
    15. Status: Downloaded newer image for hyperledger/fabric-peer:2.4.4
    16. docker.io/hyperledger/fabric-peer:2.4.4
    17. ====> hyperledger/fabric-orderer:2.4.4
    18. Error response from daemon: Get "https://registry-1.docker.io/v2/hyperledger/fabric-orderer/manifests/sha256:2a12c6789745c099dc91e7c10c35e6bee7dbfd7b80009fa4c876a7a9cd342bb5": net/http: TLS handshake timeout
    19. Error response from daemon: No such image: hyperledger/fabric-orderer:2.4.4
    20. Error response from daemon: No such image: hyperledger/fabric-orderer:2.4.4
    21. ====> hyperledger/fabric-ccenv:2.4.4
    22. 2.4.4: Pulling from hyperledger/fabric-ccenv
    23. 2408cc74d12b: Already exists
    24. ea60b727a1ce: Already exists
    25. 30c4a7721957: Already exists
    26. 4a5a11f84e29: Already exists
    27. 7f0c29549d1e: Already exists
    28. 1d4cfebdfd72: Pull complete
    29. 2310b28b5cf4: Pull complete
    30. abc5b52e1631: Pull complete
    31. cab5a0b0a76d: Pull complete
    32. Digest: sha256:39f4df6cb59f596f0511b13ad9a12e0b4e805012194b9406054a14a3c9b30668
    33. Status: Downloaded newer image for hyperledger/fabric-ccenv:2.4.4
    34. docker.io/hyperledger/fabric-ccenv:2.4.4
    35. ====> hyperledger/fabric-tools:2.4.4
    36. 2.4.4: Pulling from hyperledger/fabric-tools
    37. Digest: sha256:fbb12c6e1edc760188cb9057ad68abfa3192a4a6e832dfd0b1ddfa284d28f517
    38. Status: Image is up to date for hyperledger/fabric-tools:2.4.4
    39. docker.io/hyperledger/fabric-tools:2.4.4
    40. ====> hyperledger/fabric-baseos:2.4.4
    41. Error response from daemon: Get "https://registry-1.docker.io/v2/hyperledger/fabric-baseos/manifests/sha256:7d57d726fecf14b4cbe15ce16fcc8c6890d6d0af9337210aa597e4f0ea65485b": net/http: TLS handshake timeout
    42. Error response from daemon: No such image: hyperledger/fabric-baseos:2.4.4
    43. Error response from daemon: No such image: hyperledger/fabric-baseos:2.4.4
    44. ===> Pulling fabric ca Image
    45. ====> hyperledger/fabric-ca:1.5.5
    46. 1.5.5: Pulling from hyperledger/fabric-ca
    47. Digest: sha256:f93cd9f32702c3a6b9cb305d75bed5edd884cae0674374fd7c26467bf6a0ed9b
    48. Status: Image is up to date for hyperledger/fabric-ca:1.5.5
    49. docker.io/hyperledger/fabric-ca:1.5.5
    50. ===> List out hyperledger images
    51. hyperledger/fabric-ca 1.5 93f19fa873cb 5 weeks ago 76.5MB
    52. hyperledger/fabric-ca 1.5.5 93f19fa873cb 5 weeks ago 76.5MB
    53. hyperledger/fabric-ca latest 93f19fa873cb 5 weeks ago 76.5MB
    54. hyperledger/fabric-tools 2.4 d2f5f013cf70 8 weeks ago 489MB
    55. hyperledger/fabric-tools 2.4.4 d2f5f013cf70 8 weeks ago 489MB
    56. hyperledger/fabric-tools latest d2f5f013cf70 8 weeks ago 489MB
    57. hyperledger/fabric-peer 2.4 080114f6c98f 8 weeks ago 64.2MB
    58. hyperledger/fabric-peer 2.4.4 080114f6c98f 8 weeks ago 64.2MB
    59. hyperledger/fabric-peer latest 080114f6c98f 8 weeks ago 64.2MB
    60. hyperledger/fabric-ccenv 2.4 b01eeb054e4c 8 weeks ago 520MB
    61. hyperledger/fabric-ccenv 2.4.4 b01eeb054e4c 8 weeks ago 520MB
    62. hyperledger/fabric-ccenv latest b01eeb054e4c 8 weeks ago 520MB

    1.4.2、单独下载失败的镜像

    由于网络原因,以上有2个docker镜像下载失败,hyperledger/fabric-orderer:2.4.4 与 hyperledger/fabric-baseos:2.4.4,多次执行命令,仍然下载失败,可单独下载失败的镜像,如果仍然失败,多执行几次:(注:每次下载时失败的镜像不同,查看下载失败的镜像使用docker命令单独下载。)

    docker pull hyperledger/fabric-orderer:2.4.4

    docker pull hyperledger/fabric-baseos:2.4.4

    1. # 失败
    2. [root@localhost hyperledger]# docker pull hyperledger/fabric-orderer:2.4.4
    3. Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-orderer/manifests/2.4.4": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-orderer%3Apull&service=registry.docker.io": net/http: TLS handshake timeout
    4. # 失败
    5. [root@localhost hyperledger]# docker pull hyperledger/fabric-orderer:2.4.4
    6. Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: TLS handshake timeout
    7. # 成功
    8. [root@localhost hyperledger]# docker pull hyperledger/fabric-orderer:2.4.4
    9. 2.4.4: Pulling from hyperledger/fabric-orderer
    10. 2408cc74d12b: Already exists
    11. 6a3ced7e221e: Already exists
    12. b9a3d5e52036: Pull complete
    13. 02f61468e2f2: Pull complete
    14. 7e7e888d9eab: Pull complete
    15. b3ea10b79973: Pull complete
    16. f7cb240941e7: Pull complete
    17. Digest: sha256:2a12c6789745c099dc91e7c10c35e6bee7dbfd7b80009fa4c876a7a9cd342bb5
    18. Status: Downloaded newer image for hyperledger/fabric-orderer:2.4.4
    19. docker.io/hyperledger/fabric-orderer:2.4.4
    20. # 成功
    21. [root@localhost hyperledger]# docker pull hyperledger/fabric-baseos:2.4.4
    22. 2.4.4: Pulling from hyperledger/fabric-baseos
    23. 2408cc74d12b: Already exists
    24. 6a3ced7e221e: Already exists
    25. 5dec8747365f: Pull complete
    26. Digest: sha256:7d57d726fecf14b4cbe15ce16fcc8c6890d6d0af9337210aa597e4f0ea65485b
    27. Status: Downloaded newer image for hyperledger/fabric-baseos:2.4.4
    28. docker.io/hyperledger/fabric-baseos:2.4.4

    1.4.3、再次install-fabric.sh脚本

    若有单独下载的镜像,即执行了上面的docker pull命令,则再次执行下 install-fabric.sh 脚本,此次忽略下载失败的提示,因为所有镜像在上面步骤中都已下载完成了,为的是执行docker tag命令(可参见install-fabric.sh脚本)。

    ./install-fabric.sh docker

    1. [root@localhost hyperledger]# ./install-fabric.sh docker
    2. Pull Hyperledger Fabric docker images
    3. FABRIC_IMAGES: peer orderer ccenv tools baseos
    4. ===> Pulling fabric Images
    5. ====> hyperledger/fabric-peer:2.4.4
    6. Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-peer/manifests/2.4.4": read tcp 192.168.237.150:42142->44.194.5.25:443: read: connection reset by peer
    7. ====> hyperledger/fabric-orderer:2.4.4
    8. 2.4.4: Pulling from hyperledger/fabric-orderer
    9. Digest: sha256:2a12c6789745c099dc91e7c10c35e6bee7dbfd7b80009fa4c876a7a9cd342bb5
    10. Status: Image is up to date for hyperledger/fabric-orderer:2.4.4
    11. docker.io/hyperledger/fabric-orderer:2.4.4
    12. ====> hyperledger/fabric-ccenv:2.4.4
    13. Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-ccenv/manifests/2.4.4": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-ccenv%3Apull&service=registry.docker.io": net/http: TLS handshake timeout
    14. ====> hyperledger/fabric-tools:2.4.4
    15. 2.4.4: Pulling from hyperledger/fabric-tools
    16. Digest: sha256:fbb12c6e1edc760188cb9057ad68abfa3192a4a6e832dfd0b1ddfa284d28f517
    17. Status: Image is up to date for hyperledger/fabric-tools:2.4.4
    18. docker.io/hyperledger/fabric-tools:2.4.4
    19. ====> hyperledger/fabric-baseos:2.4.4
    20. Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: TLS handshake timeout
    21. ===> Pulling fabric ca Image
    22. ====> hyperledger/fabric-ca:1.5.5
    23. Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-ca/manifests/1.5.5": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-ca%3Apull&service=registry.docker.io": net/http: TLS handshake timeout
    24. ===> List out hyperledger images
    25. hyperledger/fabric-ca 1.5 93f19fa873cb 5 weeks ago 76.5MB
    26. hyperledger/fabric-ca 1.5.5 93f19fa873cb 5 weeks ago 76.5MB
    27. hyperledger/fabric-ca latest 93f19fa873cb 5 weeks ago 76.5MB
    28. hyperledger/fabric-tools 2.4 d2f5f013cf70 8 weeks ago 489MB
    29. hyperledger/fabric-tools 2.4.4 d2f5f013cf70 8 weeks ago 489MB
    30. hyperledger/fabric-tools latest d2f5f013cf70 8 weeks ago 489MB
    31. hyperledger/fabric-peer 2.4 080114f6c98f 8 weeks ago 64.2MB
    32. hyperledger/fabric-peer 2.4.4 080114f6c98f 8 weeks ago 64.2MB
    33. hyperledger/fabric-peer latest 080114f6c98f 8 weeks ago 64.2MB
    34. hyperledger/fabric-orderer 2.4 9e5c2bd3cd99 8 weeks ago 36.7MB
    35. hyperledger/fabric-orderer 2.4.4 9e5c2bd3cd99 8 weeks ago 36.7MB
    36. hyperledger/fabric-orderer latest 9e5c2bd3cd99 8 weeks ago 36.7MB
    37. hyperledger/fabric-ccenv 2.4 b01eeb054e4c 8 weeks ago 520MB
    38. hyperledger/fabric-ccenv 2.4.4 b01eeb054e4c 8 weeks ago 520MB
    39. hyperledger/fabric-ccenv latest b01eeb054e4c 8 weeks ago 520MB
    40. hyperledger/fabric-baseos 2.4 1c37de9bc07b 8 weeks ago 6.86MB
    41. hyperledger/fabric-baseos 2.4.4 1c37de9bc07b 8 weeks ago 6.86MB
    42. hyperledger/fabric-baseos latest 1c37de9bc07b 8 weeks ago 6.86MB

    1.4.4、查看所有docker镜像(共6个)

    docker images

    1. [root@localhost hyperledger]# docker images
    2. REPOSITORY TAG IMAGE ID CREATED SIZE
    3. hyperledger/fabric-ca 1.5 93f19fa873cb 5 weeks ago 76.5MB
    4. hyperledger/fabric-ca 1.5.5 93f19fa873cb 5 weeks ago 76.5MB
    5. hyperledger/fabric-ca latest 93f19fa873cb 5 weeks ago 76.5MB
    6. hyperledger/fabric-tools 2.4 d2f5f013cf70 8 weeks ago 489MB
    7. hyperledger/fabric-tools 2.4.4 d2f5f013cf70 8 weeks ago 489MB
    8. hyperledger/fabric-tools latest d2f5f013cf70 8 weeks ago 489MB
    9. hyperledger/fabric-peer 2.4 080114f6c98f 8 weeks ago 64.2MB
    10. hyperledger/fabric-peer 2.4.4 080114f6c98f 8 weeks ago 64.2MB
    11. hyperledger/fabric-peer latest 080114f6c98f 8 weeks ago 64.2MB
    12. hyperledger/fabric-orderer 2.4 9e5c2bd3cd99 8 weeks ago 36.7MB
    13. hyperledger/fabric-orderer 2.4.4 9e5c2bd3cd99 8 weeks ago 36.7MB
    14. hyperledger/fabric-orderer latest 9e5c2bd3cd99 8 weeks ago 36.7MB
    15. hyperledger/fabric-ccenv 2.4 b01eeb054e4c 8 weeks ago 520MB
    16. hyperledger/fabric-ccenv 2.4.4 b01eeb054e4c 8 weeks ago 520MB
    17. hyperledger/fabric-ccenv latest b01eeb054e4c 8 weeks ago 520MB
    18. hyperledger/fabric-baseos 2.4 1c37de9bc07b 8 weeks ago 6.86MB
    19. hyperledger/fabric-baseos 2.4.4 1c37de9bc07b 8 weeks ago 6.86MB
    20. hyperledger/fabric-baseos latest 1c37de9bc07b 8 weeks ago 6.86MB

    2、运行测试网络

    (1)进入test-network目录

    cd fabric-samples/test-network

    1. [root@localhost hyperledger]# cd fabric-samples/test-network
    2. [root@localhost test-network]#

    (2)查看测试网络帮助

    ./network.sh -h

    1. [root@localhost test-network]# ./network.sh -h
    2. Using docker and docker-compose
    3. Usage:
    4. network.sh [Flags]
    5. Modes:
    6. up - Bring up Fabric orderer and peer nodes. No channel is created
    7. up createChannel - Bring up fabric network with one channel
    8. createChannel - Create and join a channel after the network is created
    9. deployCC - Deploy a chaincode to a channel (defaults to asset-transfer-basic)
    10. down - Bring down the network
    11. Flags:
    12. Used with network.sh up, network.sh createChannel:
    13. -ca - Use Certificate Authorities to generate network crypto material
    14. -c - Name of channel to create (defaults to "mychannel")
    15. -s - Peer state database to deploy: goleveldb (default) or couchdb
    16. -r - CLI times out after certain number of attempts (defaults to 5)
    17. -d - CLI delays for a certain number of seconds (defaults to 3)
    18. -verbose - Verbose mode
    19. Used with network.sh deployCC
    20. -c - Name of channel to deploy chaincode to
    21. -ccn - Chaincode name.
    22. -ccl - Programming language of the chaincode to deploy: go, java, javascript, typescript
    23. -ccv - Chaincode version. 1.0 (default), v2, version3.x, etc
    24. -ccs - Chaincode definition sequence. Must be an integer, 1 (default), 2, 3, etc
    25. -ccp - File path to the chaincode.
    26. -ccep - (Optional) Chaincode endorsement policy using signature policy syntax. The default policy requires an endorsement from Org1 and Org2
    27. -cccg - (Optional) File path to private data collections configuration file
    28. -cci - (Optional) Name of chaincode initialization function. When a function is provided, the execution of init will be requested and the function will be invoked.
    29. -h - Print this message
    30. Possible Mode and flag combinations
    31. up -ca -r -d -s -verbose
    32. up createChannel -ca -c -r -d -s -verbose
    33. createChannel -c -r -d -verbose
    34. deployCC -ccn -ccl -ccv -ccs -ccp -cci -r -d -verbose
    35. Examples:
    36. network.sh up createChannel -ca -c mychannel -s couchdb
    37. network.sh createChannel -c channelName
    38. network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
    39. network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript

    (3)关闭测试网络

    在启动前先清空下测试网络

    ./network.sh down

    1. [root@localhost test-network]# ./network.sh down
    2. Using docker and docker-compose
    3. Stopping network
    4. [+] Running 4/0
    5. ⠿ Volume compose_orderer.example.com Removed 0.0s
    6. ⠿ Volume compose_peer0.org1.example.com Removed 0.0s
    7. ⠿ Volume compose_peer0.org2.example.com Removed 0.0s
    8. ⠿ Volume compose_peer0.org3.example.com Removed 0.0s
    9. Error: No such volume: docker_orderer.example.com
    10. Error: No such volume: docker_peer0.org1.example.com
    11. Error: No such volume: docker_peer0.org2.example.com
    12. Removing remaining containers
    13. Removing generated chaincode docker images
    14. "docker kill" requires at least 1 argument.
    15. See 'docker kill --help'.
    16. Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
    17. Kill one or more running containers
    18. Unable to find image 'busybox:latest' locally
    19. latest: Pulling from library/busybox
    20. 5cc84ad355aa: Pull complete
    21. Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
    22. Status: Downloaded newer image for busybox:latest

    (4)启动测试网络

    ./network.sh up

    1. [root@localhost test-network]# ./network.sh up
    2. Using docker and docker-compose
    3. Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
    4. LOCAL_VERSION=2.4.4
    5. DOCKER_IMAGE_VERSION=2.4.4
    6. /home/gopath/src/github.com/hyperledger/fabric-samples/bin/cryptogen
    7. Generating certificates using cryptogen tool
    8. Creating Org1 Identities
    9. + cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
    10. org1.example.com
    11. + res=0
    12. Creating Org2 Identities
    13. + cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
    14. org2.example.com
    15. + res=0
    16. Creating Orderer Org Identities
    17. + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
    18. + res=0
    19. Generating CCP files for Org1 and Org2
    20. [+] Running 8/8
    21. ⠿ Network fabric_test Created 0.1s
    22. ⠿ Volume "compose_peer0.org2.example.com" Created 0.0s
    23. ⠿ Volume "compose_orderer.example.com" Created 0.0s
    24. ⠿ Volume "compose_peer0.org1.example.com" Created 0.0s
    25. ⠿ Container peer0.org2.example.com Started 1.0s
    26. ⠿ Container orderer.example.com Started 1.2s
    27. ⠿ Container peer0.org1.example.com Started 1.1s
    28. ⠿ Container cli Started 1.5s
    29. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    30. c542333ec97c hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
    31. 75417c088594 hyperledger/fabric-orderer:latest "orderer" 1 second ago Up Less than a second 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp orderer.example.com
    32. 82d6f8435d30 hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp peer0.org1.example.com
    33. 3f3344d4a744 hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp peer0.org2.example.com

    查看docker容器

    docker ps -a

    1. [root@localhost test-network]# docker ps -a
    2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    3. c542333ec97c hyperledger/fabric-tools:latest "/bin/bash" 2 minutes ago Up About a minute cli
    4. 75417c088594 hyperledger/fabric-orderer:latest "orderer" 2 minutes ago Up About a minute 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp orderer.example.com
    5. 82d6f8435d30 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up About a minute 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp peer0.org1.example.com
    6. 3f3344d4a744 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up About a minute 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp peer0.org2.example.com
    7. [root@localhost tes

    (5)创建通道(channel)

    ./network.sh createChannel

    1. [root@localhost test-network]# ./network.sh createChannel
    2. Using docker and docker-compose
    3. Creating channel 'mychannel'.
    4. If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb
    5. Network Running Already
    6. Using docker and docker-compose
    7. Generating channel genesis block 'mychannel.block'
    8. /home/gopath/src/github.com/hyperledger/fabric-samples/bin/configtxgen
    9. + configtxgen -profile TwoOrgsApplicationGenesis -outputBlock ./channel-artifacts/mychannel.block -channelID mychannel
    10. 2022-08-14 16:22:05.084 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
    11. 2022-08-14 16:22:05.091 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: etcdraft
    12. 2022-08-14 16:22:05.091 CST 0003 INFO [common.tools.configtxgen.localconfig] completeInitialization -> Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
    13. 2022-08-14 16:22:05.091 CST 0004 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/configtx/configtx.yaml
    14. 2022-08-14 16:22:05.092 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
    15. 2022-08-14 16:22:05.092 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Creating application channel genesis block
    16. 2022-08-14 16:22:05.093 CST 0007 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block
    17. + res=0
    18. Creating channel mychannel
    19. Using organization 1
    20. + osnadmin channel join --channelID mychannel --config-block ./channel-artifacts/mychannel.block -o localhost:7053 --ca-file /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --client-cert /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt --client-key /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key
    21. + res=0
    22. Status: 201
    23. {
    24. "name": "mychannel",
    25. "url": "/participation/v1/channels/mychannel",
    26. "consensusRelation": "consenter",
    27. "status": "active",
    28. "height": 1
    29. }
    30. Channel 'mychannel' created
    31. Joining org1 peer to the channel...
    32. Using organization 1
    33. + peer channel join -b ./channel-artifacts/mychannel.block
    34. + res=0
    35. 2022-08-14 16:22:11.153 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    36. 2022-08-14 16:22:11.172 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
    37. Joining org2 peer to the channel...
    38. Using organization 2
    39. + peer channel join -b ./channel-artifacts/mychannel.block
    40. + res=0
    41. 2022-08-14 16:22:14.217 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    42. 2022-08-14 16:22:14.244 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
    43. Setting anchor peer for org1...
    44. Using organization 1
    45. Fetching channel config for channel mychannel
    46. Using organization 1
    47. Fetching the most recent configuration block for the channel
    48. + peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
    49. 2022-08-14 08:22:14.388 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    50. 2022-08-14 08:22:14.389 UTC 0002 INFO [cli.common] readBlock -> Received block: 0
    51. 2022-08-14 08:22:14.389 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 0
    52. 2022-08-14 08:22:14.390 UTC 0004 INFO [cli.common] readBlock -> Received block: 0
    53. Decoding config block to JSON and isolating config to Org1MSPconfig.json
    54. + configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
    55. + jq '.data.data[0].payload.data.config' config_block.json
    56. Generating anchor peer update transaction for Org1 on channel mychannel
    57. + jq '.channel_group.groups.Application.groups.Org1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' Org1MSPconfig.json
    58. + configtxlator proto_encode --input Org1MSPconfig.json --type common.Config --output original_config.pb
    59. + configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config --output modified_config.pb
    60. + configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
    61. + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
    62. + jq .
    63. ++ cat config_update.json
    64. + echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org1.example.com",' '"port":' 7051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
    65. + configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org1MSPanchors.tx
    66. 2022-08-14 08:22:14.736 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    67. 2022-08-14 08:22:14.743 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
    68. Anchor peer set for org 'Org1MSP' on channel 'mychannel'
    69. Setting anchor peer for org2...
    70. Using organization 2
    71. Fetching channel config for channel mychannel
    72. Using organization 2
    73. Fetching the most recent configuration block for the channel
    74. + peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
    75. 2022-08-14 08:22:14.880 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    76. 2022-08-14 08:22:14.882 UTC 0002 INFO [cli.common] readBlock -> Received block: 1
    77. 2022-08-14 08:22:14.882 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 1
    78. 2022-08-14 08:22:14.883 UTC 0004 INFO [cli.common] readBlock -> Received block: 1
    79. Decoding config block to JSON and isolating config to Org2MSPconfig.json
    80. + configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
    81. + jq '.data.data[0].payload.data.config' config_block.json
    82. + jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' Org2MSPconfig.json
    83. Generating anchor peer update transaction for Org2 on channel mychannel
    84. + configtxlator proto_encode --input Org2MSPconfig.json --type common.Config --output original_config.pb
    85. + configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config --output modified_config.pb
    86. + configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
    87. + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
    88. + jq .
    89. ++ cat config_update.json
    90. + echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org2.example.com",' '"port":' 9051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
    91. + configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org2MSPanchors.tx
    92. 2022-08-14 08:22:15.046 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    93. 2022-08-14 08:22:15.055 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
    94. Anchor peer set for org 'Org2MSP' on channel 'mychannel'
    95. Channel 'mychannel' joined

    (6)在通道中启动一个链码

    我们使用示例中的其中一个示例(asset-transfer-basic)部署链码

    2.6.1、安装go依赖

    1. [root@localhost test-network]# cd ..
    2. [root@localhost fabric-samples]# cd asset-transfer-basic/chaincode-go/ #进入目录
    3. [root@localhost chaincode-go]# ls #查看目录内容
    4. assetTransfer.go chaincode go.mod go.sum #此时没有vendor目录
    5. [root@localhost chaincode-go]# go env #查看go环境配置
    6. ......
    7. GOPROXY="https://proxy.golang.org,direct" #查看代理设置
    8. ......
    9. [root@localhost chaincode-go]# go env -w GOPROXY=https://goproxy.cn #更改代理
    10. [root@localhost chaincode-go]# go mod vendor #安装依赖
    11. [root@localhost chaincode-go]# ls #查看目录内容
    12. assetTransfer.go chaincode go.mod go.sum vendor #此时出现vendor目录

    2.6.2、部署链码

    进入到test-network目录,部署链码

    ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

    1. [root@localhost chaincode-go]# cd ..
    2. [root@localhost asset-transfer-basic]# cd ..
    3. [root@localhost fabric-samples]# cd test-network
    4. [root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
    5. Using docker and docker-compose
    6. deploying chaincode on channel 'mychannel'
    7. executing with the following
    8. - CHANNEL_NAME: mychannel
    9. - CC_NAME: basic
    10. - CC_SRC_PATH: ../asset-transfer-basic/chaincode-go
    11. - CC_SRC_LANGUAGE: go
    12. - CC_VERSION: 1.0
    13. - CC_SEQUENCE: 1
    14. - CC_END_POLICY: NA
    15. - CC_COLL_CONFIG: NA
    16. - CC_INIT_FCN: NA
    17. - DELAY: 3
    18. - MAX_RETRY: 5
    19. - VERBOSE: false
    20. Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go
    21. /home/gopath/src/github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go /home/gopath/src/github.com/hyperledger/fabric-samples/test-network
    22. /home/gopath/src/github.com/hyperledger/fabric-samples/test-network
    23. Finished vendoring Go dependencies
    24. + peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
    25. + res=0
    26. Chaincode is packaged
    27. Installing chaincode on peer0.org1...
    28. Using organization 1
    29. + peer lifecycle chaincode install basic.tar.gz
    30. + res=0
    31. 2022-08-14 17:14:29.284 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:"\nJbasic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7\022\tbasic_1.0" >
    32. 2022-08-14 17:14:29.285 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7
    33. Chaincode is installed on peer0.org1
    34. Install chaincode on peer0.org2...
    35. Using organization 2
    36. + peer lifecycle chaincode install basic.tar.gz
    37. + res=0
    38. 2022-08-14 17:14:38.207 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:"\nJbasic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7\022\tbasic_1.0" >
    39. 2022-08-14 17:14:38.207 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7
    40. Chaincode is installed on peer0.org2
    41. Using organization 1
    42. + peer lifecycle chaincode queryinstalled
    43. + res=0
    44. Installed chaincodes on peer:
    45. Package ID: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7, Label: basic_1.0
    46. Query installed successful on peer0.org1 on channel
    47. Using organization 1
    48. + peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7 --sequence 1
    49. + res=0
    50. 2022-08-14 17:14:40.294 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [fba0772155296854a87c03e4de42b49fcd3a58b602f6fb98daa77791f892bf9c] committed with status (VALID) at localhost:7051
    51. Chaincode definition approved on peer0.org1 on channel 'mychannel'
    52. Using organization 1
    53. Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
    54. Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
    55. + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
    56. + res=0
    57. {
    58. "approvals": {
    59. "Org1MSP": true,
    60. "Org2MSP": false
    61. }
    62. }
    63. Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'
    64. Using organization 2
    65. Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
    66. Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
    67. + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
    68. + res=0
    69. {
    70. "approvals": {
    71. "Org1MSP": true,
    72. "Org2MSP": false
    73. }
    74. }
    75. Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'
    76. Using organization 2
    77. + peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7 --sequence 1
    78. + res=0
    79. 2022-08-14 17:14:48.422 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [60bba72674fd0af78d585e7b4d71666abde82a39d0443065e6c89662122063d5] committed with status (VALID) at localhost:9051
    80. Chaincode definition approved on peer0.org2 on channel 'mychannel'
    81. Using organization 1
    82. Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
    83. Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
    84. + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
    85. + res=0
    86. {
    87. "approvals": {
    88. "Org1MSP": true,
    89. "Org2MSP": true
    90. }
    91. }
    92. Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'
    93. Using organization 2
    94. Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
    95. Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
    96. + peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
    97. + res=0
    98. {
    99. "approvals": {
    100. "Org1MSP": true,
    101. "Org2MSP": true
    102. }
    103. }
    104. Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'
    105. Using organization 1
    106. Using organization 2
    107. + peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --peerAddresses localhost:7051 --tlsRootCertFiles /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem --peerAddresses localhost:9051 --tlsRootCertFiles /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem --version 1.0 --sequence 1
    108. + res=0
    109. 2022-08-14 17:14:56.652 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [381cc8b2c247ab054ed5cbd83bb653930099b200f37b1db7858f07e0a4bcf921] committed with status (VALID) at localhost:9051
    110. 2022-08-14 17:14:56.659 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [381cc8b2c247ab054ed5cbd83bb653930099b200f37b1db7858f07e0a4bcf921] committed with status (VALID) at localhost:7051
    111. Chaincode definition committed on channel 'mychannel'
    112. Using organization 1
    113. Querying chaincode definition on peer0.org1 on channel 'mychannel'...
    114. Attempting to Query committed status on peer0.org1, Retry after 3 seconds.
    115. + peer lifecycle chaincode querycommitted --channelID mychannel --name basic
    116. + res=0
    117. Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
    118. Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
    119. Query chaincode definition successful on peer0.org1 on channel 'mychannel'
    120. Using organization 2
    121. Querying chaincode definition on peer0.org2 on channel 'mychannel'...
    122. Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
    123. + peer lifecycle chaincode querycommitted --channelID mychannel --name basic
    124. + res=0
    125. Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
    126. Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
    127. Query chaincode definition successful on peer0.org2 on channel 'mychannel'
    128. Chaincode initialization is not required

    (7)与Fabric测试网络交互

    1. # 配置
    2. [root@localhost test-network]# export PATH=${PWD}/../bin:$PATH
    3. [root@localhost test-network]# export FABRIC_CFG_PATH=$PWD/../config/
    4. # 组织1环境配置
    5. [root@localhost test-network]# # Environment variables for Org1
    6. [root@localhost test-network]#
    7. [root@localhost test-network]# export CORE_PEER_TLS_ENABLED=true
    8. [root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org1MSP"
    9. [root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    10. [root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    11. [root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:7051
    12. # 向链码中添加数据
    13. [root@localhost test-network]# peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'
    14. 2022-08-14 17:18:18.536 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200
    15. # 查看添加的数据
    16. [root@localhost test-network]# peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
    17. [{"AppraisedValue":300,"Color":"blue","ID":"asset1","Owner":"Tomoko","Size":5},{"AppraisedValue":400,"Color":"red","ID":"asset2","Owner":"Brad","Size":5},{"AppraisedValue":500,"Color":"green","ID":"asset3","Owner":"Jin Soo","Size":10},{"AppraisedValue":600,"Color":"yellow","ID":"asset4","Owner":"Max","Size":10},{"AppraisedValue":700,"Color":"black","ID":"asset5","Owner":"Adriana","Size":15},{"AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Michel","Size":15}]
    18. # 修改数据
    19. [root@localhost test-network]# peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'
    20. 2022-08-14 17:19:25.738 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200 payload:"Michel"
    21. # 查看修改的数据
    22. [root@localhost test-network]# peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
    23. [{"AppraisedValue":300,"Color":"blue","ID":"asset1","Owner":"Tomoko","Size":5},{"AppraisedValue":400,"Color":"red","ID":"asset2","Owner":"Brad","Size":5},{"AppraisedValue":500,"Color":"green","ID":"asset3","Owner":"Jin Soo","Size":10},{"AppraisedValue":600,"Color":"yellow","ID":"asset4","Owner":"Max","Size":10},{"AppraisedValue":700,"Color":"black","ID":"asset5","Owner":"Adriana","Size":15},{"AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Christopher","Size":15}]
    24. # 组织2环境配置
    25. [root@localhost test-network]# # Environment variables for Org2
    26. [root@localhost test-network]#
    27. [root@localhost test-network]# export CORE_PEER_TLS_ENABLED=true
    28. [root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org2MSP"
    29. [root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    30. [root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    31. [root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:9051
    32. # 查看组织1添加并修改的数据
    33. [root@localhost test-network]# peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'
    34. {"AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Christopher","Size":15}

    参考文档(官网):Using the Fabric test network — hyperledger-fabricdocs main documentation

  • 相关阅读:
    ESP8266-Arduino网络编程实例-OTA升级固件(基于Arduino IDE)
    C. Word Game
    用Spring Boot 3.2虚拟线程搭建静态文件服务器有多快?
    Spring OAuth2 Resource Server 配置
    >>数据管理:读书笔记|第一章 数据管理
    day-64 代码随想录算法训练营(19)图论 part 03
    OpenShift 4 - 在 Windows 上安装 OpenShift 单机开发环境
    手动下载新版的TCGA数据也是可以用TCGAbiolinks包整理的
    java日志框架详解-slf4j
    【SQL解析】- SQL血缘分析实现篇01
  • 原文地址:https://blog.csdn.net/ling1998/article/details/126205555