fabric2.2.0内部链码安装及调用(生产环境)

生成创世块 (在orderer节点上生成)在configtx.yaml文件目录

configtxgen -profile OrgsOrdererGenesis -outputBlock /tmp/hyperledger/org0/orderer/genesis.block -channelID syschannel  (系统名)

创建通道交易 (在orderer节点上生成) 将mycc.tx文件复制到创建通道的peer节点–在configtx.yaml文件目录

configtxgen -profile TwoOrgsChannel -outputCreateChannelTx  /etc/hyperledger/organizations/mycc.tx -channelID mycc  //指定链码名称

导入证书

root@peer0:/etc/hyperledger/fabric
# exportCORE_PEER_MSPCONFIGPATH=/etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/users/Admin@org1.hnpmct.com/msp

打包链码

peer lifecycle chaincode package test.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label test_1

创建通道,并且需要将生成的mycc.block复制到其他的组织节点上,然后执行加入通道

peer channel create -o orderer.hnpmct.com:7050 -c mycc --ordererTLSHostnameOverride orderer.hnpmct.com -f /etc/hyperledger/fabric/mycc.tx --outputBlock /etc/hyperledger/fabric/mycc.block --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem
root@peer0:/etc/hyperledger/fabric# ls
admin  channel.tx  core.yaml  fabcar.tar.gz  msp  mychannel.block  tls

加入通道

root@peer0:/etc/hyperledger/fabric# peer channel join -b /etc/hyperledger/fabric/mycc.block
2020-08-19 16:32:52.129 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-19 16:32:52.159 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
root@peer0:/etc/hyperledger/fabric# peer channel list
2020-08-19 16:33:01.036 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Channels peers has joined: 
mychannel

安装链码 (所有节点都需要,orderer节点不需要)

root@peer0:/etc/hyperledger/fabric# peer lifecycle chaincode install fabcar.tar.gz

查询包ID

root@peer0:/etc/hyperledger/fabric# peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506, Label: fabcar_1

配置

root@peer0:/etc/hyperledger/fabric# export CC_PACKAGE_ID=fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506

授权

root@peer0:/etc/hyperledger/fabric#  peer lifecycle chaincode approveformyorg -o 192.168.1.86:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem
2020-08-19 16:42:35.236 CST [chaincodeCmd] ClientWait -> INFO 001 txid [e4c0b2f6852a95d76c9ab2c080bf059246e26fb18ea6c1f82e69ff8d79af5aae] committed with status (VALID) at 

检查

root@peer0:/etc/hyperledger/fabric#  peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem --output json
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true,
		"Org3MSP": true,
		"Org4MSP": true
	}
}

提交链码到通道上 (某个peer节点上运行就可以,其他节点同步)

peer lifecycle chaincode commit -o orderer.hnpmct.com:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem --peerAddresses peer0.org1.hnpmct.com:7051 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/peers/peer0.org1.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org2.hnpmct.com:7151 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org2.hnpmct.com/peers/peer0.org2.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org3.hnpmct.com:7251 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org3.hnpmct.com/peers/peer0.org3.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org4.hnpmct.com:7351 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org4.hnpmct.com/peers/peer0.org4.hnpmct.com/tls/ca.crt
peer lifecycle chaincode commit -o orderer.hnpmct.com:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile 
/etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem 
--peerAddresses peer0.org1.hnpmct.com:7051 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/peers/peer0.org1.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org2.hnpmct.com:7151 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org2.hnpmct.com/peers/peer0.org2.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org3.hnpmct.com:7251 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org3.hnpmct.com/peers/peer0.org3.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org4.hnpmct.com:7351 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org4.hnpmct.com/peers/peer0.org4.hnpmct.com/tls/ca.crt

调用链码初始化

peer chaincode invoke -o orderer.hnpmct.com:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --tls --cafile  /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem -C mychannel -n fabcar --peerAddresses peer0.org1.hnpmct.com:7051 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/peers/peer0.org1.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org2.hnpmct.com:7151 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org2.hnpmct.com/peers/peer0.org2.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org3.hnpmct.com:7251 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org3.hnpmct.com/peers/peer0.org3.hnpmct.com/tls/ca.crt  --peerAddresses peer0.org4.hnpmct.com:7351 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org4.hnpmct.com/peers/peer0.org4.hnpmct.com/tls/ca.crt -c '{"function":"initLedger","Args":[]}'

查询

 peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值