本文使用test-network进行描述,仅仅了解其chaincode的操作流程,如果当前环境已经部署了test-network,建议执行./network.sh down进行资源删除后,再进行操作
1.启动测试环境并创建一个通道
通过执行一下命令,会创建两个org组织,一个order节点,并且创建一个通道channel1,并将两个org组织的peer节点加入到channel1中,并且设置anchor peer锚节点。
./network.sh up createChannel -c channel1
截取一部分日志,看看其大致流程,首先
/Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/../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
/Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2022-01-04 19:41:09.305 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-01-04 19:41:09.320 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2022-01-04 19:41:09.320 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
2022-01-04 19:41:09.320 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/configtx/configtx.yaml
2022-01-04 19:41:09.322 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2022-01-04 19:41:09.322 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
第二部分,创建通道
Generating channel create transaction 'channel1.tx'
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel1.tx -channelID channel1
2022-01-04 19:41:26.275 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-01-04 19:41:26.291 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/configtx/configtx.yaml
2022-01-04 19:41:26.292 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2022-01-04 19:41:26.294 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
+ res=0
Creating channel channel1
Using organization 1
+ peer channel create -o localhost:7050 -c channel1 --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/channel1.tx --outputBlock ./channel-artifacts/channel1.block --tls --cafile /Users/zhaojunwei/workspace/hyfa/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
2022-01-04 19:41:29.380 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 19:41:29.399 CST [cli.common] readBlock -> INFO 002 Expect block, but got status: &{NOT_FOUND}
2022-01-04 19:41:29.405 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2022-01-04 19:41:29.609 CST [cli.common] readBlock -> INFO 004 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-01-04 19:41:29.615 CST [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized
2022-01-04 19:41:29.819 CST [cli.common] readBlock -> INFO 006 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-01-04 19:41:29.825 CST [channelCmd] InitCmdFactory -> INFO 007 Endorser and orderer connections initialized
2022-01-04 19:41:30.030 CST [cli.common] readBlock -> INFO 008 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-01-04 19:41:30.036 CST [channelCmd] InitCmdFactory -> INFO 009 Endorser and orderer connections initialized
2022-01-04 19:41:30.244 CST [cli.common] readBlock -> INFO 00a Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-01-04 19:41:30.251 CST [channelCmd] InitCmdFactory -> INFO 00b Endorser and orderer connections initialized
2022-01-04 19:41:30.457 CST [cli.common] readBlock -> INFO 00c Received block: 0
Channel 'channel1' created
第三部分,将两个组织中的节点加入到通道中,
Joining org1 peer to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/channel1.block
+ res=0
2022-01-04 19:41:33.530 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 19:41:33.552 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
Joining org2 peer to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/channel1.block
+ res=0
2022-01-04 19:41:36.619 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 19:41:36.641 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
最后设置锚节点
Setting anchor peer for org1...
Using organization 1
Fetching channel config for channel channel1
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 channel1 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-01-04 11:41:37.024 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 11:41:37.026 UTC [cli.common] readBlock -> INFO 002 Received block: 0
2022-01-04 11:41:37.027 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 0
2022-01-04 11:41:37.028 UTC [cli.common] readBlock -> INFO 004 Received block: 0
Decoding config block to JSON and isolating config to Org1MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block
+ jq '.data.data[0].payload.data.config'
Generating anchor peer update transaction for Org1 on channel channel1
+ 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
+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config
+ configtxlator compute_update --channel_id channel1 --original original_config.pb --updated modified_config.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"channel1", "type":2}},"data":{"config_update":{' '"channel_id":' '"channel1",' '"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":' '"1"' '}' '},' '"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":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope
2022-01-04 11:41:37.241 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 11:41:37.252 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org1MSP' on channel 'channel1'
Setting anchor peer for org2...
Using organization 2
Fetching channel config for channel channel1
Using organization 2
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 channel1 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-01-04 11:41:37.615 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 11:41:37.617 UTC [cli.common] readBlock -> INFO 002 Received block: 1
2022-01-04 11:41:37.618 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 1
2022-01-04 11:41:37.619 UTC [cli.common] readBlock -> INFO 004 Received block: 1
Decoding config block to JSON and isolating config to Org2MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block
+ jq '.data.data[0].payload.data.config'
+ 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
Generating anchor peer update transaction for Org2 on channel channel1
+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config
+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config
+ configtxlator compute_update --channel_id channel1 --original original_config.pb --updated modified_config.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"channel1", "type":2}},"data":{"config_update":{' '"channel_id":' '"channel1",' '"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":' '"1"' '}' '},' '"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":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope
2022-01-04 11:41:37.801 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-01-04 11:41:37.811 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'channel1'
Channel 'channel1' joined
至此,将两个组织加入到通道中的操作,完成了。
2.打包chaincode
peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0
上面的命令会将合约代码打包成tar文件,--path指定代码文件的路径,label是打包的标签,这个标签在后续中会使用到。
3.安装chaincode
首先在org1组织中进行安装
test-network git:(ad8fc2f) ✗ export CORE_PEER_TLS_ENABLED=true
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_LOCALMSPID="Org1MSP"
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_ADDRESS=localhost:7051
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode install basic.tar.gz
首先设置好org的环境变量,然后执行install操作。持续几秒后,安装成功,输入打包标识
2022-01-05 09:51:43.791 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nJbasic_1.0:950c4b082bc8229268015e94e544db76afeb7086fbb52980387bd5e1bd0b41b3\022\tbasic_1.0" >
2022-01-05 09:51:43.793 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:950c4b082bc8229268015e94e544db76afeb7086fbb52980387bd5e1bd0b41b3
打包标识后续需要用到。
同样的操作,需要在org2组织中进行,让chaincode安装在org2组织中
test-network git:(ad8fc2f) ✗ export CORE_PEER_LOCALMSPID="Org2MSP"
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_ADDRESS=localhost:9051
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode install basic.tar.gz
\
2022-01-05 10:07:30.814 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nJbasic_1.0:950c4b082bc8229268015e94e544db76afeb7086fbb52980387bd5e1bd0b41b3\022\tbasic_1.0" >
2022-01-05 10:07:30.816 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:950c4b082bc8229268015e94e544db76afeb7086fbb52980387bd5e1bd0b41b3
安装完成后,也会产生打包标识,看看标识,发现没,似乎长的一样
4.Approve chaincode
在Approve之前,我们可以查看一下,chaincode是否已经安装到当前组织
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: basic_1.0:950c4b082bc8229268015e94e544db76afeb7086fbb52980387bd5e1bd0b41b3, Label: basic_1.0
在执行Approve之前,还需要设置CC_PACKAGE_ID,
export CC_PACKAGE_ID=basic_1.0:950c4b082bc8229268015e94e544db76afeb7086fbb52980387bd5e1bd0b41b3
至此就可以执行
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID channel1 --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-01-05 10:13:21.791 CST [chaincodeCmd] ClientWait -> INFO 001 txid [2eedf23dff9181ea678e975f6d1c29d87d03edff24434854be4510231056cc02] committed with status (VALID) at localhost:9051
因为当前处在org2组织下,所以该命令执行的是org2组织的approve操作。后面还需要在org1中执行approve操作,但是在org1中执行approve操作之前,我们先来看看这个命令的参数
- channelID: 通道的名称
- name: chaincode名称
- version: 当前chaincode的版本,每次升级都要增加该版本号
- package-id: 打包产生的包标识
- sequence:和version一样,每次升级都要增加
切换到org1后,再次执行approve操作
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_LOCALMSPID="Org1MSP"
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
➜ test-network git:(ad8fc2f) ✗ export CORE_PEER_ADDRESS=localhost:7051
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID channel1 --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-01-05 10:21:16.747 CST [chaincodeCmd] ClientWait -> INFO 001 txid [9cb9862c69145fe1da17ee560dd9ed92f91866293a9da12cb4c94a4167f43dfb] committed with status (VALID) at localhost:7051
5.提交chaincode
在提交之前,可以使用checkcommitreadiness查看chaincode是否已经被approve
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode checkcommitreadiness --channelID channel1 --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
}
}
至此,就可以执行commit操作了
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID channel1 --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-01-05 10:26:05.414 CST [chaincodeCmd] ClientWait -> INFO 001 txid [c7666c836d6b65f3709c4faf013c9bccbe0aa399429e1e10ddc89494ba78966b] committed with status (VALID) at localhost:9051
2022-01-05 10:26:05.419 CST [chaincodeCmd] ClientWait -> INFO 002 txid [c7666c836d6b65f3709c4faf013c9bccbe0aa399429e1e10ddc89494ba78966b] committed with status (VALID) at localhost:7051
你可以使用如下命令测试,chaincode是否已经成功提交到channel
➜ test-network git:(ad8fc2f) ✗ peer lifecycle chaincode querycommitted --channelID channel1 --name basic --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Committed chaincode definition for chaincode 'basic' on channel 'channel1':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
6.invoke chaincode
➜ test-network git:(ad8fc2f) ✗ 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 channel1 -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-01-05 10:31:32.995 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
查询chaicode
➜ test-network git:(ad8fc2f) ✗ peer chaincode query -C channel1 -n basic -c '{"Args":["GetAllAssets"]}'
[{"ID":"asset1","color":"blue","size":5,"owner":"Tomoko","appraisedValue":300},{"ID":"asset2","color":"red","size":5,"owner":"Brad","appraisedValue":400},{"ID":"asset3","color":"green","size":10,"owner":"Jin Soo","appraisedValue":500},{"ID":"asset4","color":"yellow","size":10,"owner":"Max","appraisedValue":600},{"ID":"asset5","color":"black","size":15,"owner":"Adriana","appraisedValue":700},{"ID":"asset6","color":"white","size":15,"owner":"Michel","appraisedValue":800}]
7.升级chaincode
整个流程和部署chaincode是一样的,包括packeage, approve, commit过程。需要注意的是,升级时,sequence和version参数需要增加1.每次升级都要加1.