2017-07-04 51 views

回答

0

作曲目前没有任何直接的方式尚未与其他业务网络进行通信。业务网络可以将事件发送到外部系统,以便您现在可以创建中间客户端应用程序来执行某些操作。 有一个问题在 https://github.com/hyperledger/composer/issues/898

0

跟踪这个要求我最近建立了一些代码与监控chaincode事件,这样可以为他们创建显示块信息的hyperledger作曲家(V0.13)应用程序使用。该代码是关于区块链的新教程Zero To Blockhain的一部分。该代码位于第5章&中的queryBlockchain.js文件中。定位此文件的文件夹结构为:

Chapter 05 
    ↳ controller 
    ↳restapi 
     router.js 
     ↳features 
      ↳composer 
      autoLoad.js 
      hlcAdmin.js 
      queryBlockChain.js <=== You want this file for blockchain events 
      Z2B_Services.js <=== and this file for socket communications with the browser 
      Z2B_Utilities.js 
      ↳creds 

并且它使用作曲家安装提供的凭证,它们存储在creds文件夹中。

参照Jonathan的评论,上面引用的实际代码访问任何业务网络,而不仅仅是连接了hyperledger作曲者的网络。在结构级别,您需要访问有效的keyStore,通道名称,对等请求URL和目标网络的订购者URL。代码中引用的代码如下:

var channel = {}; 
    var client = null; 
    var wallet_path = path.join(__dirname, 'creds'); 
    Promise.resolve().then(() => { 
     // 
     // As of 9/28/2017 there is a known and unresolved bug in HyperLedger Fabric 
     // https://github.com/hyperledger/composer/issues/957 
     // this requires that the file location for the wallet for Fabric version 1.0 be in the following location: 
     // {HOME}/.hfc-key-store 
     // therefore the wallet location will be ignored and any private keys required to enroll a user in this process 
     // must be located in {HOME}/.hfc-key-store 
     // this is currently managed for you in the installation exec by copying the private key for PeerAdmin to this location 
     // 
     console.log("Create a client and set the wallet location"); 
     // hfc = require('fabric-client'); 
     client = new hfc(); 
     return hfc.newDefaultKeyValueStore({ path: wallet_path }) 
     .then((wallet) => { 
      client.setStateStore(wallet); 
      // const config = require('../../../env.json'); 
      // which contains the following and is set in this 
      // example to support the hyperledger fabric dev environment: 
      // { 
      //  "composer": 
      //  { 
      //   "connectionProfile": "hlfv1", 
      //   "network": "zerotoblockchain-network", 
      //   "adminID": "admin", 
      //   "adminPW": "adminpw", 
      //   "PeerAdmin": "PeerAdmin", 
      //   "PeerPW": "randomString", 
      //   "NS": "org.acme.Z2BTestNetwork" 
      //  }, 
      //  "fabric": 
      //  { 
      //   "user": "queryUser", 
      //   "eventURL": "grpc://localhost:7053", 
      //   "channelName": "composerchannel", 
      //   "keyValStore": ".composer-credentials/PeerAdmin", 
      //   "wallet_store": "creds", 
      //   "peer": "peer0.org1.example.com", 
      //   "peerRequestURL": "grpc://localhost:7051", 
      //   "peerEventURL": "grpc://localhost:7053", 
      //   "ordererURL" : "grpc://localhost:7050", 
      //   "caURL": "http://localhost:7054" 
      //  } 
      // } 
      // 
      return client.getUserContext(config.composer.PeerAdmin, true);}) 
      .then((user) => { 
       if (user === null || user === undefined || user.isEnrolled() === false) 
        {console.error("User not defined, or not enrolled - error");} 
        channel = client.newChannel(config.fabric.channelName); 
        channel.addPeer(client.newPeer(config.fabric.peerRequestURL)); 
        channel.addOrderer(client.newOrderer(config.fabric.ordererURL)); 
       }) 
       .then(() => { 
        return channel.queryInfo() 
        .then((blockchainInfo) => { 
         if (blockchainInfo) { 
          res.send({"result": "success", "currentHash": blockchainInfo.currentBlockHash.toString("hex"), blockchain: blockchainInfo}); 
         } else { 
          console.log('response_payload is null'); 
          res.send({"result": "uncertain", "message": 'response_payload is null'}); 
         } 
        }) 
        .catch((_err) => { 
         console.log("queryInfo failed with _err = ", _err); 
         res.send({"result": "failed", "message": _err.message}); 
        });  
       }); 
     }); 
} 
+0

这并不回答关于从现有的企业网络查询等业务网络(chaincodes)问题 –

+0

上面提到的实际代码访问任何一个企业网络,而不仅仅是一个到hyperledger作曲家被附上。在结构级别,您需要访问有效的keyStore,通道名称,对等请求URL和目标网络的订购者URL。 –

相关问题