我已经创建了一个基本网络,其中包含对等点、沙发 DB、订购者和 CA。能够启动网络,但是在尝试安装用 typescript 编写的链代码时,它会引发以下错误。
docker-compose.yaml:
version: "2"
networks:
miqlave:
services:
ca.miqlave.com:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca.miqlave.com
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.suja.miqlave.com-cert.pem
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/7173c628839f14e9b1e4dbf6f73e60798c8fcf4a38cf9a6453080b0363d6a0cc_sk
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start -b admin:adminpw'
volumes:
- ./crypto-config/peerOrganizations/suja.miqlave.com/ca/:/etc/hyperledger/fabric-ca-server-config
container_name: ca.miqlave.com
networks:
- miqlave
orderer.miqlave.com:
container_name: orderer.miqlave.com
image: hyperledger/fabric-orderer
environment:
- FABRIC_LOGGING_SPEC=info
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
command: orderer
ports:
- 7050:7050
volumes:
- ./config/:/etc/hyperledger/configtx
- ./crypto-config/ordererOrganizations/miqlave.com/orderers/orderer.miqlave.com/:/etc/hyperledger/msp/orderer
- ./crypto-config/peerOrganizations/suja.miqlave.com/peers/peer0.suja.miqlave.com/:/etc/hyperledger/msp/peerOrg1
networks:
- miqlave
peer0.suja.miqlave.com:
container_name: peer0.suja.miqlave.com
image: hyperledger/fabric-peer
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer0.suja.miqlave.com
- FABRIC_LOGGING_SPEC=info
- CORE_CHAINCODE_LOGGING_LEVEL=info
- CORE_PEER_LOCALMSPID=SujaMSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_ADDRESS=peer0.suja.miqlave.com:7051
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_miqlave
- CORE_LEDGER_STATE_STATEDATABASE=CouchDB
- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start
# command: peer node start --peer-chaincodedev=true
ports:
- 7051:7051
volumes:
- /var/run/:/host/var/run/
- ./crypto-config/peerOrganizations/suja.miqlave.com/peers/peer0.suja.miqlave.com/msp:/etc/hyperledger/msp/peer
- ./crypto-config/peerOrganizations/suja.miqlave.com/users:/etc/hyperledger/msp/users
- ./config:/etc/hyperledger/configtx
# - ./SmartContract:/opt/gopath/src/github.com/
depends_on:
- orderer.miqlave.com
- couchdb
networks:
- miqlave
couchdb:
container_name: couchdb
image: hyperledger/fabric-couchdb
environment:
- COUCHDB_USER=
- COUCHDB_PASSWORD=
ports:
- 5984:5984
networks:
- miqlave
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- FABRIC_LOGGING_SPEC=info
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.suja.miqlave.com:7051
- CORE_PEER_LOCALMSPID=SujaMSP
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/suja.miqlave.com/users/Admin@suja.miqlave.com/msp
- CORE_CHAINCODE_KEEPALIVE=10
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
networks:
- miqlave
我能够成功启动网络,使用以下命令创建通道并将对等方添加到通道:
- docker-compose -f docker-compose.yml up -d ca.miqlave.com orderer.miqlave.com peer0.suja.miqlave.com couchdb
- docker exec -e "CORE_PEER_LOCALMSPID=SujaMSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@suja.miqlave.com/msp" peer0.suja.miqlave.com peer channel create -o orderer.miqlave.com:7050 -c miqlavechannel -f /etc/hyperledger/configtx/channel.tx
- docker exec -e "CORE_PEER_LOCALMSPID=SujaMSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@suja.miqlave.com/msp" peer0.suja.miqlave.com peer channel join -b miqlavechannel.block
上述命令执行成功。使用以下命令安装链码时,超级账本会抛出错误。
部署合同.sh:
CC_SRC_LANGUAGE = "typescript"
CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
CC_SRC_PATH=/opt/gopath/src/github.com/chaincode #/fabcar/typescript
echo Compiling TypeScript code into JavaScript ...
pushd ../SmartContract/typescript/
npm install
npm run build
popd
echo Finished compiling TypeScript code into JavaScript
CONFIG_ROOT=/opt/gopath/src/github.com/hyperledger/fabric/peer
ORG1_MSPCONFIGPATH=${CONFIG_ROOT}/crypto-config/peerOrganizations/suja.miqlave.com/users/Admin@suja.miqlave.com/msp
ORG1_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto-config/peerOrganizations/suja.miqlave.com/peers/peer0.suja.miqlave.com/tls/ca.crt
ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto-config/ordererOrganizations/miqlave.com/orderers/orderer.miqlave.com/msp/tlscacerts/tlsca.miqlave.com-cert.pem
echo "Installing smart contract on peer0.suja.miqlave.com"
docker exec \
-e CORE_PEER_LOCALMSPID=SujaMSP \
-e CORE_PEER_ADDRESS=peer0.suja.miqlave.com:7051 \
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE} \
peer0.suja.miqlave.com \
peer chaincode install \
-n miqlavecc \
-v 1.0 \
-p "$CC_SRC_PATH" \
-l "$CC_RUNTIME_LANGUAGE"