Hyperledger Fabric 弹珠资产管理 chaincode 测试

版权声明:博客中的文章版权归博主所有,未经授权,禁止转载,转载请注明出处

部署链码

将 弹珠资产管理系统的链码拷贝到fabric-samples/chaincode

进入链码开发目录

cd fabric-samples/chaincode-docker-devmode

打开3个终端

终端1

$ docker-compose -f docker-compose-simple.yaml up

终端2

$ docker exec -it chaincode bash

$ cd chaincode006

$ go build

$ CORE_PEER_ADDRESS=peer:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode006

终端3

$ docker exec -it cli bash

$ peer chaincode install -p chaincodedev/chaincode/chaincode006 -n mycc -v 0

$ peer chaincode instantiate -n mycc -v 0 -c '{"Args":[]}' -C myc

$ peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble1","blue","35","tom"]}' -C myc

$ peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble2","red","50","tom"]}' -C myc

$ peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble3","blue","70","tom"]}' -C myc

$ peer chaincode query -n mycc -c '{"Args":["readMarble","marble1"]}' -C myc

$ peer chaincode invoke -n mycc -c '{"Args":["transferMarble","marble2","jerry"]}' -C myc

$ peer chaincode query -n mycc -c '{"Args":["readMarble","marble2"]}' -C myc

$ peer chaincode invoke -n mycc -c '{"Args":["deleteMarble","marble1"]}' -C myc

$ peer chaincode query -n mycc -c '{"Args":["getMarblesByRange","marble1","marble3"]}' -C myc

$ peer chaincode query -n mycc -c '{"Args":["getHistoryForMarble","marble1"]}' -C myc

$ peer chaincode query -n mycc -c '{"Args":["queryMarblesByOwner","tom"]}' -C myc

富查询报错

富查询需要配置 CouchDB

chaincode for develop 配置 CouchDB

修改 chaincode-docker-devmode/docker-compose-simple.yaml 配置

# peer 加入如下配置

environment:
# 添加以下内容

- CORE_LEDGER_STATE_STATEDATABASE=CouchDB - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984 - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME= - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD= 
depends_on:
- orderer - couchdb
couchdb:
container_name: couchdb
image: hyperledger/fabric-couchdb
# Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password # for CouchDB. This will prevent CouchDB from operating in an "Admin Party" mode. environment: - COUCHDB_USER= - COUCHDB_PASSWORD= ports: - 5984:5984

关注公众号

你可能感兴趣的:(Hyperledger,Fabric)