创建network
cd /opt/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/180925
mkdir 180925
cd 180925
生成证书
cp ../first-network/crypto-config.yaml ./
cryptogen generate --config==crypto-config.yaml
生成genesis block
cp ../first-network/configtx.yaml ./
mkdir channel-artifacts
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock channel-artifacts/genesis.block
创建channel
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx channel-artifacts/channel.tx -channelID mychannel
更新anchor peer
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
启动docker container
cp ../first-network/docker-compose-cli.yaml ./
cp -r ../first-network/base ./
docker rm -f $(docker ps -a -q)
IMAGE_TAG=latest COMPOSE_PROJECT_NAME=180925 docker-compose -f docker-compose-cli.yaml up -d
进入docker container
docker exec -it cli bash
peer0.org1创建channel
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer channel create -c mychannel -f channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem
各peer加入channel
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer channel join -b mychannel.block
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_ADDRESS=peer1.org1.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer channel join -b mychannel.block
CORE_PEER_LOCALMSPID=Org2MSP CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp peer channel join -b mychannel.block
CORE_PEER_LOCALMSPID=Org2MSP CORE_PEER_ADDRESS=peer1.org2.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp peer channel join -b mychannel.block
各peer安装chaincode
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.0 -p github.com/chaincode/180925
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_ADDRESS=peer1.org1.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.0 -p github.com/chaincode/180925
CORE_PEER_LOCALMSPID=Org2MSP CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.0 -p github.com/chaincode/180925
CORE_PEER_LOCALMSPID=Org2MSP CORE_PEER_ADDRESS=peer1.org2.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.0 -p github.com/chaincode/180925
部署chaincode
peer chaincode instantiate -n 180925 -v 1.0 -C mychannel -c '{"args":["Init"]}' --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem -P "OR('Org1MSP.member','Org2MSP.member')"
调用chaincode
peer chaincode invoke -n 180925 -C mychannel -c '{"args":["recordFish","fish1","38A","67.0006 -70.5476","wang"]}' --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem
更新chaincode
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.1 -p github.com/chaincode/180925
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_ADDRESS=peer1.org1.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.1 -p github.com/chaincode/180925
CORE_PEER_LOCALMSPID=Org2MSP CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.1 -p github.com/chaincode/180925
CORE_PEER_LOCALMSPID=Org2MSP CORE_PEER_ADDRESS=peer1.org2.example.com:7051 CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp peer chaincode install -n 180925 -v 1.1 -p github.com/chaincode/180925
peer chaincode upgrade -n 180925 -v 1.1 -C mychannel -c '{"args":["Init"]}' --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem -P "OR('Org1MSP.member','Org2MSP.member')"