# milk **Repository Path**: tobenotobe/milk ## Basic Information - **Project Name**: milk - **Description**: No description available - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-02 - **Last Updated**: 2026-06-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="OrgMilkFarmMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/../organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/../organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID=OrgMilkFarmMSP export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/../organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/../organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 configtxgen -configPath $PWD \ -profile SupplyChainChannel \ -outputBlock ./scfchannel.block \ -channelID scfchannel CHANNEL_NAME="milktracechannel" CHAINCODE_NAME="milktrace" CHAINCODE_VERSION="1.0" CHAINCODE_SEQUENCE=1 configtxgen -configPath $PWD -profile MilkTraceChannel -channelID milktracechannel -outputBlock channel-artifacts/milktracechannel.block # 设置 Orderer 管理员证书路径 export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem export ORDERER_ADMIN_TLS_SIGN_CERT=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt export ORDERER_ADMIN_TLS_PRIVATE_KEY=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key osnadmin channel join \ --channelID milktracechannel \ --config-block channel-artifacts/milktracechannel.block \ -o orderer.example.com:7053 \ --ca-file "$ORDERER_CA" \ --client-cert "$ORDERER_ADMIN_TLS_SIGN_CERT" \ --client-key "$ORDERER_ADMIN_TLS_PRIVATE_KEY" ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt osnadmin channel join \ --channelID milktracechannel \ --config-block channel-artifacts/milktracechannel.block \ -o orderer.example.com:7053 \ --ca-file $ORDERER_CA \ --client-cert organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt \ --client-key organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key 1. 停止并清理所有运行的容器及旧数据 bash cd ~/network docker-compose down -v # 停止容器并删除卷(清理账本数据) docker rm -f $(docker ps -aq) 2>/dev/null # 如有残留容器 docker volume prune -f # 清理无用的卷 rm -rf organizations rm -rf channel-artifacts mkdir -p channel-artifacts mkdir -p organizations 2. 使用 cryptogen 重新生成加密材料 cryptogen 会根据 crypto-config.yaml 生成所有组织和节点的 MSP 及 TLS 证书。 # 假设 cryptogen 在 $PATH 中,或者使用相对路径 ../bin/cryptogen cryptogen generate --config=./crypto-config.yaml --output=../organizations 3. 使用 configtxgen 生成系统通道创世块和应用通道配置区块 export FABRIC_CFG_PATH=$PWD # 设置小写通道名 export CHANNEL_NAME=milktracechannel #生成系统通道 configtxgen -profile MilkTraceChannel -outputBlock ./channel-artifacts/${CHANNEL_NAME}.block -channelID $CHANNEL_NAME 4.orderer加入通道 export ORDERER_CA=$PWD/../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt export ORDERER_ADMIN_TLS_SIGN_CERT=$PWD/../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt export ORDERER_ADMIN_TLS_PRIVATE_KEY=$PWD/../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key #orderer1加入通道 osnadmin channel join \ --channelID MilkTraceChannel \ --config-block ./channel-artifacts/MilkTraceChannel.block \ -o orderer.example.com:7053 \ --ca-file "$ORDERER_CA" \ --client-cert "$ORDERER_ADMIN_TLS_SIGN_CERT" \ --client-key "$ORDERER_ADMIN_TLS_PRIVATE_KEY" # orderer2 加入通道 osnadmin channel join \ --channelID milktracechannel \ --config-block ./channel-artifacts/milktracechannel.block \ -o orderer2.example.com:8053 \ --ca-file "$ORDERER_CA" \ --client-cert "$ORDERER_ADMIN_TLS_SIGN_CERT" \ --client-key "$ORDERER_ADMIN_TLS_PRIVATE_KEY" # orderer3 加入通道 osnadmin channel join \ --channelID milktracechannel \ --config-block ./channel-artifacts/milktracechannel.block \ -o orderer3.example.com:9053 \ --ca-file "$ORDERER_CA" \ --client-cert "$ORDERER_ADMIN_TLS_SIGN_CERT" \ --client-key "$ORDERER_ADMIN_TLS_PRIVATE_KEY" 5.peer节点加入通道 #1.OrgMilkFarmMSP # 组织 MSP ID(必须与 configtx.yaml 中一致) export CORE_PEER_LOCALMSPID="OrgMilkFarmMSP" # Peer 地址和端口 export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 # Peer 的 TLS 根证书 export CORE_PEER_TLS_ROOTCERT_FILE=$PWD/../organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt # 当前组织管理员用户的 MSP 路径 export CORE_PEER_MSPCONFIGPATH=$PWD/../organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp # 开启 TLS export CORE_PEER_TLS_ENABLED=true peer channel join -b ./channel-artifacts/milktracechannel.block #2.orgManufacturer # 组织 MSP ID(必须与 configtx.yaml 中一致) export CORE_PEER_LOCALMSPID="OrgManufacturerMSP" # Peer 地址和端口 export CORE_PEER_ADDRESS=peer0.orgManufacturer.example.com:9051 # Peer 的 TLS 根证书 export CORE_PEER_TLS_ROOTCERT_FILE=$PWD/../organizations/peerOrganizations/orgManufacturer.example.com/peers/peer0.orgManufacturer.example.com/tls/ca.crt # 当前组织管理员用户的 MSP 路径 export CORE_PEER_MSPCONFIGPATH=$PWD/../organizations/peerOrganizations/orgManufacturer.example.com/users/Admin@orgManufacturer.example.com/msp # 开启 TLS export CORE_PEER_TLS_ENABLED=true peer channel join -b ./channel-artifacts/milktracechannel.block #3.OrgLogisticsMSP # 组织 MSP ID(必须与 configtx.yaml 中一致) export CORE_PEER_LOCALMSPID="OrgLogisticsMSP" # Peer 地址和端口 export CORE_PEER_ADDRESS=peer0.orgLogistics.example.com:11051 # Peer 的 TLS 根证书 export CORE_PEER_TLS_ROOTCERT_FILE=$PWD/../organizations/peerOrganizations/orgLogistics.example.com/peers/peer0.orgLogistics.example.com/tls/ca.crt # 当前组织管理员用户的 MSP 路径 export CORE_PEER_MSPCONFIGPATH=$PWD/../organizations/peerOrganizations/orgLogistics.example.com/users/Admin@orgLogistics.example.com/msp # 开启 TLS export CORE_PEER_TLS_ENABLED=true peer channel join -b ./channel-artifacts/milktracechannel.block #4.OrgRetailerMSP # 组织 MSP ID(必须与 configtx.yaml 中一致) export CORE_PEER_LOCALMSPID="OrgRetailerMSP" # Peer 地址和端口 export CORE_PEER_ADDRESS=peer0.orgRetailer.example.com:13051 # Peer 的 TLS 根证书 export CORE_PEER_TLS_ROOTCERT_FILE=$PWD/../organizations/peerOrganizations/orgRetailer.example.com/peers/peer0.orgRetailer.example.com/tls/ca.crt # 当前组织管理员用户的 MSP 路径 export CORE_PEER_MSPCONFIGPATH=$PWD/../organizations/peerOrganizations/orgRetailer.example.com/users/Admin@orgRetailer.example.com/msp # 开启 TLS export CORE_PEER_TLS_ENABLED=true peer channel join -b ./channel-artifacts/milktracechannel.block #5.OrgRegulatorMSP # 组织 MSP ID(必须与 configtx.yaml 中一致) export CORE_PEER_LOCALMSPID="OrgRegulatorMSP" # Peer 地址和端口 export CORE_PEER_ADDRESS=peer0.orgRegulator.example.com:15051 # Peer 的 TLS 根证书 export CORE_PEER_TLS_ROOTCERT_FILE=$PWD/../organizations/peerOrganizations/orgRegulator.example.com/peers/peer0.orgRegulator.example.com/tls/ca.crt # 当前组织管理员用户的 MSP 路径 export CORE_PEER_MSPCONFIGPATH=$PWD/../organizations/peerOrganizations/orgRegulator.example.com/users/Admin@orgRegulator.example.com/msp # 开启 TLS export CORE_PEER_TLS_ENABLED=true peer channel join -b ./channel-artifacts/milktracechannel.block 6.编译链码 cd chaincode/milktrace-javaScript npm install 7.打包链码 # 返回 network 目录打包 cd ~/milk/network peer lifecycle chaincode package milktrace.tar.gz \ --path ./chaincode/milktrace \ --lang node \ --label milktrace_1.0 8.安装链码→ 每个 Peer 都要装 CHANNEL_NAME="milktracechannel" CC_NAME="milktrace" CC_VERSION="1.0" CC_SEQUENCE=1 CC_LABEL="milktrace_1.0" CC_PACKAGE="milktrace.tar.gz" # 通用 Orderer CA ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt # --- OrgMilkFarm (peer0:7051) --- export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="OrgMilkFarmMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 peer lifecycle chaincode install ${CC_PACKAGE} # --- OrgManufacturer (peer0:9051) --- export CORE_PEER_LOCALMSPID="OrgManufacturerMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgManufacturer.example.com/peers/peer0.orgManufacturer.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgManufacturer.example.com/users/Admin@orgManufacturer.example.com/msp export CORE_PEER_ADDRESS=peer0.orgManufacturer.example.com:9051 peer lifecycle chaincode install ${CC_PACKAGE} # --- OrgLogistics (peer0:11051) --- export CORE_PEER_LOCALMSPID="OrgLogisticsMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgLogistics.example.com/peers/peer0.orgLogistics.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgLogistics.example.com/users/Admin@orgLogistics.example.com/msp export CORE_PEER_ADDRESS=peer0.orgLogistics.example.com:11051 peer lifecycle chaincode install ${CC_PACKAGE} # --- OrgRetailer (peer0:13051) --- export CORE_PEER_LOCALMSPID="OrgRetailerMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgRetailer.example.com/peers/peer0.orgRetailer.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgRetailer.example.com/users/Admin@orgRetailer.example.com/msp export CORE_PEER_ADDRESS=peer0.orgRetailer.example.com:13051 peer lifecycle chaincode install ${CC_PACKAGE} # --- OrgRegulator (peer0:15051) --- export CORE_PEER_LOCALMSPID="OrgRegulatorMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgRegulator.example.com/peers/peer0.orgRegulator.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgRegulator.example.com/users/Admin@orgRegulator.example.com/msp export CORE_PEER_ADDRESS=peer0.orgRegulator.example.com:15051 peer lifecycle chaincode install ${CC_PACKAGE} 查询链码包 ID # 在任意一个已安装的 Peer 上查询(这里用 OrgMilkFarm) export CORE_PEER_LOCALMSPID="OrgMilkFarmMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 peer lifecycle chaincode queryinstalled --output json | tee /tmp/cc-installed.json # 提取 Package ID CC_PACKAGE_ID=$(peer lifecycle chaincode calculatepackageid ${CC_PACKAGE}) 8.各组织批准链码定义 # --- OrgMilkFarm 批准 --- export CORE_PEER_LOCALMSPID="OrgMilkFarmMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 peer lifecycle chaincode approveformyorg \ -o orderer.example.com:7050 \ --channelID ${CHANNEL_NAME} \ --name ${CC_NAME} \ --version ${CC_VERSION} \ --package-id ${CC_PACKAGE_ID} \ --sequence ${CC_SEQUENCE} \ --tls --cafile ${ORDERER_CA} # --- OrgManufacturer 批准 --- export CORE_PEER_LOCALMSPID="OrgManufacturerMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgManufacturer.example.com/peers/peer0.orgManufacturer.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgManufacturer.example.com/users/Admin@orgManufacturer.example.com/msp export CORE_PEER_ADDRESS=peer0.orgManufacturer.example.com:9051 peer lifecycle chaincode approveformyorg \ -o orderer.example.com:7050 \ --channelID ${CHANNEL_NAME} \ --name ${CC_NAME} \ --version ${CC_VERSION} \ --package-id ${CC_PACKAGE_ID} \ --sequence ${CC_SEQUENCE} \ --tls --cafile ${ORDERER_CA} # --- OrgLogistics 批准 --- export CORE_PEER_LOCALMSPID="OrgLogisticsMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgLogistics.example.com/peers/peer0.orgLogistics.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgLogistics.example.com/users/Admin@orgLogistics.example.com/msp export CORE_PEER_ADDRESS=peer0.orgLogistics.example.com:11051 peer lifecycle chaincode approveformyorg \ -o orderer.example.com:7050 \ --channelID ${CHANNEL_NAME} \ --name ${CC_NAME} \ --version ${CC_VERSION} \ --package-id ${CC_PACKAGE_ID} \ --sequence ${CC_SEQUENCE} \ --tls --cafile ${ORDERER_CA} # --- OrgRetailer 批准 --- export CORE_PEER_LOCALMSPID="OrgRetailerMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgRetailer.example.com/peers/peer0.orgRetailer.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgRetailer.example.com/users/Admin@orgRetailer.example.com/msp export CORE_PEER_ADDRESS=peer0.orgRetailer.example.com:13051 peer lifecycle chaincode approveformyorg \ -o orderer.example.com:7050 \ --channelID ${CHANNEL_NAME} \ --name ${CC_NAME} \ --version ${CC_VERSION} \ --package-id ${CC_PACKAGE_ID} \ --sequence ${CC_SEQUENCE} \ --tls --cafile ${ORDERER_CA} # --- OrgRegulator 批准 --- export CORE_PEER_LOCALMSPID="OrgRegulatorMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgRegulator.example.com/peers/peer0.orgRegulator.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgRegulator.example.com/users/Admin@orgRegulator.example.com/msp export CORE_PEER_ADDRESS=peer0.orgRegulator.example.com:15051 peer lifecycle chaincode approveformyorg \ -o orderer.example.com:7050 \ --channelID ${CHANNEL_NAME} \ --name ${CC_NAME} \ --version ${CC_VERSION} \ --package-id ${CC_PACKAGE_ID} \ --sequence ${CC_SEQUENCE} \ --tls --cafile ${ORDERER_CA} 9.检查链码批准状态... export CORE_PEER_LOCALMSPID="OrgMilkFarmMSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/peers/peer0.orgMilkFarm.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/orgMilkFarm.example.com/users/Admin@orgMilkFarm.example.com/msp export CORE_PEER_ADDRESS=peer0.orgMilkFarm.example.com:7051 peer lifecycle chaincode checkcommitreadiness \ --channelID ${CHANNEL_NAME} \ --name ${CC_NAME} \ --version ${CC_VERSION} \ --sequence ${CC_SEQUENCE} \ --tls --cafile ${ORDERER_CA} \ --output json