执行yo hyperledger-composer无法正确导入模型 [英] Executing yo hyperledger-composer fails to correctly import model

查看:146
本文介绍了执行yo hyperledger-composer无法正确导入模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建一个基于hyperledger-composer的简单应用程序,并使用类似于车辆生命周期示例代码中的模型定义.具体来说,我有两个模型文件: base.cto

Building a simple hyperledger-composer based app and using model definitions similar to those in the vehicle-lifecycle sample code. Specifically, I have two model files: base.cto

namespace composer.base

abstract participant Member {
  o String companyName
}

和sample.cto(部分列表)

and sample.cto (partial listing)

namespace org.acme.Z2BTestNetwork
import composer.base.*
import composer.events.*

participant Buyer identified by buyerID extends Member{
    o String buyerID
}
participant Seller identified by sellerID extends Member{
    o String sellerID
}

asset Order identified by orderNumber {
    o String orderNumber
    o String[] items

我能够使用此结构成功构建网络并使用composer-rest-server服务和基于Bluemix的composer来测试网络.但是,yo生成的应用程序找不到"Member",显然在生成和生成过程中未导入base.cto文件. yo为该网络的model文件夹中的每个文件生成一个.ts文件.对应于"sample.cto"的.ts文件包含以下内容,但是缺少base.cto文件(位于另一个.ts文件中)的抽象定义,并且缺少指向该文件的任何链接.

I am able to successfully build the network using this structure and test the network, both using the composer-rest-server service and the Bluemix based composer. However a yo-generated app is unable to find "Member", apparently not importing the base.cto file during the generate and build process. yo generates a .ts file for each of the files in the model folder for this network. The .ts file which corresponds to 'sample.cto' contains the following, however it is missing the abstract definition from the base.cto file (which is in a different .ts file) and it is missing any link to that file.

import {Asset} from './org.hyperledger.composer.system';
import {Participant} from './org.hyperledger.composer.system';
import {Transaction} from './org.hyperledger.composer.system';
import {Event} from './org.hyperledger.composer.system';
// export namespace org.acme.Z2BTestNetwork{
   export class Buyer extends Member {
      buyerID: string;
   }
   export class Seller extends Member {
      sellerID: string;
   }
   export class Shipper extends Member {
      shipperID: string;
   }
   export class Provider extends Member {
      providerID: string;
   }
   export class FinanceCo extends Member {
      financeCoID: string;
   }
   export class Order extends Asset {
      orderNumber: string;
      items: string[];

此应用需要附加的导入语句才能正常运行.

An additional import statement is required for this app to function correctly.

import {Member} from './org.acme.Z2BTestNetwork.base';

对于hyperledger-composer,这似乎是yo的此实现中的一个错误.关于自动修复此问题的任何建议?

This appears to be a bug in this implementation of yo for hyperledger-composer. Any recommendations on automating a fix for this?

注意,如果选择了使用命名空间的yo选项,则sample.cto仅生成一个文件. base.cto文件不再导致生成.ts文件;但是,由于缺少base.cto文件中定义的Member的抽象定义,因此未使用base.cto文件中的定义,并且应用仍然无法加载.

Note if the yo option to use namespaces is selected, then only a single file is generated from sample.cto. The base.cto file no longer causes a .ts file to be generated; however the definitions from the base.cto file are not used and the app still fails to load because of the missing abstract definition for Member defined in the base.cto file.

推荐答案

在修复该错误之前,有手动解决方法.那就是在基本的.ts文件中添加必要的import语句-在我的情况下,这将是org.acme.Z2BTestNetwork.ts文件.目标环境中需要的每个类都需要导入.因为我只缺少一个类(成员),所以只需要一个import语句.

Until the bug is fixed, there is a manual work-around. That is to add in the necessary import statements to the base .ts file - in my case, that would be the org.acme.Z2BTestNetwork.ts file. An import is required for each of the classes which you will need in your target environment. As I was only missing a single class (Member), only one import statement was required.

如果存在许多必需的import语句,则可以构建一个蛮力的bash exec来将必要的文件合并在一起,直到解决为止.

It would be possible to build a brute force bash exec to merge the necessary files together as an alternative until this is resolved if there were many required import statements.

这篇关于执行yo hyperledger-composer无法正确导入模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆