Network model file (.cto)

A CTO file is composed of the following elements:

Element

Description

A single namespace

Defines the composer model namespace; every .cto model file requires a namespace.

Resources - asset

Anything of value that can be exchanged between parties.

Resources - participant

Business network member.

Resources - enum

A data type consisting of a set of named values.

Resources - concept

Any object you want to model that is not one of the other types.

Resources - transactions

Defines the blockchain business logic.

Resources - events

Blockchain transaction notification.

Import

Imports resources from other namespaces.

 

The composer model language, like other programming languages, has data types including String, Double, Integer, and so on.

Let's see some samples of assets, participants, transactions, and events.

IBM Bluemix provides a browser version playground without installation; we can use this tool to do a quick prototype. Here is the link: https://composer-playground.mybluemix.net/.

Connect to basic-sample-network. Playground will generate some default sample assets, participants, transactions, and events for you, for example:

sample.cto
/**
* Sample business network definition.
*/
namespace org.example.basic
asset SampleAsset identified by assetId {
o String assetId
--> SampleParticipant owner
o String value
}
participant SampleParticipant identified by participantId {
o String participantId
o String firstName
o String lastName
}
transaction SampleTransaction {
--> SampleAsset asset
o String newValue
}
event SampleEvent {
--> SampleAsset asset
o String oldValue
o String newValue
}

A namespace org.example.basic was defined in sample.cto.SampleAsset and is an example of an Asset class. It defines an asset whose name is followed by an identifying field.o String assetId: a field of the SampleAsset.--> SampleParticipant owner:  field point to SampleParticipant instance.SampleParticipant is an example of a Participant class, the syntax is similar to SampleAsset.SampleTransaction is an example of a transaction class.SampleEvent is an example of an event class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.139.169