Hyperledger Composer Modeling Language
Hyperledger Composer Modeling Language
/**
* Abstract system asset that all assets extend.
* Has no properties, and is solely used as a basis to model other assets.
*/
@docs('asset.md')
abstract asset Asset { }
/**
* Abstract system participant that all participants extend.
* Has no properties, and is soley used as a basis to model other assets.
*/
@docs('participant.md')
abstract participant Participant { }
/**
* Abstract transaction that all transactions, including system ones, extend.
*
* Has two properties that are used set and are accessible in all transactions.
*
*
* @param {String} transactionId Identifier for this transaction
* @param {DateTime} timestamp Timestamp for this transaction
*/
@docs('transaction.md')
abstract transaction Transaction identified by transactionId {
o String transactionId
o DateTime timestamp
}
/**
* Abstract event that all events, including system ones, extend.
*
* Has two properties that are used set and are accessible in all transactions.
*
* @param {String} eventId Identifier for this event
* @param {DateTime} timestamp Timestamp for this event
*/
@docs('event.md')
abstract event Event identified by eventId {
o String eventId
o DateTime timestamp
}
/**
* Abstract Registry asset, that is used as the basis for all types of registries.
*
* @param {String} registryId identity
* @param {String} name Name of the registry
* @param {String} type type of the registry
* @param {Boolean} system Is this a system registry?
*/
@docs('registry.md')
abstract asset Registry identified by registryId {
o String registryId
o String name
o String type
o Boolean system
}
• And so on…..
• Get complete list from -
https://github.com/hyperledger/composer/blob/master/packages/composer-common/lib/system/org.hyperledger.com
poser.system.cto
• In the system namespace definitions, asset and
participant have no required values.
• Events and transactions are defined by an
eventId or transactionId and a timestamp.
• The system namespace also includes definitions
of registries, historian records, identities, and a
number of system transactions.
• Note - If you have defined an event or
transaction including an eventId, transactionId,
or timestamp, you must delete the eventId,
transactionId, or timestamp properties.
• Declarations of resources
• Resources in Hyperledger Composer include:-
• Assets, Participants, Transactions, and Events.
• Enumerated Types.
• Concepts.
• Assets, Participants and Transactions are class
definitions. The concepts of Asset, Participant and
Transaction may be considered to be different
stereotypes of the class type.
• A class in Hyperledger Composer is referred to as a
Resource Definition, therefore an asset instance has
an Asset Definition.
• A resource definition has the following properties:-
1- A namespace defined by the namespace of its parent file. The
namespace of a .cto file implicitly applies to all resources created in
it.
2- A name, for example Vehicle, and an identifying field, for
example, vin. If the resource is an asset or participant, the name is
followed by the identifying field, if the resource is an event or
transaction, the identifying field is set automatically. In this
example, the asset is named Vehicle and the identifying field is vin.
/**
* A vehicle asset.
*/
asset Vehicle identified by vin {
o String vin
}
3- An optional super-type, which the resource definition extends. The
resource will take all properties and fields required by the super-type
and add any additional properties or fields from its own definition.
/**
* A car asset. A car is related to a list of parts
*/
asset Car extends Vehicle {
o String model
--> Part[] Parts
}
4- An optional 'abstract' declaration, to indicate that this type cannot be
created. Abstract resources can be used as a basis for other classes to
extend. Extensions of abstract classes do not inherit the abstract status.
For example, the asset Vehicle defined above should never be created,
as there should be more specific asset classes defined to extend it.
/**
* An abstract Vehicle asset.
*/
abstract asset Vehicle identified by vin {
o String vin
}
5- A set of named properties. The properties must be named,
and the primitive data type defined.The properties and their
data are owned by each resource, for example, a Car asset
has a vin, and a model property, both of which are strings.
6- A set of relationships to other Composer types that are not
owned by the resource but that may be referenced from the
resource. Relationships are unidirectional.
/**
* A Field asset. A Field is related to a list of
animals
*/
asset Field identified by fieldId {
o String fieldId
o String name
--> Animal[] animals
}
• Declarations of enumerated types
• Enumerated types are used to specify a type that may have
1 or N possible values. The example below defines the
ProductType enumeration, which may have the
value DAIRY or BEEF or VEGETABLES.
/**
* An enumerated type
*/
enum ProductType {
o DAIRY
o BEEF
o VEGETABLES
}
• When another resource is created, for
example, a participant, a property of that
resource can be defined in terms of an
enumerated type.
participant Farmer identified by farmerId {
o String farmerId
o ProductType primaryProduct
}
• Concepts (User Defined Data Types) –
• Concepts are abstract classes that are not assets, participants or transactions.
They are typically contained by an asset, participant or transaction.
• For example, below an abstract concept Address is defined, and then
specialized into a UnitedStatesAddress. Note that concepts do not have
an identified by field as they cannot be directly stored in registries or
referenced in relationships.
abstract concept Address {
o String street
o String city default ="Winchester"
o String country default = "UK"
o Integer[] counts optional
}