Hyperledger Composer

From air
Jump to navigation Jump to search



npm install -g composer-cli
npm install -g composer-rest-server
npm install -g generator-hyperledger-composer
npm install -g yo

Hyperledger Fabric:

mkdir ~/fabric-tools && cd ~/fabric-tools
curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
unzip fabric-dev-servers.zip

cd ~/fabric-tools

Generate a business network structure

yo hyperledger-composer:businessnetwork
  • Enter tutorial-network for the network name, and desired information for description, author name, and author email.
  • Select Apache-2.0 as the license.
  • Select org.acme.biznet as the namespace.

Defining a business network

A business network is made up of assets, participants, transactions, access control rules, and optionally events and queries. In the skeleton business network created in the previous steps, there is a model (.cto) file which will contain the class definitions for all assets, participants, and transactions in the business network. The skeleton business network also contains an access control (permissions.acl) document with basic access control rules, a script (logic.js) file containing transaction processor functions, and a package.json file containing business network metadata.

The first document to update is the model (.cto) file. This file is written using the Hyperledger Composer Modelling Language. The model file contains the definitions of each class of asset, transaction, participant, and event. It implicitly extends the Hyperledger Composer System Model described in the modelling language documentation.

Open the org.acme.biznet.cto model file to edit it.

The transaction processor function file contains the JavaScript logic to execute the transactions defined in the model file.

Open the logic.js script file to edit 

Adding access control (optionnal)

  • Create a permissions.acl file in the tutorial-network directory.
  • Add the following access control rules to permissions.acl:
 * Access control rules for tutorial-network
 rule Default {
    description: "Allow all participants access to all resources"
    participant: "ANY"
    operation: ALL
    resource: "org.acme.biznet.*"
    action: ALLOW

 rule SystemACL {
   description:  "System ACL to permit all access"
   participant: "ANY"
   operation: ALL
   resource: "org.hyperledger.composer.system.**"
   action: ALLOW