0

I want to debug a chaincode, but npm script by default always use version 1.0 of chaincode, but I'm in version 1.7 and don't want to restart environment

1 Answers1

1

Diego: do the cc:install:debug because otherwise it will try to read a config file you don't have, so package it first and then cc:install:debug you maybe have to hard code the folder name too play with the scripts variables so you can have something dynamic :wink:

debug2 debug2

$ 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 ===========

Note for chaincode name person-debug1, it create a dir with same name in root of project, next time increment number ex person-debug2 else

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

Tip: use npm run cc:package -- person-debug1 org1 too, useful to check error before install

Tip: if required to seed ledger don't forget to use person-debug1 chaincode name

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

if code changes do that to above steps, and we have a new chaincode deployed and ready to stop in breakpoints has soon has you invoke something

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