注意:Fabric 2.0已发布,请参考这篇文章 【fabric源码】Goland/Vscode调试Hyperledger Fabric 2.0源码、单机网络(傻瓜式调试)
启动一个peer和一个node,用example02作为例子,安装、初始化、调用、查询链码。
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric.git
git checkout release-1.4
git clone https://github.com/hyperledger/fabric-samples
127.0.0.1 peer
127.0.0.1 orderer
1.在fabric项目下创建dev-network
目录
2.将fabric项目下sampleconfig
文件夹下的所有文件复制到 dev-network
3.修改 core.yaml
中fileSystemPath = $GOPATH/src/github.com/hyperledger/fabric/dev-network/production/peer
4.修改 orderer.yaml
中 Location =$GOPATH/src/github.com/hyperledger/fabric/dev-network/production/orderer
5.在 dev-network
新建 config
目录,并复制fabric-samples
项目中的chaincode-docker-devmode
下的myc.tx
和 orderer.block
文件到config
目录中
注意修改GOPATH
{
"version": "0.2.0",
"configurations": [
{
"name": "orderer",
"type": "go",
"request": "launch",
"mode": "debug",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/orderer",
"env": {
"ORDERER_GENERAL_LISTENADDRESS":"0.0.0.0",
"ORDERER_GENERAL_GENESISMETHOD":"file",
"ORDERER_GENERAL_GENESISFILE":"${workspaceRoot}/dev-network/config/orderer.block",
"ORDERER_GENERAL_LOCALMSPID":"DEFAULT",
"ORDERER_GENERAL_LOCALMSPDIR":"${workspaceRoot}/dev-network/msp",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": []
},
{
"name": "peer",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2346,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"peer",
"CORE_PEER_MSPCONFIGPATH": "${workspaceRoot}/dev-network/msp",
"CORE_PEER_ADDRESS":"127.0.0.1:7051",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["node","start","--peer-chaincodedev=true"],
"showLog": true
},
{
"name": "channel create",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2347,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"cli",
"CORE_PEER_MSPCONFIGPATH": "${workspaceRoot}/dev-network/msp",
"CORE_PEER_ADDRESS":"127.0.0.1:7051",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["channel","create","-c", "myc","-f","${workspaceRoot}/dev-network/config/myc.tx","-o","127.0.0.1:7050"],
"showLog": true
},
{
"name": "channel join",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2348,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"cli",
"CORE_PEER_MSPCONFIGPATH": "${workspaceRoot}/dev-network/msp",
"CORE_PEER_ADDRESS":"127.0.0.1:7051",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["channel","join","-b","myc.block"],
"showLog": true
},
{
"name": "chaincode install",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2349,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"cli",
"CORE_PEER_MSPCONFIGPATH": "${workspaceRoot}/dev-network/msp",
"CORE_PEER_ADDRESS":"127.0.0.1:7051",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["chaincode","install","-p","github.com/hyperledger/fabric/examples/chaincode/go/example02","-n" ,"mycc", "-v", "1.0"],
"showLog": true
},
{
"name": "run chaincode example02",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2353,
"host": "127.0.0.1",
"program": "${workspaceRoot}/examples/chaincode/go/example02/cmd",
"env": {
"CORE_PEER_ADDRESS":"127.0.0.1:7052",
"CORE_CHAINCODE_ID_NAME":"mycc:1.0"
},
"args": [],
"showLog": true
},
{
"name": "chaincode instantiate",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2350,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"cli",
"CORE_PEER_MSPCONFIGPATH": "${workspaceRoot}/dev-network/msp",
"CORE_PEER_ADDRESS":"127.0.0.1:7051", "FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["chaincode","instantiate","-n", "mycc", "-v" ,"1.0" ,"-c", "{\"Args\":[\"init\",\"a\",\"100\",\"b\",\"200\"]}" ,"-C", "myc"],
"showLog": true
},
{
"name": "chaincode invoke",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2351,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"cli",
"CORE_PEER_MSPCONFIGPATH": "${workspaceRoot}/dev-network/msp",
"CORE_PEER_ADDRESS":"127.0.0.1:7051",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["chaincode","invoke","-n", "mycc" ,"-c", "{\"Args\":[\"invoke\",\"a\",\"b\",\"10\"]}" ,"-C", "myc"],
"showLog": true
},
{
"name": "chaincode query",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2352,
"host": "127.0.0.1",
"program": "${workspaceRoot}/peer",
"env": {
"CORE_PEER_LOCALMSPID":"DEFAULT",
"CORE_PEER_ID":"cli",
"CORE_PEER_ADDRESS":"127.0.0.1:7051",
"FABRIC_CFG_PATH":"${workspaceRoot}/dev-network",
},
"args": ["chaincode","query","-n", "mycc" ,"-c", "{\"Args\":[\"query\",\"a\"]}" ,"-C", "myc"],
"showLog": true
}
]
}