《HyperLedger Fabric 实战》—— 十七、升级 Fabric 1.2 —— 6、部署验证合约

1、加载智能合约(以 211 机器为例)

拷贝~/fabric/examples/chaincode/go/文件夹下的example02marbles02两个目录到~/fabric/aberic/chaincode/go/目录下。

重启 Peer 服务。

docker-compose -f docker-peer0.org1.yaml down --volumes
docker-compose -f docker-peer0.org1.yaml up

2、安装实例化合约

登入 211 机器的 cli 容器。

docker exec -it cli bash

由于刚刚我们彻底清除了 peer 容器,所以这里需要重新加入通道。

cp channel-artifacts/mychannel.block ./
peer channel join -b mychannel.block

安装实例化合约

peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/aberic/chaincode/go/example02/cmd
peer chaincode instantiate -o orderer1.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"

3、查询、交易、验证合约

peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer1.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

4、验证 CouchDB

安装、实例化 marbles02 合约,该合约会自动基于 couchdb 创建索引。

peer chaincode install -n marble1 -v 1.0 -p github.com/hyperledger/fabric/aberic/chaincode/go/marbles02

实例化若失败,可稍等几秒钟,可能是安装还没有完成。

peer chaincode instantiate -o orderer1.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n marble1 -c '{"Args":[]}' -P "OR ('Org1MSP.peer', 'Org2MSP.peer')" -v 1.0

验证合约,若成功,也是变相验证了 couchdb。

peer chaincode invoke -C mychannel -n marble1 -c '{"Args":["initMarble","marble1","blue","35","tom"]}' -o orderer1.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peer chaincode invoke -C mychannel -n marble1 -c '{"Args":["initMarble","marble2","red","50","tom"]}' -o orderer1.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peer chaincode invoke -C mychannel -n marble1 -c '{"Args":["initMarble","marble3","blue","70","tom"]}' -o orderer1.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peer chaincode query -C mychannel -n marble1 -c '{"Args":["readMarble","marble1"]}'
peer chaincode query -C mychannel -n marble1 -c '{"Args":["queryMarblesByOwner","tom"]}'    # need couchdb

5、验证 Peer 集群其他节点

复制第一步的加载合约,和第二步的安装合约,注意,不必再行实例化,之后直接进行查询。

后面我们尝试动态增加组织。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值