Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error:
- Instantiating chaincode hangs:
- 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"]}'
- 2019-01-16 14:32:18.451 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
- 2019-01-16 14:32:18.451 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
- Chaincode:
- /*
- # Copyright IBM Corp. All Rights Reserved.
- #
- # SPDX-License-Identifier: Apache-2.0
- */
- /*
- const shim = require('fabric-shim');
- const util = require('util');
- var Chaincode = class {
- // Initialize the chaincode
- async Init(stub) {
- console.info('========= example02 Init =========');
- console.log("HELLO WORLD!!!");
- console.log("Init: Does nothing!");
- return shim.success();
- }
- async Invoke(stub) {
- let ret = stub.getFunctionAndParameters();
- console.info("Truong: async Invoke!!");
- console.info(ret);
- let method = this[ret.fcn];
- if (!method) {
- console.log('no method of name:' + ret.fcn + ' found');
- return shim.success();
- }
- try {
- let payload = await method(stub, ret.params);
- return shim.success(payload);
- } catch (err) {
- console.log(err);
- return shim.error(err);
- }
- }
- // Insert
- async insert(stub, args) {
- console.log("Truong: async insert!!!");
- console.log(args);
- console.log("HELLO!");
- let ID = args[0];
- let Name = args[1];
- let Dob = args[2];
- let entry = {};
- entry.name = Name;
- entry.dateOfBirth = Dob;
- // entry.docType = "Student";
- console.log("Entry:");
- console.log(entry);
- console.log(ID);
- console.log(ID.toString());
- console.log("Ending async insert!");
- let temp = [];
- temp.push(Name);
- temp.push(Dob);
- // await stub.putState(ID.toString(), Buffer.from(JSON.stringify(entry)));
- await stub.putState(ID.toString(), Buffer.from(JSON.stringify(temp)));
- console.info('============= END : Create Student ===========');
- }
- // Delete
- async delete(stub, args) {
- console.info("Truong: async delete!!!");
- if (args.length != 1) {
- throw new Error('Incorrect number of arguments. Expecting 1');
- }
- let ID = args[0];
- // Delete the key from the state in ledger
- await stub.deleteState(ID);
- }
- // query callback representing the query of a chaincode
- async query(stub, args) {
- if (args.length != 1) {
- throw new Error('Incorrect number of arguments. Expecting name of the person to query')
- }
- let jsonResp = {};
- let ID = args[0];
- // Get the state from the ledger
- let Result = await stub.getState(ID);
- if (!Result) {
- jsonResp.error = 'Failed to get state for ' + ID;
- throw new Error(JSON.stringify(jsonResp));
- }
- console.log(Result.toString());
- return Result;
- }
- };
- shim.start(new Chaincode());
- */
- /*
- const shim = require('fabric-shim');
- const util = require('util');
- var Chaincode = class {
- // Initialize the chaincode
- async Init(stub) {
- console.info('========= example02 Init =========');
- console.log("HELLO WORLD!!!");
- console.log("Init: Does nothing!");
- return shim.success();
- }
- async Invoke(stub) {
- let ret = stub.getFunctionAndParameters();
- console.info("Truong: async Invoke!!");
- console.info(ret);
- let method = this[ret.fcn];
- if (!method) {
- console.log('no method of name:' + ret.fcn + ' found');
- return shim.success();
- }
- try {
- let payload = await method(stub, ret.params);
- return shim.success(payload);
- } catch (err) {
- console.log(err);
- return shim.error(err);
- }
- }
- // Insert
- async insert(stub, args) {
- console.log("Truong: async insert!!!");
- if (args.length != 2) {
- throw new Error('Incorrect number of arguments. Expecting 2');
- }
- let ID = args[0];
- let Attrs = args[1];
- await stub.putState(ID, Buffer.from(JSON.stringify(Attrs)));
- }
- // Delete
- async delete(stub, args) {
- console.info("Truong: async delete!!!");
- if (args.length != 1) {
- throw new Error('Incorrect number of arguments. Expecting 1');
- }
- let ID = args[0];
- // Delete the key from the state in ledger
- await stub.deleteState(ID);
- }
- // query callback representing the query of a chaincode
- async query(stub, args) {
- if (args.length != 1) {
- throw new Error('Incorrect number of arguments. Expecting name of the person to query')
- }
- let jsonResp = {};
- let ID = args[0];
- // Get the state from the ledger
- let Result = await stub.getState(ID);
- if (!Result) {
- jsonResp.error = 'Failed to get state for ' + ID;
- throw new Error(JSON.stringify(jsonResp));
- }
- jsonResp.ID = ID;
- jsonResp.Attrs = Result.toString();
- console.info('Query Response:');
- console.info(jsonResp);
- return Result;
- }
- };
- shim.start(new Chaincode());
- */
- const shim = require('fabric-shim');
- const util = require('util');
- var Chaincode = class {
- // Initialize the chaincode
- async Init(stub) {
- console.info('========= example02 Init =========');
- let key = "A";
- let value = "15";
- try {
- await stub.putState(key, Buffer.from(value));
- } catch (err) {
- return shim.error(err);
- }
- return shim.success();
- }
- async Invoke(stub) {
- let ret = stub.getFunctionAndParameters();
- console.info("Truong: async Invoke!!");
- console.info(ret);
- let method = this[ret.fcn];
- if (!method) {
- console.log('no method of name:' + ret.fcn + ' found');
- return shim.success();
- }
- try {
- let payload = await method(stub, ret.params);
- return shim.success(payload);
- } catch (err) {
- console.log(err);
- return shim.error(err);
- }
- }
- // Insert
- /*
- async insert(stub, args) {
- console.log("Truong: async insert!!!");
- if (args.length != 2) {
- throw new Error('Incorrect number of arguments. Expecting 2');
- }
- let key = args[0];
- let value = args[1];
- let key1 = "3";
- let value1 = "Huhuhu";
- console.log("Key = ");
- console.log(key);
- console.log("Value = ");
- console.log(value);
- try {
- await stub.putState(key.toString(), Buffer.from(value.toString()));
- await stub.putState(key1.toString(), Buffer.from(value1.toString()));
- } catch (err) {
- return shim.error(err);
- }
- }
- */
- // Delete
- async delete(stub, args) {
- console.info("Truong: async delete!!!");
- if (args.length != 1) {
- throw new Error('Incorrect number of arguments. Expecting 1');
- }
- let ID = args[0];
- // Delete the key from the state in ledger
- await stub.deleteState(ID);
- }
- // query callback representing the query of a chaincode
- /*
- async query(stub, args) {
- if (args.length != 1) {
- throw new Error('Incorrect number of arguments. Expecting name of the person to query')
- }
- let jsonResp = {};
- let key = args[0];
- // Get the state from the ledger
- let Result = await stub.getState(key);
- if (!Result) {
- jsonResp.error = 'Failed to get state for ' + ID;
- throw new Error(JSON.stringify(jsonResp));
- }
- jsonResp.key = key;
- jsonResp = Result.toString();
- console.log("Result = ");
- console.log(jsonResp);
- return Result;
- }
- */
- async query(stub, args) {
- let jsonResp = {};
- let Result = await stub.getState("A");
- if (!Result) {
- jsonResp.error = 'Failed to get state for A';
- throw new Error(JSON.stringify(jsonResp));
- }
- jsonResp.value = Result.toString();
- console.log("Result = ");
- console.log(jsonResp);
- return Result;
- }
- };
- shim.start(new Chaincode());
- docker-compose.yml file:
- #
- # Copyright IBM Corp All Rights Reserved
- #
- # SPDX-License-Identifier: Apache-2.0
- #
- version: '2'
- networks:
- basic:
- services:
- ca.example.com:
- image: hyperledger/fabric-ca
- environment:
- - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- - FABRIC_CA_SERVER_CA_NAME=ca.example.com
- - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem
- - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/d0231097d72499a57ea7e0141e6db01bfda9f8fd948e44398926900a57676ddf_sk
- ports:
- - "7054:7054"
- command: sh -c 'fabric-ca-server start -b admin:adminpw'
- volumes:
- - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
- container_name: ca.example.com
- networks:
- - basic
- orderer.example.com:
- container_name: orderer.example.com
- image: hyperledger/fabric-orderer
- environment:
- - ORDERER_GENERAL_LOGLEVEL=info
- - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- - ORDERER_GENERAL_GENESISMETHOD=file
- - ORDERER_GENERAL_GENESISPROFILE=SampleDevModeSolo
- - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
- - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
- command: orderer
- ports:
- - 7050:7050
- volumes:
- - ./config/:/etc/hyperledger/configtx
- - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/:/etc/hyperledger/msp/orderer
- - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peerOrg1
- networks:
- - basic
- peer0.org1.example.com:
- container_name: peer0.org1.example.com
- image: hyperledger/fabric-peer
- environment:
- - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- - CORE_PEER_ID=peer0.org1.example.com
- - CORE_LOGGING_PEER=debug
- - CORE_CHAINCODE_LOGGING_LEVEL=debug
- - CORE_PEER_LOCALMSPID=Org1MSP
- - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- # # the following setting starts chaincode containers on the same
- # # bridge network as the peers
- # # https://docs.docker.com/compose/networking/
- - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
- - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
- - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
- # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
- # provide the credentials for ledger to connect to CouchDB. The username and password must
- # match the username and password set for the associated CouchDB.
- - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
- - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric
- # command: peer node start
- command: peer node start --peer-chaincodedev=true
- ports:
- - 7051:7051
- - 7053:7053
- volumes:
- - /var/run/:/host/var/run/
- - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/msp/peer
- - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
- - ./config:/etc/hyperledger/configtx
- - ./fabcar:/opt/gopath/src/github.com/
- depends_on:
- - orderer.example.com
- - couchdb
- networks:
- - basic
- couchdb:
- container_name: couchdb
- image: hyperledger/fabric-couchdb
- # Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password
- # for CouchDB. This will prevent CouchDB from operating in an "Admin Party" mode.
- environment:
- - COUCHDB_USER=
- - COUCHDB_PASSWORD=
- ports:
- - 5984:5984
- networks:
- - basic
- cli:
- container_name: cli
- image: hyperledger/fabric-tools
- tty: true
- environment:
- - GOPATH=/opt/gopath
- - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- - CORE_LOGGING_LEVEL=info
- - CORE_PEER_ID=cli
- - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- - CORE_PEER_LOCALMSPID=Org1MSP
- - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
- - CORE_CHAINCODE_KEEPALIVE=10
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
- command: /bin/bash
- volumes:
- - /var/run/:/host/var/run/
- - ./../chaincode/:/opt/gopath/src/github.com/
- - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- networks:
- - basic
- #depends_on:
- # - orderer.example.com
- # - peer0.org1.example.com
- # - couchdb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement