代码之家  ›  专栏  ›  技术社区  ›  claudiomatiasrg

部署在google计算引擎上时,hyperledger composer模块local_connection.json

  •  0
  • claudiomatiasrg  · 技术社区  · 7 年前

    我有一个hyperledger composer项目,它可以在本地主机上顺利运行,但我试图将它部署到google云计算引擎,但无法正常工作。

    该项目分为两部分:一个作曲家网络和一个与网络交互的nodejs后端。T

    我跟随开发人员,从composer站点部署到单个组织教程。

    nodejs服务器处理注册和登录逻辑,并公开rest api以与客户端交互。这是我的代码:

    索引文件

    //post call to register graduate on the network
    app.post('/api/registerGraduate', function(req, res) {
        console.log("Creando cuenta graduado");
        var graduateRut = req.body.graduaterut;
        var cardId = req.body.cardid;
        var firstName = req.body.firstname;
        var lastName = req.body.lastname;
        var email = req.body.email;
        var phoneNumber = req.body.phonenumber;
    
        network.registerGraduate(cardId, graduateRut, firstName, lastName, email, phoneNumber)
          .then((response) => {
           //return error if error in response
            if (response.error != null) {
                res.json({
                error: response.error
                });
              } else {
              //else return success
              res.json({
              success: response
                    });
                }
          });    
    });
    

    网络处理器JS

       registerGraduate: async function (cardId, graduateRut,firstName, lastName, email, phoneNumber) {
          try {
    
    
        //connect as admin
        businessNetworkConnection = new BusinessNetworkConnection();
        await businessNetworkConnection.connect('admin@degree');
    
        //get the factory for the business network
        factory = businessNetworkConnection.getBusinessNetwork().getFactory();
    
        //create graduate participant
        const graduate = factory.newResource(namespace, 'Graduate', graduateRut);
        graduate.firstName = firstName;
        graduate.lastName = lastName;
        graduate.email = email;
        graduate.phoneNumber = phoneNumber;
    
    
        //add graduate participant
        const participantRegistry = await businessNetworkConnection.getParticipantRegistry(namespace + '.Graduate');
        await participantRegistry.add(graduate);
    
        //issue identity
        const identity = await businessNetworkConnection.issueIdentity(namespace + '.Graduate#' + graduateRut, cardId);
    
        //import card for identity
        await importCardForIdentity(cardId, identity);
    
        //disconnect
        await businessNetworkConnection.disconnect('admin@degree');
    
        return true;
      }
      catch(err) {
        //print and return error
        console.log(err);
        var error = {};
        error.error = err.message;
        return error;
      }
    
    },
    

    我正在跟邮递员测试rest api。我回来的错误是 "error": "Cannot find module './local_connection.json'" 但这种情况只有在我第一次发送post请求时才会发生。第二次错误是 Error: Failed to add object with ID '166438715' in collection with ID 'Participant:org.degree.ucsd.University' as the object already exists .

    显然,尽管错误是将数据写入链链,但是如果我试图得到数据,我会得到一个错误,说明 cardid 找不到。

    那么,我错过了什么?如果它在本地主机上工作,而不是在google vm上,那么它是身份验证吗?我该怎么解决?

    谢谢你的帮助!

    编辑!

    importCardForIdentity函数:

    async function importCardForIdentity(cardName, identity) {
    
      //use admin connection
      adminConnection = new AdminConnection();
      businessNetworkName = 'degree';
    
      //declare metadata
      const metadata = {
          userName: identity.userID,
          version: 1,
          enrollmentSecret: identity.userSecret,
          businessNetwork: businessNetworkName
      };
    
      //get connectionProfile from json, create Idcard
      const connectionProfile = require('./local_connection.json');
      const card = new IdCard(metadata, connectionProfile);
    
      //import card
      await adminConnection.importCard(cardName, card);
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Paul O'Mahony    7 年前

    报告的第二个错误是(如您所示),参与者已创建。

    真正的问题是尝试从你的客户端REST API或邮递员中找到新发布的“毕业证书”业务网卡(“未找到”)。在当前的安装中,它会在$home//Cyror下的同一个客户端上查找这个。这是在你的NoDEJS后端的一个不同的节点上吗?

    也是你的 ImportCardForIdentity 像这里所示的功能?

    Unable to issue identity card using Hyperledger Composer Javascript API

    推荐文章