|
| 1 | +Using dev mode |
| 2 | +============== |
| 3 | + |
| 4 | +Normally chaincodes are started and maintained by peer. However in “dev” |
| 5 | +mode, chaincode is built and started by the user. This mode is useful |
| 6 | +during chaincode development phase for rapid code/build/run/debug cycle |
| 7 | +turnaround. |
| 8 | + |
| 9 | +To keep this a realistic “dev” environment, we are going to keep it “out |
| 10 | +of the box” - with one exception: we create two channels instead of |
| 11 | +using the default ``testchainid`` channel to show how the single running |
| 12 | +instance can be accessed from multiple channels. |
| 13 | + |
| 14 | +Start the orderer |
| 15 | +----------------- |
| 16 | + |
| 17 | +:: |
| 18 | + |
| 19 | + orderer |
| 20 | + |
| 21 | +The above starts the orderer in the local environment using default |
| 22 | +orderer configuration as defined in ``orderer/orderer.yaml``. |
| 23 | + |
| 24 | +Start the peer in dev mode |
| 25 | +-------------------------- |
| 26 | + |
| 27 | +:: |
| 28 | + |
| 29 | + peer node start --peer-defaultchain=false --peer-chaincodedev=true |
| 30 | + |
| 31 | +The above command starts the peer using the default ``msp/sampleconfig`` |
| 32 | +MSP. The ``--peer-chaincodedev=true`` puts it in “dev” mode. ##Create |
| 33 | +channels ch1 and ch2 |
| 34 | + |
| 35 | +:: |
| 36 | + |
| 37 | + peer channel create -o 127.0.0.1:7050 -c ch1 |
| 38 | + peer channel create -o 127.0.0.1:7050 -c ch2 |
| 39 | + |
| 40 | +Above assumes orderer is reachable on ``127.0.0.1:7050``. The orderer |
| 41 | +now is tracking channels ch1 and ch2 for the default configuration. |
| 42 | + |
| 43 | +:: |
| 44 | + |
| 45 | + peer channel join -b ch1.block |
| 46 | + peer channel join -b ch2.block |
| 47 | + |
| 48 | +The peer has now joined channels cha1 and ch2. |
| 49 | + |
| 50 | +Start the chaincode |
| 51 | +------------------- |
| 52 | + |
| 53 | +:: |
| 54 | + |
| 55 | + cd examples/chaincode/go/chaincode_example02 |
| 56 | + go build |
| 57 | + CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02 |
| 58 | + |
| 59 | +The chaincode is started with peer and chaincode logs showing it got |
| 60 | +registered successfully with the peer. |
| 61 | + |
| 62 | +Use the chaincode |
| 63 | +----------------- |
| 64 | + |
| 65 | +:: |
| 66 | + |
| 67 | + peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch1 |
| 68 | + |
| 69 | + peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch2 |
| 70 | + |
| 71 | +The above instantiates the chaincode with the two channels. With default |
| 72 | +settings it might take a few seconds for the transactions to be |
| 73 | +committed. |
| 74 | + |
| 75 | +:: |
| 76 | + |
| 77 | + peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch1 |
| 78 | + peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch2 |
| 79 | + |
| 80 | +The above invokes the chaincode using the two channels. |
| 81 | + |
| 82 | +:: |
| 83 | + |
| 84 | + peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch1 |
| 85 | + peer chaincode invoke -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch2 |
0 commit comments