Развертывание и обновление базового цепочного кода Fabric-samples assets-transfer-basic (Fabric 2.4.4)

1. Анализ кода

1.1. Запуск чейнкода

актив-передача-основной/chaincode-go/assetTransfer.go

func main() {

    //新建链码
	assetChaincode, err := contractapi.NewChaincode(&chaincode.SmartContract{})
	if err != nil {
		log.Panicf("Error creating asset-transfer-basic chaincode: %v", err)
	}

    //启动链码
	if err := assetChaincode.Start(); err != nil {
		log.Panicf("Error starting asset-transfer-basic chaincode: %v", err)
	}
}

1.2 Структура чейнкода

передача активов-базовый/chaincode-go/chaincode/smartcontract.go

type SmartContract struct {
	contractapi.Contract
}

1.3. Работа с данными 

передача активов-базовый/chaincode-go/chaincode/smartcontract.go

1.3.1. Хранить данные

err = ctx.GetStub().PutState(asset.ID, assetJSON)

1.3.2. Получить данные

assetJSON, err := ctx.GetStub().GetState(id)

1.3.3 Удалить данные

ctx.GetStub().DelState(id)

1.3.4 Получить список данных (итератор)

resultsIterator, err := ctx.GetStub().GetStateByRange("", "")

2. Развертывание чейнкода

2.1. Запустите тестовую сеть

2.1.1, войдите в тестовую сетевую директорию

cd образцы тканей / тестовая сеть

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

2.1.2. Закройте тестовую сеть

./network.sh вниз

[root@localhost test-network]# ./network.sh down
Using docker and docker-compose
Stopping network
[+] Running 4/0
 ⠿ Volume compose_peer0.org3.example.com  Removed                                                                                                 0.0s
 ⠿ Volume compose_orderer.example.com     Removed                                                                                                 0.0s
 ⠿ Volume compose_peer0.org1.example.com  Removed                                                                                                 0.0s
 ⠿ Volume compose_peer0.org2.example.com  Removed                                                                                                 0.0s
Error: No such volume: docker_orderer.example.com
Error: No such volume: docker_peer0.org1.example.com
Error: No such volume: docker_peer0.org2.example.com
Removing remaining containers
Removing generated chaincode docker images
"docker kill" requires at least 1 argument.
See 'docker kill --help'.

Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]

Kill one or more running containers

2.1.3 Запустите тестовую сеть и одновременно создайте канал

./network.sh up createChannel -c tracychannel 

-c указывает имя канала, если не указано, по умолчанию используется mychannel 

[root@localhost test-network]# ./network.sh up createChannel -c tracychannel
Using docker and docker-compose
Creating channel 'tracychannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb with crypto from 'cryptogen'
Bringing up network
LOCAL_VERSION=2.4.4
DOCKER_IMAGE_VERSION=2.4.4
/home/gopath/src/github.com/hyperledger/fabric-samples/bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
[+] Running 8/8
 ⠿ Network fabric_test                      Created                                                                                               0.1s
 ⠿ Volume "compose_orderer.example.com"     Created                                                                                               0.0s
 ⠿ Volume "compose_peer0.org1.example.com"  Created                                                                                               0.0s
 ⠿ Volume "compose_peer0.org2.example.com"  Created                                                                                               0.0s
 ⠿ Container peer0.org1.example.com         Started                                                                                               0.7s
 ⠿ Container peer0.org2.example.com         Started                                                                                               0.6s
 ⠿ Container orderer.example.com            Started                                                                                               1.0s
 ⠿ Container cli                            Started                                                                                               1.2s
CONTAINER ID   IMAGE                               COMMAND             CREATED         STATUS                  PORTS                                                                                                                             NAMES
996db23379fb   hyperledger/fabric-tools:latest     "/bin/bash"         2 seconds ago   Up Less than a second                                                                                                                                     cli
9694d2a81710   hyperledger/fabric-peer:latest      "peer node start"   2 seconds 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
256d3c257a04   hyperledger/fabric-peer:latest      "peer node start"   2 seconds 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
0c67126f3c75   hyperledger/fabric-orderer:latest   "orderer"           2 seconds 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
Using docker and docker-compose
Generating channel genesis block 'tracychannel.block'
/home/gopath/src/github.com/hyperledger/fabric-samples/bin/configtxgen
+ configtxgen -profile TwoOrgsApplicationGenesis -outputBlock ./channel-artifacts/tracychannel.block -channelID tracychannel
2022-10-08 09:17:04.201 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2022-10-08 09:17:04.208 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: etcdraft
2022-10-08 09:17:04.208 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 
2022-10-08 09:17:04.208 CST 0004 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/configtx/configtx.yaml
2022-10-08 09:17:04.209 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
2022-10-08 09:17:04.209 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Creating application channel genesis block
2022-10-08 09:17:04.209 CST 0007 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block
+ res=0
Creating channel tracychannel
Using organization 1
+ osnadmin channel join --channelID tracychannel --config-block ./channel-artifacts/tracychannel.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
+ res=0
Status: 201
{
	"name": "tracychannel",
	"url": "/participation/v1/channels/tracychannel",
	"consensusRelation": "consenter",
	"status": "active",
	"height": 1
}

Channel 'tracychannel' created
Joining org1 peer to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/tracychannel.block
+ res=0
2022-10-08 09:17:10.273 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-10-08 09:17:10.284 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
Joining org2 peer to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/tracychannel.block
+ res=0
2022-10-08 09:17:13.322 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-10-08 09:17:13.335 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
Setting anchor peer for org1...
Using organization 1
Fetching channel config for channel tracychannel
Using organization 1
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c tracychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2022-10-08 01:17:13.467 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-10-08 01:17:13.469 UTC 0002 INFO [cli.common] readBlock -> Received block: 0
2022-10-08 01:17:13.469 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 0
2022-10-08 01:17:13.470 UTC 0004 INFO [cli.common] readBlock -> Received block: 0
Decoding config block to JSON and isolating config to Org1MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
Generating anchor peer update transaction for Org1 on channel tracychannel
+ 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
+ configtxlator proto_encode --input Org1MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id tracychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"tracychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"tracychannel",' '"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"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org1MSPanchors.tx
2022-10-08 01:17:13.809 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-10-08 01:17:13.817 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
Anchor peer set for org 'Org1MSP' on channel 'tracychannel'
Setting anchor peer for org2...
Using organization 2
Fetching channel config for channel tracychannel
Using organization 2
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c tracychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
Fetching the most recent configuration block for the channel
2022-10-08 01:17:13.960 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-10-08 01:17:13.962 UTC 0002 INFO [cli.common] readBlock -> Received block: 1
2022-10-08 01:17:13.962 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 1
2022-10-08 01:17:13.963 UTC 0004 INFO [cli.common] readBlock -> Received block: 1
Decoding config block to JSON and isolating config to Org2MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
Generating anchor peer update transaction for Org2 on channel tracychannel
+ 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
+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id tracychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"tracychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"tracychannel",' '"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"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org2MSPanchors.tx
2022-10-08 01:17:14.130 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-10-08 01:17:14.137 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'tracychannel'
Channel 'tracychannel' joined

2.1.4, просмотр канала

список одноранговых каналов

[root@localhost test-network]# peer channel list
-bash: peer: command not found

Если сообщается об ошибке «-bash: peer: команда не найдена», необходимо установить переменные среды (шаг 2.3.2 был выполнен заранее)

экспорт PATH=${PWD}/../bin:$PATH

экспортировать FABRIC_CFG_PATH=$PWD/../config/

[root@localhost test-network]# export PATH=${PWD}/../bin:$PATH
[root@localhost test-network]# export FABRIC_CFG_PATH=$PWD/../config/

Просмотр набора переменных среды

эхо $PATH

эхо $FABRIC_CFG_PATH

[root@localhost test-network]# echo $PATH
/home/gopath/src/github.com/hyperledger/fabric-samples/test-network/../bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/home/gopath/bin:/root/bin
[root@localhost test-network]# echo $FABRIC_CFG_PATH
/home/gopath/src/github.com/hyperledger/fabric-samples/test-network/../config/

Выполнить список одноранговых каналов снова

[root@localhost test-network]# peer channel list
2022-10-08 10:04:30.074 CST 0001 ERRO [main] InitCmd -> Cannot run peer because cannot init crypto, specified path "/home/gopath/src/github.com/hyperledger/fabric-samples/config/msp" does not exist or cannot be accessed: stat /home/gopath/src/github.com/hyperledger/fabric-samples/config/msp: no such file or directory

2.1.5 Просмотр запущенных узлов

докер пс

Запущено 2 организации, у каждой организации есть одноранговый узел

[root@localhost test-network]# docker ps
CONTAINER ID   IMAGE                               COMMAND             CREATED          STATUS          PORTS                                                                                                                             NAMES
996db23379fb   hyperledger/fabric-tools:latest     "/bin/bash"         57 minutes ago   Up 57 minutes                                                                                                                                     cli
9694d2a81710   hyperledger/fabric-peer:latest      "peer node start"   57 minutes ago   Up 57 minutes   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
256d3c257a04   hyperledger/fabric-peer:latest      "peer node start"   57 minutes ago   Up 57 minutes   0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp                                              peer0.org1.example.com
0c67126f3c75   hyperledger/fabric-orderer:latest   "orderer"           57 minutes ago   Up 57 minutes   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

 2.2 Генерация зависимостей проекта

GO111MODULE=поставщик модов

Войдите в каталог проекта и сгенерируйте зависимости 

[root@localhost test-network]# cd ..
[root@localhost fabric-samples]# cd asset-transfer-basic/chaincode-go/
[root@localhost chaincode-go]# GO111MODULE=on go mod vendor

 Создайте каталог поставщика следующим образом:

2.3, код цепочки упаковки

2.3.1, войдите в каталог test-network

cd ../../тестовая сеть

[root@localhost chaincode-go]# cd ../../test-network

2.3.2 Установка переменных окружения

Если шаг 2.1.4 был выполнен выше, нет необходимости выполнять этот шаг.

Примечание. Установка переменной среды здесь должна выполняться в каталоге test-network.

экспорт PATH=${PWD}/../bin:$PATH

экспортировать FABRIC_CFG_PATH=$PWD/../config/

[root@localhost test-network]# export PATH=${PWD}/../bin:$PATH
[root@localhost test-network]# export FABRIC_CFG_PATH=$PWD/../config/

2.3.3, код цепочки упаковки

пакет цепочек кодов жизненного цикла одноранговых узлов basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0

[root@localhost test-network]# peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0

Создайте пакет чейнкода basic.tar.gz в текущем каталоге, как показано на следующем рисунке: 

2.4, установить код цепи

Установите чейнкод в 2 организациях (организация 1 и организация 2).

2.4.1 Установите переменные среды (Организация 1 - Org1)

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD} /organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051

[root@localhost test-network]# export CORE_PEER_TLS_ENABLED=true
[root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org1MSP"
[root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
[root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
[root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:7051

2.4.2. Установите код цепи (организация 1 - Org1)

Чейнкод жизненного цикла однорангового узла установить basic.tar.gz

[root@localhost test-network]# peer lifecycle chaincode install basic.tar.gz
2022-10-08 10:44:16.265 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nJbasic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7\022\tbasic_1.0" > 
2022-10-08 10:44:16.265 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7

2.4.3 Установите переменные среды (Организация 2 - Org2)

export CORE_PEER_TLS_ENABLED
= true ### Необходимо установить его снова, иначе установка чейнкода не удастся.
.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051

[root@localhost test-network]# export CORE_PEER_TLS_ENABLED=true
[root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org2MSP"
[root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
[root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
[root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:9051

2.4.4. Установите чейн-код (организация 2 — Org2)

Чейнкод жизненного цикла однорангового узла установить basic.tar.gz

root@localhost test-network]# peer lifecycle chaincode install basic.tar.gz
2022-10-08 10:50:00.193 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nJbasic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7\022\tbasic_1.0" > 
2022-10-08 10:50:00.193 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7

2.5 Код цепочки авторизации 

2.5.1. Просмотр состояния установки чейнкода (Организация 2 — Org2)

Поскольку переменные среды, настроенные на шаге 2.4.4 выше, принадлежат организации 2, поэтому переменные среды здесь также относятся к организации 2.

установлен запрос кода цепи жизненного цикла однорангового узла

[root@localhost test-network]# peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7, Label: basic_1.0

2.5.2. Установите переменные среды пакета чейнкода (организация 2 — Org2)

Идентификатор пакета чейнкода — это идентификатор пакета, указанный выше.

экспорт CC_PACKAGE_ID=basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7

[root@localhost test-network]# export CC_PACKAGE_ID=basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7

2.5.3. Цепочка авторизации (Организация 2 — Org2)

Примечание. Имя канала — это имя канала, созданное при запуске сети.

код цепочки жизненного цикла однорангового узла утвердить формуyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD }/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"

[root@localhost test-network]# peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
2022-10-08 11:00:18.110 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [d68bed6e512945ffbd85430acd0f19c2486ba796c4e2a718be1b4ce743d7ba36] committed with status (VALID) at localhost:9051

2.5.4 Переключиться на организацию 1

export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example .com/peers/peer0.org1.example.com/tls/ca.crt
экспорт CORE_PEER_ADDRESS=localhost:7051

[root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org1MSP"
[root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
[root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
[root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:7051

2.5.5 Просмотр состояния установки чейнкода (Организация 1 – Организация 1)

установлен запрос кода цепи жизненного цикла однорангового узла

[root@localhost test-network]# peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7, Label: basic_1.0

Видно, что идентификатор пакета чейнкода здесь такой же, как и в организации 2. 

2.5.6. Установите переменные среды пакета чейнкода (организация 1 - Org1)

Идентификатор пакета чейнкода — это идентификатор пакета, указанный выше.

экспорт CC_PACKAGE_ID=basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7

[root@localhost test-network]# export CC_PACKAGE_ID=basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7

2.5.7, код цепочки авторизации (организация 1 - Org1)

Примечание. Имя канала — это имя канала, созданное при запуске сети.

код цепочки жизненного цикла однорангового узла утвердить формуyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD }/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"

[root@localhost test-network]# peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
2022-10-08 11:09:44.671 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [7dae727d6a3312039fe40c4893244e316e0bd71ab6e9977787f4f1251bea8757] committed with status (VALID) at localhost:7051

2.5.8 Просмотр результатов авторизации

Примечание. Имя канала — это имя канала, созданное при запуске сети.

жизненный цикл равноправного узла chaincode checkcommitreadiness --channelID tracychannel --name basic --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/ tlscacerts/tlsca.example.com-cert.pem" -- вывод json

2022-10-08 11:09:44.671 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [7dae727d6a3312039fe40c4893244e316e0bd71ab6e9977787f4f1251bea8757] committed with status (VALID) at localhost:7051
[root@localhost test-network]# peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --output json
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}

2.6. Отправить код цепи

После авторизации вы можете отправить код цепочки. Только организация, которая авторизует код цепочки, может отправить код цепочки (любая организация, которая авторизует код цепочки, может отправить), и вы можете просмотреть результат авторизации организации на шаге 2.5.8 выше.

2.6.1. Отправить код цепи

Примечание. Имя канала — это имя канала, созданное при запуске сети.

код цепочки жизненного цикла однорангового узла commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example .com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --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"

[root@localhost test-network]# peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --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"
2022-10-08 11:19:06.266 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [1129f4b4285403e8660ef674f0f07726865bc720d08f8ebae224ae255f75f67f] committed with status (VALID) at localhost:7051
2022-10-08 11:19:06.274 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [1129f4b4285403e8660ef674f0f07726865bc720d08f8ebae224ae255f75f67f] committed with status (VALID) at localhost:9051

2.6.2. Просмотр результатов отправки

Примечание. Имя канала — это имя канала, созданное при запуске сети.

одноранговый жизненный цикл chaincode querycommitted --channelID tracychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem " -- вывод JSON

[root@localhost test-network]# peer lifecycle chaincode querycommitted --channelID tracychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"  --output json
{
	"sequence": 1,
	"version": "1.0",
	"endorsement_plugin": "escc",
	"validation_plugin": "vscc",
	"validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
	"collections": {},
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}

2.7, вызовите чейн-код

Примечание. В команде, выполняемой путем вызова чейнкода, обратите внимание, что имя канала — это имя канала, созданное при запуске сети, а имя канала в команде выделено полужирным шрифтом.

2.7.1 Вызов функции данных инициализации

peer chaincode invoke -o localhost:7050 --ordererTLSHhostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca. example.com-cert.pem" -C tracychannel -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 '{ «функция»: «InitLedger», «Аргументы»: []}'

 -c '{"функция":"InitLedger","Аргументы":[]}' 

функция: указывает, что функция должна быть вызвана

InitLedger: имя функции

Args: параметры, текущий массив параметров пуст, то есть параметров нет

[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 tracychannel -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":[]}'
2022-10-08 11:41:16.406 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200 

2.7.2. Запросить все данные актива

запрос однорангового кода цепи -C tracychannel -n basic -c '{"Args":["GetAllAssets"]}' 

[root@localhost test-network]# peer chaincode query -C tracychannel -n basic -c '{"Args":["GetAllAssets"]}'
[{"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}]

2.7.3. Вызов функции создания актива

Посмотреть название и параметры функции создания актива в коде

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, color string, size int, owner string, appraisedValue int) error {
	exists, err := s.AssetExists(ctx, id)
	if err != nil {
		return err
	}
	if exists {
		return fmt.Errorf("the asset %s already exists", id)
	}

	asset := Asset{
		ID:             id,
		Color:          color,
		Size:           size,
		Owner:          owner,
		AppraisedValue: appraisedValue,
	}
	assetJSON, err := json.Marshal(asset)
	if err != nil {
		return err
	}

	return ctx.GetStub().PutState(id, assetJSON)
}

Выполнение заказа:

peer chaincode invoke -o localhost:7050 --ordererTLSHhostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca. example.com-cert.pem" -C tracychannel -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 '{ «функция»: «CreateAsset», «Аргументы»: [«актив7», «розовый», «27», «Трейси», «900»]}'

[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 tracychannel -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":"CreateAsset","Args":["asset7","pink","27","Tracy","900"]}'
2022-10-08 11:58:40.493 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200 

 Примечание. Когда параметр имеет тип int, также используются двойные кавычки, в противном случае будет сообщено об ошибке следующим образом:

Ошибка: ошибка аргумента цепного кода: json: невозможно разобрать число в поле структуры Go. Args типа string

[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 tracychannel -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":"CreateAsset","Args":["asset7","pink","27","Tracy",900]}'
Error: chaincode argument error: json: cannot unmarshal number into Go struct field .Args of type string

3. Обновление чейнкода

3.1. Регенерация зависимостей проекта

Перейдите в каталог проекта и заново создайте зависимости проекта.

иди поставщик модов

[root@localhost test-network]# cd ../asset-transfer-basic/chaincode-go/
[root@localhost chaincode]# go mod vendor

3.2. Переупаковать чейнкод

Тег пакета Chaincode обновлен с 1.0 до 2.0.

пакет цепочек жизненного цикла одноранговых узлов basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_2.0

[root@localhost test-network]# ​peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_2.0

3.3. Установите чейн-код

Следующая операция открывает 2 терминала, одна переменная среды устанавливается в организацию 1, а другая переменная среды устанавливается в организацию 2.

3.3.1 Установка переменных окружения

# Терминал 1 - переменная окружения установлена ​​на организацию 1

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD} /organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051

# Терминал 2 - переменная окружения установлена ​​на организацию 2

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD} /organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051

3.3.2. Установить чейн-код (2 организации)

И Организация 1, и Организация 2 выполняют команду для установки чейнкода:

Чейнкод жизненного цикла однорангового узла установить basic.tar.gz

[root@localhost test-network]# peer lifecycle chaincode install basic.tar.gz
2022-10-11 17:28:13.880 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nJbasic_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7\022\014marriage_2.0" > 
2022-10-11 17:28:13.880 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7

3.4 Код цепочки авторизации 

3.4.1. Проверьте статус установки чейнкода

установлен запрос кода цепи жизненного цикла однорангового узла

[root@localhost test-network]# peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: basic_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7, Label: marriage_2.0
Package ID: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7, Label: basic_1.0

3.4.2. Установка переменных среды пакета чейнкода (2 организации)

Организация 1 и Организация 2 выполняют

экспорт CC_PACKAGE_ID=basic_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7

[root@localhost test-network]# export CC_PACKAGE_ID=basic_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7

3.4.3 Код цепочки авторизации (2 организации)

Выполнены как организация 1, так и организация 2, обратите внимание: метка 2.0, а серийный номер 2

код цепочки жизненного цикла однорангового узла утвердить формуyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic  --version 2.0 --package-id $CC_PACKAGE_ID --sequence 2 --tls --cafile "${PWD }/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"

[root@localhost test-network]# peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 2.0 --package-id $CC_PACKAGE_ID --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
2022-10-11 18:09:07.883 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [e259a06ab844af518d87ddd264c0f1db7d2cb050a7cdb79d7ad3406808431e07] committed with status (VALID) at localhost:9051

3.5. Отправить код цепи

3.5.1. Отправить чейнкод

Используйте организацию 1 или организацию 2 для отправки кода цепи, примечание: метка – 2.0, а серийный номер – 2.

 код цепочки жизненного цикла однорангового узла commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 2.0 --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example .com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --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"

[root@localhost test-network]# peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID tracychannel --name basic --version 2.0 --sequence 2 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --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"
2022-10-11 19:02:18.990 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [3ae48a1b16c8295e3fbf44289447581b66828c1ddfd1ea1761219c5baca0206c] committed with status (VALID) at localhost:9051
2022-10-11 19:02:19.025 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [3ae48a1b16c8295e3fbf44289447581b66828c1ddfd1ea1761219c5baca0206c] committed with status (VALID) at localhost:7051

3.5.2. Просмотр результатов отправки

одноранговый жизненный цикл chaincode querycommitted --channelID tracychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem " -- вывод JSON

4. Используйте deployCC для развертывания кода цепочки

Вы можете напрямую использовать deployCC, предоставленный сценарием network.sh, для развертывания или обновления кода цепочки, напрямую заменяя все команды, выполняемые при развертывании (шаг 3 — упаковка, установка, авторизация и отправка) или обновлении (шаг 4).

4.1, посмотреть справку

./network.sh deployCC -h

[root@localhost test-network]# ./network.sh deployCC -h
Using docker and docker-compose
Usage: 
  network.sh deployCC [Flags]

    Flags:
    -c <channel name> - Name of channel to deploy chaincode to
    -ccn <name> - Chaincode name.
    -ccl <language> - Programming language of chaincode to deploy: go, java, javascript, typescript
    -ccv <version>  - Chaincode version. 1.0 (default), v2, version3.x, etc
    -ccs <sequence>  - Chaincode definition sequence. Must be an integer, 1 (default), 2, 3, etc
    -ccp <path>  - File path to the chaincode.
    -ccep <policy>  - (Optional) Chaincode endorsement policy using signature policy syntax. The default policy requires an endorsement from Org1 and Org2
    -cccg <collection-config>  - (Optional) File path to private data collections configuration file
    -cci <fcn name>  - (Optional) Name of chaincode initialization function. When a function is provided, the execution of init will be requested and the function will be invoked.

    -h - Print this message

 Possible Mode and flag combinations
   deployCC -ccn -ccl -ccv -ccs -ccp -cci -r -d -verbose

 Examples:
   network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ ./ -ccl javascript
   network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript

4.2. Используйте deployCC для развертывания кода цепочки 

./network.sh deployCC -c tracychannel -ccn basic -ccl go -ccv 2 -ccs 2 -ccp ../asset-transfer-basic/chaincode-go/

[root@localhost test-network]# ./network.sh deployCC -c tracychannel -ccn basic -ccl go -ccv 2 -ccs 2 -ccp ../asset-transfer-basic/chaincode-go/
Using docker and docker-compose
deploying chaincode on channel 'tracychannel'
executing with the following
- CHANNEL_NAME: tracychannel
- CC_NAME: basic
- CC_SRC_PATH: ../asset-transfer-basic/chaincode-go/
- CC_SRC_LANGUAGE: go
- CC_VERSION: 2
- CC_SEQUENCE: 2
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go/
/home/gopath/src/github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go /home/gopath/src/github.com/hyperledger/fabric-samples/test-network
/home/gopath/src/github.com/hyperledger/fabric-samples/test-network
Finished vendoring Go dependencies
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_2
+ res=0
Chaincode is packaged
Installing chaincode on peer0.org1...
Using organization 1
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2022-10-12 02:07:22.101 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nHbasic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2\022\007basic_2" > 
2022-10-12 02:07:22.101 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2
Chaincode is installed on peer0.org1
Install chaincode on peer0.org2...
Using organization 2
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2022-10-12 02:07:31.538 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nHbasic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2\022\007basic_2" > 
2022-10-12 02:07:31.538 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2
Chaincode is installed on peer0.org2
Using organization 1
+ peer lifecycle chaincode queryinstalled
+ res=0
Installed chaincodes on peer:
Package ID: marriage_5.0:5b1643320e134816113b2b56344dc62eb4f3c03ccf0922f203f5a435f089a27a, Label: marriage_5.0
Package ID: marriage_6.0:ed4871dd8ea92ada34a86177246a2b09a7f95459d4e9d693997bd55e6e946417, Label: marriage_6.0
Package ID: marriage_7.0:ae39c2a9ec16e025fb0cb202245fb90a95cc78df66c290c10c79dd903d889998, Label: marriage_7.0
Package ID: basic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2, Label: basic_2
Package ID: marriage_1.0:925646ffd9f02e51a860a94366685ebd78dbbd1416839f505fbe81c660c66266, Label: marriage_1.0
Package ID: marriage_3.0:a3479c2dabe5451cdbe7851aefa3de52c19f882ef9898a194cf88b292056e08a, Label: marriage_3.0
Package ID: marriage_4.0:4bb04c3808309e75d226c0450595b602bbc78f1dbc7edb7cc02dd8ea426d380b, Label: marriage_4.0
Package ID: marriage_8:e0f08bb9c7447f2da1efb9481ed0998278a7913993feda42981a3980153e6b9e, Label: marriage_8
Package ID: basic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426, Label: basic_1
Package ID: marriage_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7, Label: marriage_2.0
Query installed successful on peer0.org1 on channel
Using organization 1
+ 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 tracychannel --name basic --version 2 --package-id basic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2 --sequence 2
+ res=0
2022-10-12 02:07:33.638 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [f43136a5bc8ec1100d201931c4fec26084c5aed67f30c006fe1b6e0e945ebf8c] committed with status (VALID) at localhost:7051
Chaincode definition approved on peer0.org1 on channel 'tracychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 2 --sequence 2 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'tracychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 2 --sequence 2 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'tracychannel'
Using organization 2
+ 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 tracychannel --name basic --version 2 --package-id basic_2:228a0fc53601ffa1a02c38684534133de993c5e980077edc3e6d0141a9fca4a2 --sequence 2
+ res=0
2022-10-12 02:07:41.780 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [b2354d11c5a12acdc209e4d6cb36409ed1a6ee6de075d1fa274ebcb567965ea0] committed with status (VALID) at localhost:9051
Chaincode definition approved on peer0.org2 on channel 'tracychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 2 --sequence 2 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'tracychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 2 --sequence 2 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'tracychannel'
Using organization 1
Using organization 2
+ 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 tracychannel --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 2 --sequence 2
+ res=0
2022-10-12 02:07:50.017 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [46253162c9f92d8c5adbec13805139658a335e27c5d7f85396bf2753b165db6a] committed with status (VALID) at localhost:9051
2022-10-12 02:07:50.050 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [46253162c9f92d8c5adbec13805139658a335e27c5d7f85396bf2753b165db6a] committed with status (VALID) at localhost:7051
Chaincode definition committed on channel 'tracychannel'
Using organization 1
Querying chaincode definition on peer0.org1 on channel 'tracychannel'...
Attempting to Query committed status on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID tracychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'tracychannel':
Version: 2, Sequence: 2, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org1 on channel 'tracychannel'
Using organization 2
Querying chaincode definition on peer0.org2 on channel 'tracychannel'...
Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID tracychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'tracychannel':
Version: 2, Sequence: 2, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org2 on channel 'tracychannel'
Chaincode initialization is not required

4.3. Компиляция и развертывание скриптов

4.3.1 Создать файл сценария

vi install-cc.sh

[root@localhost test-network]# vi install-cc.sh

4.3.2, скомпилировать файл сценария 

#!/bin/bash

# 验证参数个数
if [ $# != 4 ]; then 
	echo "the count of paramter is not 4";
	exit;
fi

cc_name=$1        #链码名称
cc_version=$2     #版本号
cc_sequence=$3    #序号
cc_path=$4        #源码路径

./network.sh deployCC -c tracychannel -ccn $cc_name -ccl go -ccv $cc_version -ccs $cc_sequence -ccp $cc_path

Нажмите Esc, чтобы выйти из компиляции, введите: wq, чтобы сохранить файл и выйти.

4.3.3, выполнить файл сценария

./install-cc.sh базовый 1 1 ../asset-transfer-basic/chaincode-go/

 Как видно ниже, результат выполнения такой же, как и у 4.2 (номер версии отличается от серийного номера)

[root@localhost test-network]# ./install-cc.sh basic 1 1 ../asset-transfer-basic/chaincode-go/
Using docker and docker-compose
deploying chaincode on channel 'tracychannel'
executing with the following
- CHANNEL_NAME: tracychannel
- CC_NAME: basic
- CC_SRC_PATH: ../asset-transfer-basic/chaincode-go/
- CC_SRC_LANGUAGE: go
- CC_VERSION: 1
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go/
/home/gopath/src/github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go /home/gopath/src/github.com/hyperledger/fabric-samples/test-network
/home/gopath/src/github.com/hyperledger/fabric-samples/test-network
Finished vendoring Go dependencies
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1
+ res=0
Chaincode is packaged
Installing chaincode on peer0.org1...
Using organization 1
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2022-10-12 02:02:24.752 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nHbasic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426\022\007basic_1" > 
2022-10-12 02:02:24.753 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426
Chaincode is installed on peer0.org1
Install chaincode on peer0.org2...
Using organization 2
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2022-10-12 02:02:34.474 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nHbasic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426\022\007basic_1" > 
2022-10-12 02:02:34.474 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426
Chaincode is installed on peer0.org2
Using organization 1
+ peer lifecycle chaincode queryinstalled
+ res=0
Installed chaincodes on peer:
Package ID: marriage_1.0:925646ffd9f02e51a860a94366685ebd78dbbd1416839f505fbe81c660c66266, Label: marriage_1.0
Package ID: marriage_5.0:5b1643320e134816113b2b56344dc62eb4f3c03ccf0922f203f5a435f089a27a, Label: marriage_5.0
Package ID: marriage_6.0:ed4871dd8ea92ada34a86177246a2b09a7f95459d4e9d693997bd55e6e946417, Label: marriage_6.0
Package ID: marriage_7.0:ae39c2a9ec16e025fb0cb202245fb90a95cc78df66c290c10c79dd903d889998, Label: marriage_7.0
Package ID: basic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426, Label: basic_1
Package ID: marriage_2.0:f7ee6e4bff33e4ad7e28060f5d6528550489f1409d0acbd44236974a699ef6a7, Label: marriage_2.0
Package ID: marriage_3.0:a3479c2dabe5451cdbe7851aefa3de52c19f882ef9898a194cf88b292056e08a, Label: marriage_3.0
Package ID: marriage_4.0:4bb04c3808309e75d226c0450595b602bbc78f1dbc7edb7cc02dd8ea426d380b, Label: marriage_4.0
Package ID: marriage_8:e0f08bb9c7447f2da1efb9481ed0998278a7913993feda42981a3980153e6b9e, Label: marriage_8
Query installed successful on peer0.org1 on channel
Using organization 1
+ 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 tracychannel --name basic --version 1 --package-id basic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426 --sequence 1
+ res=0
2022-10-12 02:02:36.576 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [df1759d59ddfb01450b6fa11f75410f36fa826020d716b7fe17537b1aea09b05] committed with status (VALID) at localhost:7051
Chaincode definition approved on peer0.org1 on channel 'tracychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 1 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'tracychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 1 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'tracychannel'
Using organization 2
+ 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 tracychannel --name basic --version 1 --package-id basic_1:edf534ff779c873877e0552c894053a1f02263fc7213ac8b91425ec014bef426 --sequence 1
+ res=0
2022-10-12 02:02:44.715 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [b52d52b514da29cb6a6234f5fe1e2e05f8fb181da8f46e7548efcccbd593dd47] committed with status (VALID) at localhost:9051
Chaincode definition approved on peer0.org2 on channel 'tracychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 1 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'tracychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'tracychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID tracychannel --name basic --version 1 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'tracychannel'
Using organization 1
Using organization 2
+ 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 tracychannel --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 --sequence 1
+ res=0
2022-10-12 02:02:52.972 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [ee426616c430d4e75f901cae0f59c8942b016beaf2c0e8f1808a0e22b45b3643] committed with status (VALID) at localhost:7051
2022-10-12 02:02:52.982 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [ee426616c430d4e75f901cae0f59c8942b016beaf2c0e8f1808a0e22b45b3643] committed with status (VALID) at localhost:9051
Chaincode definition committed on channel 'tracychannel'
Using organization 1
Querying chaincode definition on peer0.org1 on channel 'tracychannel'...
Attempting to Query committed status on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID tracychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'tracychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org1 on channel 'tracychannel'
Using organization 2
Querying chaincode definition on peer0.org2 on channel 'tracychannel'...
Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID tracychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'tracychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org2 on channel 'tracychannel'
Chaincode initialization is not required

5. Резюме

  • Анализ кода, создание чейнкода, запуск и хранение
  • Запустите тестовую сеть, одновременно создайте канал и разверните чейн-код в канале ./network.sh up createChannel
  • Генерация зависимостей проекта GO111MODULE=on go mod vendor
  • Пакет chaincode жизненного цикла однорангового кода упаковки
  • Установите чейнкод однорангового жизненного цикла кода цепочки (разные организации устанавливают отдельно)
  • Проверьте результат установки чейнкода: запрос чейнкода жизненного цикла однорангового узла установлен.
  • Код цепочки авторизации одноранговый жизненный цикл chaincode appendformyorg (разные организации авторизуют отдельно)
  • Проверьте результат авторизации чейнкода: одноранговый жизненный цикл чейнкода checkcommitreadiness
  • Фиксация цепочки кодов жизненного цикла одноранговых узлов
  • Просмотр результатов отправки чейнкода: запрос чейнкода жизненного цикла однорангового узла выполнен
  • Вызов чейнкода для записи данных: вызов чейнкода пира
  • Просмотр данных чтения чейнкода: запрос однорангового чейнкода
  • Обновление цепного кода: обратите внимание на номер версии обновления и последовательность серийных номеров.
  • Используйте deployCC для развертывания чейнкода: ./network.sh deployCC

рекомендация

отblog.csdn.net/ling1998/article/details/127202209