通过fabric sample中的test-network-k8s和chaincode service在vscode调试智能合约。 合约选用fabric sample中的chaincode-external
127.0.0.1 host.docker.internal > /etc/hosts合约配置
{
"address": "host.docker.internal:9999",
"dial_timeout": "10s",
"tls_required": false
}
启动test-network-k8s指向位于host.docker.internal:9999的合约
$ ./network up $ ./network channel create $ export TEST_NETWORK_CHAINCODE_NAME=asset-transfer-basic-debug $ export TEST_NETWORK_CHAINCODE_IMAGE=localhost:5000/asset-transfer-basic $ ./network chaincode install Installing chaincode "asset-transfer-basic-debug": ✅ - Packaging chaincode folder chaincode/asset-transfer-basic-debug ... ✅ - Transferring chaincode archive to org1 ... ✅ - Installing chaincode for org org1 ... - Chaincode is installed with CHAINCODE_ID=basic_1.0:159ed2f227586f40c5804e157919903fda2b861488f35eefb365eb9d85a73da3配置vscode启动器监听host.docker.internal:9999并且绑定合约id basic_1.0:159ed2f227586f40c5804e157919903fda2b861488f35eefb365eb9d85a73da3
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
//"program": "${fileDirname}"
"program": "${workspaceFolder}",
"env": {
"CHAINCODE_ID": "basic_1.0:a265635539e1fb9358664e124c95757d9253534902ac00f880b4eb0231613667",
"CHAINCODE_SERVER_ADDRESS": "0.0.0.0:9999",
},
"args": []
}
]
}
启动vscode暂停在服务启动的断点
释放vscode debug模式的断点
在test-network-k8s中发起调用
$ ./network chaincode activate
./network chaincode invoke '{"Args":["CreateAsset","1","blue","35","tom","1000"]}'
./network chaincode query '{"Args":["ReadAsset","1"]}'
完成(进入到业务上的断点)
提示
在本模式中,如果不及时释放vscode中的短点
会触发 合约调用超时异常
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: failed to execute transaction fb939cda10dc13c6c28d6cf90f5aa4abed32d8d9a939bf1076f9bb816f2c6bac: error sending: timeout expired while executing transaction"



