首页 > 解决方案 > 如何在没有重启环境 cc:restart 的情况下调试对流链码?

问题描述

我想调试一个链码,但默认情况下 npm 脚本总是使用 1.0 版的链码,但我在 1.7 版并且不想重新启动环境

标签: hyperledger-fabricconvector

解决方案


Diego:执行 cc:install:debug 否则它会尝试读取你没有的配置文件,所以先打包它然后 cc:install:debug 你可能不得不硬编码文件夹名称也玩脚本变量,所以你可以有一些动态的东西:wink:

调试2 调试2

$ npm run cc:install:debug -- person-debug1
...
Installed Chaincode person-debug1 version 1.0 at org2
[nodemon] 1.19.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node --inspect=9990 ./start.js --peer.address localhost:7052`
Debugger listening on ws://127.0.0.1:9990/23f811d2-a16f-4a97-ac57-8a64bde4561a
For help see https://nodejs.org/en/docs/inspector
[nodemon] 1.19.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node --inspect=9991 ./start.js --peer.address localhost:7152`
Debugger listening on ws://127.0.0.1:9991/713821ef-aa72-441c-850d-f4b0718b8ae5
For help see https://nodejs.org/en/docs/inspector
2019-08-23T22:58:57.212Z info [shim:lib/chaincode.js]                             Registering with peer localhost:7052 as chaincode "person-debug1:1.0"  
2019-08-23T22:58:57.229Z info [shim:lib/chaincode.js]                             Registering with peer localhost:7152 as chaincode "person-debug1:1.0"  
2019-08-23T22:58:57.242Z info [shim:lib/handler.js]                               Successfully registered with peer node. State transferred to "established"  
2019-08-23T22:58:57.246Z info [shim:lib/handler.js]                               Successfully established communication with peer node. State transferred to "ready"  
2019-08-23T22:58:57.255Z info [shim:lib/handler.js]                               Successfully registered with peer node. State transferred to "established"  
2019-08-23T22:58:57.256Z info [shim:lib/handler.js]                               Successfully established communication with peer node. State transferred to "ready"  
Debugger attached.
Debugger attached.
Instantiating Chaincode at org1 for channel ch1
It may take a few minutes depending on the chaincode dependencies
2019-08-23 23:59:05.841 WEST [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-08-23 23:59:05.841 WEST [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
info: [Chaincode] =========== Instantiated Chaincode chaincode ===========
info: [Chaincode] Transaction ID: 6bd7609598c269de4756e1d30da82e4c95195ab909015679eba348b82ba693dc
info: [Chaincode] Args: init,
2019-08-23T22:59:05.877Z info [shim:lib/handler.js]                               [ch1-6bd76095] Calling chaincode Init() succeeded. Sending COMPLETED message back to peer  
Instantiated Chaincode at org1
Found config in package [ { name: 'participant-cc',
    version: 'file:./packages/participant-cc',
    controller: 'ParticipantController' },
  { name: 'person-cc',
    version: 'file:./packages/person-cc',
    controller: 'PersonController' },
  { name: '@convector-rest-sample/common',
    version: 'file:./packages/common',
    controller: 'CommonController' } ]
Found config in package [ { name: 'participant-cc',
    version: 'file:./packages/participant-cc',
    controller: 'ParticipantController' },
  { name: 'person-cc',
    version: 'file:./packages/person-cc',
    controller: 'PersonController' },
  { name: '@convector-rest-sample/common',
    version: 'file:./packages/common',
    controller: 'CommonController' } ]
info: [Chaincode] =========== Invoked Chaincode Chaincode ===========
info: [Chaincode] Transaction ID: 5f84022dcb29f04b182ad96b8439b372dd41e3d870fd4bf1cc2acd81af36db99
info: [Chaincode] Args: person_create,{"id":"1-100-115","firstname":"Pete","lastname":"Doe","username":"peter","password":"12345678","email":"pete.doe@example.com"}
debug: [Chaincode] ============= START : person_create ===========
info: [Chaincode] =========== Invoked Chaincode Chaincode ===========
info: [Chaincode] Transaction ID: 5f84022dcb29f04b182ad96b8439b372dd41e3d870fd4bf1cc2acd81af36db99
info: [Chaincode] Args: person_create,{"id":"1-100-115","firstname":"Pete","lastname":"Doe","username":"peter","password":"12345678","email":"pete.doe@example.com"}
debug: [Chaincode] ============= START : person_create ===========

注意链码名称person-debug1,它会在项目的根目录中创建一个同名的目录,下次递增编号 ex person-debug2else

Error: could not assemble transaction, err proposal response was not successful, error code 500, msg chaincode with name 'person-debug1' already exists

提示:use npm run cc:package -- person-debug1 org1在安装前检查错误也很有用

提示:如果需要播种分类帐,请不要忘记使用person-debug1链代码名称

$ npx hurl invoke person-debug1 participant_register gov "Big Government" -u admin

如果代码更改对上述步骤进行了更改,并且我们部署了新的链代码并准备在断点处停止,那么您很快就会调用某些东西

# change to person-debug2
$ npm run cc:package -- person-debug2 org1
$ npm run cc:install:debug -- person-debug2

推荐阅读