热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

问:HyperLedgerfabric-starter-kit定制-Q:HyperLedgerfabric-starter-kitcustomisation

IhavefollowedthebasicguideforgettingtheHyperLedgerfabric-starter-kitupandrunningwhich

I have followed the basic guide for getting the HyperLedger fabric-starter-kit up and running which works perfectly. I cannot figure out how to successfully change the development directory of the app.js without causing an "invalid ELF header" error:

我已经按照基本的指南,获得了HyperLedger fabric-starter-kit up和running,它运行得很好。我不知道如何成功地更改app.js的开发目录,而不会导致“无效的ELF头”错误:

root@104efc36f09e:/user/env# node app
module.js:355
   Module._extensions[extension](this, filename);
                           ^
Error: /user/env/node_modules/grpc/src/node/extension_binary/grpc_node.node: invalid ELF header
   at Error (native)
   at Module.load (module.js:355:32)
   at Function.Module._load (module.js:310:12)
   at Module.require (module.js:365:17)
   at require (module.js:384:17)
   at Object. (/user/env/node_modules/grpc/src/node/src/grpc_extension.js:38:15)
   at Module._compile (module.js:460:26)
   at Object.Module._extensions..js (module.js:478:10)
   at Module.load (module.js:355:32)
   at Function.Module._load (module.js:310:12)
root@104efc36f09e:/user/env#

Dockerfile (unchanged):

Dockerfile(不变):

FROM hyperledger/fabric-peer:latest
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
RUN go build
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/examples/sdk/node
RUN npm install hfc`

docker-compose.yaml (changed volume to local workdir: ~/Documents/Work/Blockchain/env):

docker-compose。yaml(更改为本地workdir: ~/文档/工作/区块链/env):

membersrvc:
  container_name: membersrvc
  image: hyperledger/fabric-membersrvc
  command: membersrvc

peer:
  container_name: peer
  image: hyperledger/fabric-peer
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp0
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
  # this gives access to the docker host daemon to deploy chain code in network mode
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  # have the peer wait 10 sec for membersrvc to start
  #  the following is to run the peer in Developer mode - also set sample DEPLOY_MODE=dev
  command: sh -c "sleep 10; peer node start --peer-chaincodedev"
  #command: sh -c "sleep 10; peer node start"
  links:
    - membersrvc

starter:
  container_name: starter
  image: hyperledger/fabric-starter-kit
  volumes:
    - ~/Documents/Work/Blockchain/env:/user/env
  environment:
    - MEMBERSRVC_ADDRESS=membersrvc:7054
    - PEER_ADDRESS=peer:7051
    - KEY_VALUE_STORE=/tmp/hl_sdk_node_key_value_store
    # set to following to 'dev' if peer running in Developer mode
    - DEPLOY_MODE=dev
    - CORE_CHAINCODE_ID_NAME=mycc
    - CORE_PEER_ADDRESS=peer:7051
  # the following command will start the chain code when this container starts and ready it for deployment by the app
  command: sh -c "sleep 20; /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02"
  stdin_open: true
  tty: true
  links:
    - membersrvc
    - peer

app.js (unchanged):

app.js(不变):

/*
 * A simple application utilizing the Node.js Client SDK to:
 * 1) Enroll a user
 * 2) User deploys chaincode
 * 3) User queries chaincode
 */
// "HFC" stands for "Hyperledger Fabric Client"
var hfc = require("hfc");

console.log(" **** STARTING APP.JS ****");

// get the addresses from the docker-compose environment
var PEER_ADDRESS         = process.env.CORE_PEER_ADDRESS;
var MEMBERSRVC_ADDRESS   = process.env.MEMBERSRVC_ADDRESS;

var chain, chaincodeID;

// Create a chain object used to interact with the chain.
// You can name it anything you want as it is only used by client.
chain = hfc.newChain("mychain");

// Initialize the place to store sensitive private key information
chain.setKeyValStore( hfc.newFileKeyValStore('/tmp/keyValStore') );

// Set the URL to membership services and to the peer
console.log("member services address ="+MEMBERSRVC_ADDRESS);
console.log("peer address ="+PEER_ADDRESS);
chain.setMemberServicesUrl("grpc://"+MEMBERSRVC_ADDRESS);
chain.addPeer("grpc://"+PEER_ADDRESS);

// The following is required when the peer is started in dev mode
// (i.e. with the '--peer-chaincodedev' option)
var mode =  process.env['DEPLOY_MODE'];
console.log("DEPLOY_MODE=" + mode);
if (mode === 'dev') {
    chain.setDevMode(true);xs
    //Deploy will not take long as the chain should already be running
    chain.setDeployWaitTime(10);
} else {
    chain.setDevMode(false);
    //Deploy will take much longer in network mode
    chain.setDeployWaitTime(120);
}


chain.setInvokeWaitTime(10);

// Begin by enrolling the user
enroll();

// Enroll a user.
function enroll() {
   console.log("enrolling user admin ...");
   // Enroll "admin" which is preregistered in the membersrvc.yaml
   chain.enroll("admin", "Xurw3yU9zI0l", function(err, admin) {
      if (err) {
         console.log("ERROR: failed to register admin: %s",err);
         process.exit(1);
      }
      // Set this user as the chain's registrar which is authorized to register other users.
      chain.setRegistrar(admin);

      var userName = "JohnDoe";
      // registrationRequest
      var registratiOnRequest= {
          enrollmentID: userName,
          affiliation: "bank_a"
      };
      chain.registerAndEnroll(registrationRequest, function(error, user) {
          if (error) throw Error(" Failed to register and enroll " + userName + ": " + error);
          console.log("Enrolled %s successfully\n", userName);
          deploy(user);
      });      
   });
}

// Deploy chaincode
function deploy(user) {
   console.log("deploying chaincode; please wait ...");
   // Construct the deploy request
   var deployRequest = {
       chaincodeName: process.env.CORE_CHAINCODE_ID_NAME,
       fcn: "init",
       args: ["a", "100", "b", "200"]
   };
   // where is the chain code, ignored in dev mode
   deployRequest.chaincodePath = "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02";

   // Issue the deploy request and listen for events
   var tx = user.deploy(deployRequest);
   tx.on('complete', function(results) {
       // Deploy request completed successfully
       console.log("deploy complete; results: %j",results);
       // Set the testChaincodeID for subsequent tests
       chaincodeID = results.chaincodeID;
       invoke(user);
   });
   tx.on('error', function(error) {
       console.log("Failed to deploy chaincode: request=%j, error=%k",deployRequest,error);
       process.exit(1);
   });

}

// Query chaincode
function query(user) {
   console.log("querying chaincode ...");
   // Construct a query request
   var queryRequest = {
      chaincodeID: chaincodeID,
      fcn: "query",
      args: ["a"]
   };
   // Issue the query request and listen for events
   var tx = user.query(queryRequest);
   tx.on('complete', function (results) {
      console.log("query completed successfully; results=%j",results);
      process.exit(0);
   });
   tx.on('error', function (error) {
      console.log("Failed to query chaincode: request=%j, error=%k",queryRequest,error);
      process.exit(1);
   });
}

//Invoke chaincode
function invoke(user) {
   console.log("invoke chaincode ...");
   // Construct a query request
   var invokeRequest = {
      chaincodeID: chaincodeID,
      fcn: "invoke",
      args: ["a", "b", "1"]
   };
   // Issue the invoke request and listen for events
   var tx = user.invoke(invokeRequest);
   tx.on('submitted', function (results) {
          console.log("invoke submitted successfully; results=%j",results);       
       });   
   tx.on('complete', function (results) {
      console.log("invoke completed successfully; results=%j",results);
      query(user);      
   });
   tx.on('error', function (error) {
      console.log("Failed to invoke chaincode: request=%j, error=%k",invokeRequest,error);
      process.exit(1);
   });
}

My goal is to create an authentication service using the HFC so that an Android app invoke a transaction. Any help would be greatly appreciated.

我的目标是使用HFC创建一个身份验证服务,以便Android应用程序调用事务。非常感谢您的帮助。

2 个解决方案

#1


1  

you installed node modules in your mac and used them in your Linux docker image. This is what causing the problem.

您在mac中安装了节点模块,并在Linux docker映像中使用它们。这就是造成问题的原因。

Make sure that npm modules are built on the platform you are executing it. Re-install your node modules in your linux environment by first deleting node_modules and running npm install from inside starter docker image.

确保npm模块是在您正在执行的平台上构建的。在linux环境中重新安装节点模块,首先删除node_modules并从启动docker映像中运行npm安装。

Please consult these questions as well,

请咨询这些问题,

NodeJs Google Compute Engine Invalid ELF Header when using 'gcloud' module

在使用“gcloud”模块时,NodeJs谷歌计算引擎无效。

"invalid ELF header" when using the nodejs "ref" module on AWS Lambda

在AWS上使用nodejs“ref”模块时,“无效的ELF头”。

#2


0  

Credit to Sufiyan Ghori for pointing this out - the issue was that the node modules were installed in my host (mac) and therefore weren't compatible with the linux docker image I was trying to execute code within.

Credit to Sufiyan Ghori指出这一点——问题是,节点模块安装在我的主机(mac)中,因此与我试图在内部执行代码的linux docker映像不兼容。

SOLUTION:

解决方案:

  • Delete node_modules folder from work directory.
  • 从工作目录中删除node_modules文件夹。
  • Run npm install hfc@0.6.x from inside the starter docker image.
  • 运行npm安装hfc@0.6。x来自启动docker镜像。

推荐阅读
author-avatar
_我是谁谁谁__950
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有