学习记录:fabric(1)- 部署网络

前情提要

网络都要从创建用户开始。fabric有两种方法,fabric-ca或者cryptogen,这两个都可以。cryptogen属于开发场景下的使用,聚焦到这个上面来,快速把链码开发和SDK开发两种环境都搭好。

这写网上已有的就比较多

开始

创建空项目,创建文件cryptogen-config.yaml

配置文件中描述了网络的拓扑结构同时会为Orgnizations和Orgnizations下的节点生成一系列的证书。

网络节点的命名规则为{Hostname}.{Domain}。以上述配置文件中order节点为例,order节点的命名为orderer.example.com,对应的MSP Id为Orderer。运行cryptogen命令后,生成的数字证书和密钥信息保存在crypto-config文件夹中。

OrdererOrgs:
  - Name: Orderer
    Domain: hys.com
    EnableNodeOUs: false
    Specs:
      - Hostname: orderer
PeerOrgs:
  - Name: Org1
    Domain: org1.hys.com
    EnableNodeOUs: false
    Template:
      Count: 2
    Users:
      Count: 1
  - Name: Org2
    Domain: org2.hys.com
    EnableNodeOUs: false
    Template:
      Count: 2
    Users:
      Count: 1
cryptogen generate --config=crypto-config.yaml

还是测试工具好用啊。啊~~~~~~~~~~~~~~~~
在这里插入图片描述
用extend可以扩展,这样不用改已经存在的用户和证书,https://www.jianshu.com/p/9d031a0606b7说的很详细

创建configtx.yaml,运行configtxgen,得到创世区块和通道事务。

然后用已有的msp配置容器,参照fabric-sample改一改,启动。这次的容器设置是继承的,新学到的。

然后创建各自通道,加入通道,更新通道以加入锚节点。

然后自己弄一个链码,安装上去。

调用一下链码,链码这一段,参考官方教程多一些,博客里有点老。
https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html

搞定。

主要参考https://www.jianshu.com/p/813621eff343,写的非常详细(但是注意那个教程是1.4的)。

项目结构:
在这里插入图片描述
几个yaml文件

peer-base.yaml

version: '2'

services:
  peer-base:
    image: hyperledger/fabric-peer
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
      - FABRIC_LOGGING_SPEC=DEBUG # INFO ERROR
      - CORE_PEER_TLS_ENABLED=true
      # - CORE_PEER_GOSSIP_USELEADERELECTION=true
      # - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start

dc-base.yaml

version: '2'

services:
  # 名称和cryptogen中产生的一样
  orderer.hys.com:
    container_name: orderer.hys.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    volumes:
    - ../system-genesis-block/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
    - ../crypto-config/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp:/var/hyperledger/orderer/msp
    - ../crypto-config/ordererOrganizations/hys.com/orderers/orderer.hys.com/tls/:/var/hyperledger/orderer/tls
    ports:
      - 7050:7050
    command: orderer

  peer0.org1.hys.com:
    container_name: peer0.org1.hys.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org1.hys.com
      - CORE_PEER_ADDRESS=peer0.org1.hys.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.hys.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.hys.com:7051      
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.hys.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 7051:7051
      - 7052:7052 
    command: peer node start

  peer0.org2.hys.com:
    container_name: peer0.org2.hys.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org2.hys.com
      - CORE_PEER_ADDRESS=peer0.org2.hys.com:9051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:9051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.hys.com:9051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.hys.com:9051      
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_CHAINCODEADDRESS=peer0.org2.hys.com:9052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org2.hys.com/peers/peer0.org2.hys.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org2.hys.com/peers/peer0.org2.hys.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 9051:9051
      - 9052:9052
    command: peer node start

docker-compose.yaml

version: '2'

networks:
    basic:
services:
    orderer.hys.com:
        extends:
            file:   base/dc-base.yaml
            service: orderer.hys.com
        container_name: orderer.hys.com
        networks:
            - basic

    peer0.org1.hys.com:
        extends:
            file:  base/dc-base.yaml
            service: peer0.org1.hys.com
        container_name: peer0.org1.hys.com
        networks:
            - basic

    peer0.org2.hys.com:
        extends:
            file:  base/dc-base.yaml
            service: peer0.org2.hys.com
        container_name: peer0.org2.hys.com
        networks:
            - basic
 
    cli:
        container_name: cli
        image: hyperledger/fabric-tools
        tty: true
        environment:
            - GOPATH=/opt/gopath
            - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
            - FABRIC_LOGGING_SPEC=DEBUG
            - CORE_PEER_ID=cli
            - CORE_PEER_ADDRESS=peer0.org1.hys.com:7051
            - CORE_PEER_LOCALMSPID=Org1MSP  # 同configtx配置
            - CORE_PEER_TLS_ENABLED=true
            - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/tls/server.crt
            - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/tls/server.key
            - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/tls/ca.crt
            - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.hys.com/users/Admin@org1.hys.com/msp
        working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer # bash进入时的路径
        # command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
        volumes:
            - /var/run/:/host/var/run/
            - ./chaincode/:/opt/gopath/src/github.com/chaincode
            - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
            - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
        depends_on:
            - orderer.hys.com
            - peer0.org1.hys.com
            - peer0.org2.hys.com
        networks:
            - basic  

configtx.yaml

# 基于fabric-sample/test-network/configt/configtx.yaml,进行修改
---
################################################################################
#   Section: Organizations
#
#   - 这部分定义不同组织身份,以供其他配置引用
################################################################################
Organizations:

    # SampleOrg defines an MSP using the sampleconfig.  It should never be used
    # in production but may be used as a template for other definitions
    - &OrdererOrg # 排序组织
        Name: OrdererOrg
        ID: OrdererMSP
        # MSPDir 文件路径指向msp文件夹
        MSPDir: ./crypto-config/ordererOrganizations/hys.com/msp
        # 本层级策略。组织策略的话,规范路径为/Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"
        # 排序节点的端点
        OrdererEndpoints: 
            - orderer.hys.com:7050
        
    - &Org1
        Name: Org1MSP
        ID: Org1MSP
        MSPDir: ./crypto-config/peerOrganizations/org1.hys.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org1MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org1MSP.peer')"
        # leave this flag set to true.
        # 锚节点
        AnchorPeers:
            #组织间通信的锚节点。注意,该值在Application部分中仅在创世区块内编码
            - Host: peer0.org1.hys.com
              Port: 7051

    - &Org2
        Name: Org2MSP
        ID: Org2MSP
        MSPDir: ./crypto-config/peerOrganizations/org2.hys.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org2MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org2MSP.peer')"
        AnchorPeers:
            - Host: peer0.org2.hys.com
              Port: 9051

################################################################################
#   SECTION: Capabilities
#   
#   暂时不需要了解
################################################################################
Capabilities:
    Channel: &ChannelCapabilities
        V2_0: true

    Orderer: &OrdererCapabilities
        V2_0: true

    Application: &ApplicationCapabilities
        V2_0: true

################################################################################
#   SECTION: Application
#
#   本节定义了要编码进配置事务或创世区块的应用相关参数
################################################################################
Application: &ApplicationDefaults
    # 组织列表
    Organizations:
    # 对于application策略,规范为/Channel/Application/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        LifecycleEndorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"
        Endorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"
    Capabilities:
        <<: *ApplicationCapabilities
################################################################################
#   SECTION: Orderer
#
#   本节定义了要编码进配置事务或创世区块的排序节点相关参数
################################################################################
Orderer: &OrdererDefaults
    # 共识类型
    OrdererType: etcdraft
    EtcdRaft:
        Consenters:
        - Host: orderer.hys.com
          Port: 7050
          ClientTLSCert: ./crypto-config/ordererOrganizations/hys.com/orderers/orderer.hys.com/tls/server.crt
          ServerTLSCert: ./crypto-config/ordererOrganizations/hys.com/orderers/orderer.hys.com/tls/server.crt
    # 客户端和peer节点可以连接到排序节点的地址。但这不允许客户端和排序节点的地址关联以及排序
    # 组织的TLS验证。更好的方法是在组织定义里写OrdererEndpoints
    Addresses:
        - orderer.hys.com:7050
    # Batch Timeout: The amount of time to wait before creating a batch
    BatchTimeout: 2s
    # Batch Size: Controls the number of messages batched into a block
    BatchSize:
        # Max Message Count: The maximum number of messages to permit in a batch
        MaxMessageCount: 10
        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch.
        AbsoluteMaxBytes: 99 MB
        # Preferred Max Bytes: The preferred maximum number of bytes allowed for
        # the serialized messages in a batch. A message larger than the preferred
        # max bytes will result in a batch larger than preferred max bytes.
        PreferredMaxBytes: 512 KB
    # Organizations is the list of orgs which are defined as participants on
    # the orderer side of the network
    Organizations:
    # Policies defines the set of policies at this level of the config tree
    # For Orderer policies, their canonical path is
    #   /Channel/Orderer/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        # BlockValidation specifies what signatures must be included in the block
        # from the orderer for the peer to validate it.
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"

################################################################################
#   CHANNEL
#
#   本节定义了要编码进配置事务或创世区块的通道相关参数
################################################################################
Channel: &ChannelDefaults
    # 格式为/Channel/<PolicyName>
    Policies:
        # Who may invoke the 'Deliver' API
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        # Who may invoke the 'Broadcast' API
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        # By default, who may modify elements at this config level
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
    Capabilities:
        <<: *ChannelCapabilities

################################################################################
#   Profile
#
#   各种事务的配置,给configtxgen调用
################################################################################
Profiles:
    OrgsOrdererGenesis:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
    OrgsChannel:
        Consortium: SampleConsortium
        <<: *ChannelDefaults
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
            Capabilities:
                <<: *ApplicationCapabilities

crypto-config.yaml

OrdererOrgs:
  - Name: Orderer
    Domain: hys.com
    EnableNodeOUs: false
    Specs:
      - Hostname: orderer
PeerOrgs:
  - Name: Org1
    Domain: org1.hys.com
    EnableNodeOUs: false
    Template:
      Count: 2
    Users:
      Count: 1
  - Name: Org2
    Domain: org2.hys.com
    EnableNodeOUs: false
    Template:
      Count: 2
    Users:
      Count: 1

感觉全程照着教程和博客做,很容易就弄好了。我的天,为什么我去搞了fabric-ca。。。

补充

用到的命令(参数可能不同,请注意,这个就是scripts.txt文件,方便我自己记录,不用一直打命令):

# 锚节点更新交易创建
configtxgen -profile OrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID app-channel -asOrg Org2MSP
configtxgen -profile OrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID app-channel -asOrg Org1MSP

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
# 或
docker-compose down
docker volume prune #这很重要

CHANNEL_NAME=app-channel docker-compose up -d

docker exec -it cli bash
# 创建通道
peer channel create -o orderer.hys.com:7050 -c app-channel -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem
# 加入
peer channel join -b app-channel.block
# 锚节点指定
peer channel update -o orderer.hys.com:7050 -c app-channel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem

# 各节点都要加入通道
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.hys.com/peers/peer0.org2.hys.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.hys.com/users/Admin@org2.hys.com/msp
export CORE_PEER_ADDRESS=peer0.org2.hys.com:9051

 # 加入
peer channel join -b app-channel.block
# 锚节点指定
peer channel update -o orderer.hys.com:7050 -c app-channel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem


# 打包
cd /opt/gopath/src/github.com/chaincode/atcc
go env -w GOPROXY=https://goproxy.cn,direct
go mod init
go mod vendor
cd /opt/gopath/src/github.com/hyperledger/fabric/peer  # 工作目录

peer lifecycle chaincode package atcc.tar.gz --path ../../../chaincode/atcc --lang golang --label atcc_1
# 安装 
peer lifecycle chaincode install atcc.tar.gz
# 查询package id
peer lifecycle chaincode queryinstalled
#Package ID: atcc_1.0:e14f82badce9491f7aabf6c05e6105622604daf2e7521815f7108bf12674a61d, Label: atcc_1
# 批准链码
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.hys.com --channelID app-channel --name atcc --version 1.0 --package-id atcc_1.0:e14f82badce9491f7aabf6c05e6105622604daf2e7521815f7108bf12674a61d --sequence 1 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem

# 批准 注意添加package id,通道内各个节点都要批准
peer lifecycle chaincode approveformyorg --channelID mychannel --name atcc --version 1.0 --init-required --package-id  --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem

# 检查批准
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name atcc --version 1.0 --init-required --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem --output json

# 提交 一次即可
peer lifecycle chaincode commit -o orderer.hys.com:7050 --channelID mychannel --name atcc --version 1.0 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem --peerAddresses peer0.org1.hys.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/tls/ca.crt --peerAddresses peer0.org2.hys.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.hys.com/peers/peer0.org2.hys.com/tls/ca.crt

# 调用
peer chaincode invoke -o orderer.hys.com:7050 --isInit  --ordererTLSHostnameOverride orderer.hys.com --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/hys.com/orderers/orderer.hys.com/msp/tlscacerts/tlsca.hys.com-cert.pem -C mychannel -n sacc --peerAddresses peer0.org1.hys.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.hys.com/peers/peer0.org1.hys.com/tls/ca.crt --peerAddresses peer0.org2.hys.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.hys.com/peers/peer0.org2.hys.com/tls/ca.crt -c '{"Args":[]}'
# 调用
peer chaincode query -C mychannel -n sacc -c '{"Args":["GetAllAssets"]}'

init.sh

频繁的测试还是用脚本比较好

# 创建加密材料
if [ ! -f "crypto-config.yaml" ]
then
    echo "crypto-config.yaml not found."
fi
DIRECTORY="./crypto-config"
if [ "`ls -A $DIRECTORY`" = "" ]; then
    echo "create crypto-config..."
    cryptogen generate --config=./crypto-config.yaml
else
    echo "$DIRECTORY is not empty. using exist crypto-config" 
fi

# 创建创世区块和通道
DIRECTORY="./system-genesis-block"
mkdir -p $DIRECTORY
if [ "`ls -A $DIRECTORY`" = "" ]; then
    echo "create $DIRECTORY..." 
    configtxgen -profile OrgsOrdererGenesis -outputBlock $DIRECTORY/genesis.block -channelID orderer-system-channel
else
    echo "$DIRECTORY is not empty. using exist $DIRECTORY" 
fi
DIRECTORY="./channel-artifacts"
mkdir -p $DIRECTORY
if [ "`ls -A $DIRECTORY`" = "" ]; then
    echo "create $DIRECTORY..."
    configtxgen -profile OrgsChannel -outputCreateChannelTx $DIRECTORY/channel.tx -channelID app-channel
else
    echo "$DIRECTORY is not empty. using exist $DIRECTORY" 
fi

问题 chaincode definition for ‘sacc’ exists, but chaincode is not installed"

这个问题找到了:是packageid设置问题,批准的时候,需要设置为sacc_1.0:1ec5f659f7b95978829202e4201cd969ccb0952a9c87a1bb51c9588b518923a1
而不是
1ec5f659f7b95978829202e4201cd969ccb0952a9c87a1bb51c9588b518923a1
注意前面的sacc_1.0:,大意了,之前用测试网络都是注意到的,这就是必须要全程手打命令决不能复制的原因,这样才能注意到一些问题。

这里也有说明 https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html#invoke-failure
还有这里 https://stackoverflow.com/questions/60939652/in-hyperledger-fabric-when-i-try-to-invoke-im-getting-the-following-error-cha

如果不记得package id,用下面的命令查询

peer lifecycle chaincode queryinstalled

如果还有什么需要的,请留言。

参考

  • https://www.jianshu.com/p/8beb3a355f99
  • https://www.jianshu.com/p/9d031a0606b7
  • https://www.jianshu.com/p/813621eff343
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值