2016-11-07 29 views
2

我已经遵循的基本guide用于获取HyperLedger织物初学者工具包并运行它完美的作品。我无法弄清楚如何成功地改变app.js的开发目录,而不会导致 “无效ELF头” 错误:问:HyperLedger织物初学者工具包定制

[email protected]:/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.<anonymous> (/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) 
[email protected]:/user/env# 

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(改变体积本地WORKDIR:〜/文档/工作/ Blockchain/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(不变):

/* 
* 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); 
    }); 
} 

我的目标是创建一个使用HFC使Android应用调用交易的认证服务。任何帮助将不胜感激。

+0

你的平台或用于发展的架构之间进行切换?确保'npm'模块建立在你正在执行它的平台上。尝试重新安装节点模块。请阅读这个http://stackoverflow.com/questions/32618976/nodejs-google-compute-engine-invalid-elf-header-when-using-gcloud-module,这也是如此http://stackoverflow.com/questions/ 29994411/invalid-elf-header-when-using-the-nodejs-ref-module-on-aws-lambda。让我知道,如果它有帮助 –

+1

@SufiyanGhori伟大的帮助!我删除了我的工作目录中的node_modules文件夹,并从'starter' docker映像中运行'npm install hfc @ 0.6.x'。谢谢! –

+0

尝试使用这个样板https://github.com/IBM-Blockchain/fabric-boilerplate –

回答

0

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

解决方案:从工作目录

  • 删除node_modules文件夹。从starter泊坞窗图像内
  • 运行npm install [email protected]