Hyperledger Composer: Difference between revisions
No edit summary |
No edit summary |
||
Line 90: | Line 90: | ||
* <code>Yes</code> |
* <code>Yes</code> |
||
* <code>No</code> |
* <code>No</code> |
||
== Congratulation ! == |
|||
[[File:UGAChain-HyperledgerSwagger.jpg]] |
|||
You should see this result in your browser |
|||
Sources: |
Sources: |
Revision as of 07:55, 15 March 2018
This tutorial is inspired by the two tutorials linked at the end of this page.
Prerequisites
Tools:
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 ./downloadFabric.sh
Launch some Fabric dockers
cd ~/fabric-tools ./startFabric.sh
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 }
Generate a business network archive
Now that the business network has been defined, it must be packaged into a deployable business network archive (.bna) file. From the tutorial-network directory, run the following command:
composer archive create -t dir -n .
Deploying the business network
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName tutorial-network composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile tutorial-network@0.0.1.bna --file networkadmin.card composer card import --file networkadmin.card composer network ping --card admin@tutorial-network
Generating a REST server
composer-rest-server
admin@tutorial-network
never use namespaces
No
Yes
No
Congratulation !
File:UGAChain-HyperledgerSwagger.jpg
You should see this result in your browser
Sources: