创建一个业务网络定义

业务网络定义具有以下布局:

  1. models/ (optional)
  2. lib/
  3. permissions.acl (optional)
  4. package.json
  5. README.md (optional)

创建新的业务网络定义的最简单的方法是git clone范例,或者使用Hyperledger Composer Yeoman生成器来创建骨架业务网络。

README.md

使用Markdown标记语言描述业务网络的意图。

Package.json

业务网络定义有一个名称(仅限于基本的ASCII字母数字字符和-)、一个可读的描述和一个版本号。网络的版本号应采用Major.Minor.Micro形式 ,增加版本号时应使用Semantic Versioning原则。

网络的标识符由其名称、-字符和版本号组成。一个有效的标识符(和例子)类似于mybusinessnetwork-1.0.3

业务网络定义的元数据从package.json中读取,这意味着业务网络定义也是有效的npm包。

模型

业务网络定义的领域模型集定义了用于网络内的有效类型,和用于与外部系统(例如,向网络提交交易的系统)集成的有效类型。

领域模型可以打包在业务网络定义中(通常存储在models目录下),也可以在package.json中声明为外部依赖。如果您想跨业务网络定义共享模型,则可以通过npm依赖引用模型。

脚本

业务网络定义的脚本通常存储在lib目录下,并打包在业务网络定义中。这些脚本是用ES 5 JavaScript编写的,并引用在业务网络的域模型中定义的类型。

Permissions.acl

表示的业务网络的权限表示在一个可选permissions.acl文件中。

克隆一个示例业务网络定义

示例业务网络定义存储在GitHub上https://github.com/hyperledger/composer-sample-networks。你可以通过git clone这个存储库来拉取所有的示例网络。每个示例网络都存储在packages目录下。

生成业务网络定义

生成

1.yo hyperledger-composer

  1. Welcome to the Hyperledger Composer Skeleton Application Generator
  2. ? Please select the type of Application: (Use arrow keys)
  3. CLI Application
  4. Angular 2 Application
  5. Skeleton Business Network

并选择 Skeleton Business Netork

2.回答所有的问题

  1. ? Please select the type of Application: Skeleton Business Network
  2. You can run this generator using: 'yo hyperledger-composer:businessnetwork'
  3. Welcome to the business network skeleton generator
  4. ? Do you only want to generate a model? Yes
  5. ? What is the business network's name? mynetwork
  6. ? What is the business network's namespace? org.example
  7. ? Describe the business network This is my test network
  8. ? Who is the author? Dan Selman
  9. ? Which license do you want to use? Apache-2
  10. create index.js
  11. create package.json
  12. create README.md
  13. create models/org.example.cto
  14. create .eslintrc.yml

这产生了骨架业务网络与assetparticipanttransaction定义,以及一个mocha单元测试。

还包括一个“最佳实践”eslint配置文件,它定义了JS代码的示例linting 规则。

参考