0

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
}

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

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';

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

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.

Bob Dill
  • 1,000
  • 5
  • 13
  • as Dan pointed out, I appear to be having a related problem: https://stackoverflow.com/questions/45951060/attempt-to-launch-hyperledger-composer-app-using-npm-start-gives-cannot-find-na – JP Lew Aug 30 '17 at 18:10
  • Yes, same issue for both of us. – Bob Dill Aug 30 '17 at 19:05

2 Answers2

0

This does indeed look like a bug. I will investigate, create an issue and fix.

Dan Selman
  • 2,287
  • 2
  • 9
  • 18
  • as per Bob's suggestion, I managed to compile successfully by hardcoding those import commands into their respective files. In my case it looked like this: `import {ContactDetails} from './composer.base'; import {MedicalDevice} from './composer.manufacturer'; import {Distributor} from './composer.distributor';` – JP Lew Aug 30 '17 at 20:39
  • Perhaps I'm missing a critical step somewhere, but it still fails. I've checked to make sure that the docker images are current, updated the binaries, updated the global npm modules and run the exec to both use an existing rest interface and to generate its own, use namespaces or not and get the same failure every time. – Bob Dill Sep 05 '17 at 13:00
  • What version are you using? There was a fix went in for this in 0.12.0 – Dan Selman Sep 06 '17 at 07:56
0

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.

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.

Bob Dill
  • 1,000
  • 5
  • 13
  • You can confirm on your own, but looks like they fixed the bug: https://stackoverflow.com/a/46028359/1011766. – JP Lew Sep 03 '17 at 22:32