0

I am quite new to Hyperledger Composer and I really need your help guys!

I need an asset that would be defined dynamically with N amount of properties which aren't known at this moment and would be defined by the end user.

I assume that this could be done by using decorators in the modeling language, but I didn't find any examples that fully explains how to use them including Front-End interaction.

To be more clear I need an advice on how is it possible to implement something like this as a result:

asset $CustomNameFromFrontEnd {
o String id
o $TypeFromFrontEnd1 $PropertyNameFromFrontEnd1
o $TypeFromFrontEnd2 $PropertyNameFromFrontEnd2
…
o $TypeFromFrontEndN $PropertyNameFromFrontEndN
}

I would really appreciate if someone could help me with an example how should I describe the asset in .cto file and how should I implement asset creation in the logic.js file.

Taras
  • 13
  • 2
  • I've already read https://github.com/hyperledger/composer/issues/2157 but this doesn't clarify for me how to deal with decorators... – Taras Jun 05 '18 at 11:29

2 Answers2

0

I don't think Decorators, documented at the bottom of the Modeling Language topic, do what you want. Decorators are added to the model at design time, just like all the properties. For example, you could add annotations to influence some UI code generation:

@frontEndApp("customArgument") asset CustomAsset { o String id o String customProperty1 }

Depending on how often the shape of the data changes, and what proportion of the data is dynamic, you might be able to try:

  • generating a model based on input from a front end app (pretty much the yo generator use case)
  • using a static model for most of the data but using getNativeAPI in your logic for small pieces of data that do not have a model
  • using Fabric without the Composer tools
James Taylor
  • 785
  • 5
  • 19
  • Maybe then it is possible to create a concept with decorator like that: `@customData('fieldName', 1) concept CustomField { o String fieldName }` and then create an asset with decorator that would pass as many this CustomFields as were sent from fronEnd? – Taras Jun 05 '18 at 14:13
  • I was so disturbed with this issue, that forgot to thank you). Could you please give me some additional info about "generating a model based on input from a front end app". I assume that's what I want. The goal is to make asset with fields which will be defined by user in some form on front-end. – Taras Jun 05 '18 at 14:29
  • I don't think combining a concept with decorator is going to help, since they are both still design time concepts. When you say 'The goal is to make asset with fields which will be defined by user in some form on front-end' - is this for a tool to help people create entire business networks, or something to customise the names of a small number of fields in an otherwise well defined model? The `yo hyperledger-composer:businessnetwork` is used in the developer tutorial if that helps https://hyperledger.github.io/composer/latest/tutorials/developer-tutorial – James Taylor Jun 05 '18 at 15:38
0

I've figured out how to deal with that. Maybe it will be useful to someone else. Here is how I defined CustomAsset:

enum FieldType {
 o String
 o Double
 o Boolean
 o Integer
 o DateTime
 o Long
}

concept customFieldName {
 o String customFieldName
}

concept customFieldValue {
 o FieldType customFieldValue
}

concept customField {
 o customFieldName customFieldName
 o customFieldValue customFieldValue
}

asset CustomAsset identified by id {
 o String id
 o String assetName
 o customField[] customFields
}

transaction CreateCustomAsset {
 o CustomAsset customAsset
}
Taras
  • 13
  • 2
  • Have you tried that in the online playground? I don't think it does quite what you want. This might work... ``` concept customField { o String customFieldName o FieldType customFieldType o String customFieldValue } ``` I'll add it to my answer if I get a chance to test it. – James Taylor Jun 06 '18 at 09:05