Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.85 KB | None | 0 0
  1. Error:
  2. Instantiating chaincode hangs:
  3.  
  4. docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -l node -v 1.0 -c '{"Args":["Init"]}'
  5. 2019-01-16 14:32:18.451 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
  6. 2019-01-16 14:32:18.451 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
  7.  
  8. Chaincode:
  9. /*
  10. # Copyright IBM Corp. All Rights Reserved.
  11. #
  12. # SPDX-License-Identifier: Apache-2.0
  13. */
  14.  
  15. /*
  16. const shim = require('fabric-shim');
  17. const util = require('util');
  18.  
  19. var Chaincode = class {
  20.  
  21. // Initialize the chaincode
  22. async Init(stub) {
  23. console.info('========= example02 Init =========');
  24. console.log("HELLO WORLD!!!");
  25. console.log("Init: Does nothing!");
  26. return shim.success();
  27. }
  28.  
  29. async Invoke(stub) {
  30. let ret = stub.getFunctionAndParameters();
  31. console.info("Truong: async Invoke!!");
  32. console.info(ret);
  33. let method = this[ret.fcn];
  34. if (!method) {
  35. console.log('no method of name:' + ret.fcn + ' found');
  36. return shim.success();
  37. }
  38. try {
  39. let payload = await method(stub, ret.params);
  40. return shim.success(payload);
  41. } catch (err) {
  42. console.log(err);
  43. return shim.error(err);
  44. }
  45. }
  46.  
  47. // Insert
  48. async insert(stub, args) {
  49. console.log("Truong: async insert!!!");
  50. console.log(args);
  51. console.log("HELLO!");
  52. let ID = args[0];
  53. let Name = args[1];
  54. let Dob = args[2];
  55. let entry = {};
  56. entry.name = Name;
  57. entry.dateOfBirth = Dob;
  58. // entry.docType = "Student";
  59. console.log("Entry:");
  60. console.log(entry);
  61. console.log(ID);
  62. console.log(ID.toString());
  63. console.log("Ending async insert!");
  64.  
  65. let temp = [];
  66. temp.push(Name);
  67. temp.push(Dob);
  68.  
  69.  
  70. // await stub.putState(ID.toString(), Buffer.from(JSON.stringify(entry)));
  71. await stub.putState(ID.toString(), Buffer.from(JSON.stringify(temp)));
  72. console.info('============= END : Create Student ===========');
  73. }
  74.  
  75. // Delete
  76. async delete(stub, args) {
  77. console.info("Truong: async delete!!!");
  78. if (args.length != 1) {
  79. throw new Error('Incorrect number of arguments. Expecting 1');
  80. }
  81.  
  82. let ID = args[0];
  83.  
  84. // Delete the key from the state in ledger
  85. await stub.deleteState(ID);
  86. }
  87.  
  88. // query callback representing the query of a chaincode
  89. async query(stub, args) {
  90. if (args.length != 1) {
  91. throw new Error('Incorrect number of arguments. Expecting name of the person to query')
  92. }
  93.  
  94. let jsonResp = {};
  95. let ID = args[0];
  96.  
  97. // Get the state from the ledger
  98. let Result = await stub.getState(ID);
  99. if (!Result) {
  100. jsonResp.error = 'Failed to get state for ' + ID;
  101. throw new Error(JSON.stringify(jsonResp));
  102. }
  103.  
  104. console.log(Result.toString());
  105. return Result;
  106.  
  107.  
  108. }
  109. };
  110.  
  111. shim.start(new Chaincode());
  112. */
  113.  
  114. /*
  115. const shim = require('fabric-shim');
  116. const util = require('util');
  117.  
  118. var Chaincode = class {
  119.  
  120. // Initialize the chaincode
  121. async Init(stub) {
  122. console.info('========= example02 Init =========');
  123. console.log("HELLO WORLD!!!");
  124. console.log("Init: Does nothing!");
  125. return shim.success();
  126. }
  127.  
  128. async Invoke(stub) {
  129. let ret = stub.getFunctionAndParameters();
  130. console.info("Truong: async Invoke!!");
  131. console.info(ret);
  132. let method = this[ret.fcn];
  133. if (!method) {
  134. console.log('no method of name:' + ret.fcn + ' found');
  135. return shim.success();
  136. }
  137. try {
  138. let payload = await method(stub, ret.params);
  139. return shim.success(payload);
  140. } catch (err) {
  141. console.log(err);
  142. return shim.error(err);
  143. }
  144. }
  145.  
  146. // Insert
  147. async insert(stub, args) {
  148. console.log("Truong: async insert!!!");
  149. if (args.length != 2) {
  150. throw new Error('Incorrect number of arguments. Expecting 2');
  151. }
  152.  
  153. let ID = args[0];
  154. let Attrs = args[1];
  155. await stub.putState(ID, Buffer.from(JSON.stringify(Attrs)));
  156. }
  157.  
  158. // Delete
  159. async delete(stub, args) {
  160. console.info("Truong: async delete!!!");
  161. if (args.length != 1) {
  162. throw new Error('Incorrect number of arguments. Expecting 1');
  163. }
  164.  
  165. let ID = args[0];
  166.  
  167. // Delete the key from the state in ledger
  168. await stub.deleteState(ID);
  169. }
  170.  
  171. // query callback representing the query of a chaincode
  172. async query(stub, args) {
  173. if (args.length != 1) {
  174. throw new Error('Incorrect number of arguments. Expecting name of the person to query')
  175. }
  176.  
  177. let jsonResp = {};
  178. let ID = args[0];
  179.  
  180. // Get the state from the ledger
  181. let Result = await stub.getState(ID);
  182. if (!Result) {
  183. jsonResp.error = 'Failed to get state for ' + ID;
  184. throw new Error(JSON.stringify(jsonResp));
  185. }
  186.  
  187. jsonResp.ID = ID;
  188. jsonResp.Attrs = Result.toString();
  189. console.info('Query Response:');
  190. console.info(jsonResp);
  191.  
  192. return Result;
  193. }
  194. };
  195.  
  196. shim.start(new Chaincode());
  197. */
  198.  
  199. const shim = require('fabric-shim');
  200. const util = require('util');
  201.  
  202. var Chaincode = class {
  203.  
  204. // Initialize the chaincode
  205. async Init(stub) {
  206. console.info('========= example02 Init =========');
  207. let key = "A";
  208. let value = "15";
  209. try {
  210. await stub.putState(key, Buffer.from(value));
  211. } catch (err) {
  212. return shim.error(err);
  213. }
  214. return shim.success();
  215. }
  216.  
  217. async Invoke(stub) {
  218. let ret = stub.getFunctionAndParameters();
  219. console.info("Truong: async Invoke!!");
  220. console.info(ret);
  221. let method = this[ret.fcn];
  222. if (!method) {
  223. console.log('no method of name:' + ret.fcn + ' found');
  224. return shim.success();
  225. }
  226. try {
  227. let payload = await method(stub, ret.params);
  228. return shim.success(payload);
  229. } catch (err) {
  230. console.log(err);
  231. return shim.error(err);
  232. }
  233. }
  234.  
  235. // Insert
  236. /*
  237. async insert(stub, args) {
  238. console.log("Truong: async insert!!!");
  239. if (args.length != 2) {
  240. throw new Error('Incorrect number of arguments. Expecting 2');
  241. }
  242.  
  243. let key = args[0];
  244. let value = args[1];
  245. let key1 = "3";
  246. let value1 = "Huhuhu";
  247. console.log("Key = ");
  248. console.log(key);
  249. console.log("Value = ");
  250. console.log(value);
  251. try {
  252. await stub.putState(key.toString(), Buffer.from(value.toString()));
  253. await stub.putState(key1.toString(), Buffer.from(value1.toString()));
  254. } catch (err) {
  255. return shim.error(err);
  256. }
  257. }
  258. */
  259.  
  260. // Delete
  261. async delete(stub, args) {
  262. console.info("Truong: async delete!!!");
  263. if (args.length != 1) {
  264. throw new Error('Incorrect number of arguments. Expecting 1');
  265. }
  266.  
  267. let ID = args[0];
  268.  
  269. // Delete the key from the state in ledger
  270. await stub.deleteState(ID);
  271. }
  272.  
  273. // query callback representing the query of a chaincode
  274. /*
  275. async query(stub, args) {
  276. if (args.length != 1) {
  277. throw new Error('Incorrect number of arguments. Expecting name of the person to query')
  278. }
  279.  
  280. let jsonResp = {};
  281. let key = args[0];
  282.  
  283. // Get the state from the ledger
  284. let Result = await stub.getState(key);
  285. if (!Result) {
  286. jsonResp.error = 'Failed to get state for ' + ID;
  287. throw new Error(JSON.stringify(jsonResp));
  288. }
  289.  
  290. jsonResp.key = key;
  291. jsonResp = Result.toString();
  292. console.log("Result = ");
  293. console.log(jsonResp);
  294.  
  295. return Result;
  296. }
  297. */
  298. async query(stub, args) {
  299. let jsonResp = {};
  300. let Result = await stub.getState("A");
  301. if (!Result) {
  302. jsonResp.error = 'Failed to get state for A';
  303. throw new Error(JSON.stringify(jsonResp));
  304. }
  305. jsonResp.value = Result.toString();
  306. console.log("Result = ");
  307. console.log(jsonResp);
  308. return Result;
  309. }
  310.  
  311. };
  312.  
  313. shim.start(new Chaincode());
  314.  
  315.  
  316. docker-compose.yml file:
  317. #
  318. # Copyright IBM Corp All Rights Reserved
  319. #
  320. # SPDX-License-Identifier: Apache-2.0
  321. #
  322. version: '2'
  323.  
  324. networks:
  325. basic:
  326.  
  327. services:
  328. ca.example.com:
  329. image: hyperledger/fabric-ca
  330. environment:
  331. - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
  332. - FABRIC_CA_SERVER_CA_NAME=ca.example.com
  333. - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem
  334. - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/d0231097d72499a57ea7e0141e6db01bfda9f8fd948e44398926900a57676ddf_sk
  335. ports:
  336. - "7054:7054"
  337. command: sh -c 'fabric-ca-server start -b admin:adminpw'
  338. volumes:
  339. - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
  340. container_name: ca.example.com
  341. networks:
  342. - basic
  343.  
  344. orderer.example.com:
  345. container_name: orderer.example.com
  346. image: hyperledger/fabric-orderer
  347. environment:
  348. - ORDERER_GENERAL_LOGLEVEL=info
  349. - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
  350. - ORDERER_GENERAL_GENESISMETHOD=file
  351. - ORDERER_GENERAL_GENESISPROFILE=SampleDevModeSolo
  352. - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
  353. - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
  354. - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
  355. working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
  356. command: orderer
  357. ports:
  358. - 7050:7050
  359. volumes:
  360. - ./config/:/etc/hyperledger/configtx
  361. - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/:/etc/hyperledger/msp/orderer
  362. - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peerOrg1
  363. networks:
  364. - basic
  365.  
  366. peer0.org1.example.com:
  367. container_name: peer0.org1.example.com
  368. image: hyperledger/fabric-peer
  369. environment:
  370. - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
  371. - CORE_PEER_ID=peer0.org1.example.com
  372. - CORE_LOGGING_PEER=debug
  373. - CORE_CHAINCODE_LOGGING_LEVEL=debug
  374. - CORE_PEER_LOCALMSPID=Org1MSP
  375. - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
  376. - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
  377. # # the following setting starts chaincode containers on the same
  378. # # bridge network as the peers
  379. # # https://docs.docker.com/compose/networking/
  380. - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
  381. - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
  382. - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
  383. # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
  384. # provide the credentials for ledger to connect to CouchDB. The username and password must
  385. # match the username and password set for the associated CouchDB.
  386. - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
  387. - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
  388. working_dir: /opt/gopath/src/github.com/hyperledger/fabric
  389. # command: peer node start
  390. command: peer node start --peer-chaincodedev=true
  391. ports:
  392. - 7051:7051
  393. - 7053:7053
  394. volumes:
  395. - /var/run/:/host/var/run/
  396. - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/msp/peer
  397. - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
  398. - ./config:/etc/hyperledger/configtx
  399. - ./fabcar:/opt/gopath/src/github.com/
  400. depends_on:
  401. - orderer.example.com
  402. - couchdb
  403. networks:
  404. - basic
  405.  
  406. couchdb:
  407. container_name: couchdb
  408. image: hyperledger/fabric-couchdb
  409. # Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password
  410. # for CouchDB. This will prevent CouchDB from operating in an "Admin Party" mode.
  411. environment:
  412. - COUCHDB_USER=
  413. - COUCHDB_PASSWORD=
  414. ports:
  415. - 5984:5984
  416. networks:
  417. - basic
  418.  
  419. cli:
  420. container_name: cli
  421. image: hyperledger/fabric-tools
  422. tty: true
  423. environment:
  424. - GOPATH=/opt/gopath
  425. - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
  426. - CORE_LOGGING_LEVEL=info
  427. - CORE_PEER_ID=cli
  428. - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
  429. - CORE_PEER_LOCALMSPID=Org1MSP
  430. - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
  431. - CORE_CHAINCODE_KEEPALIVE=10
  432. working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
  433. command: /bin/bash
  434. volumes:
  435. - /var/run/:/host/var/run/
  436. - ./../chaincode/:/opt/gopath/src/github.com/
  437. - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
  438. networks:
  439. - basic
  440. #depends_on:
  441. # - orderer.example.com
  442. # - peer0.org1.example.com
  443. # - couchdb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement