从零部署Hyperledger Composer

从零部署Hyperledger Composer

此文档为官方教程的整合,官方教程

配置开发环境

准备环境

  • Ubuntu Linux 14.04 / 16.04 LTS
  • Docker Engine:版本17.03或更高版本
  • Docker-Compose:版本1.8或更高版本
  • Node: 8.9 or higher (note version 9 is not supported)
  • npm: v5.x
  • git: 2.9.x or higher
  • Python: 2.7.x

you can download the prerequisites using the following commands:

curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh

chmod u+x prereqs-ubuntu.sh

Next run the script - as this briefly uses sudo during its execution, you will be prompted for your password.

./prereqs-ubuntu.sh

安装开发环境

不应使用susudo执行以下安装命令

Step 1: Install the CLI tools
  1. Essential CLI tools:

    npm install -g composer-cli@0.19
  2. Utility for running a REST Server on your machine to expose your business networks as RESTful APIs:

    npm install -g composer-rest-server@0.19
  3. Useful utility for generating application assets:

    npm install -g generator-hyperledger-composer@0.19
  4. Yeoman is a tool for generating applications, which utilises generator-hyperledger-composer:

    npm install -g yo
Step 2: Install Playground

Browser app for simple editing and testing Business Networks:

npm install -g composer-playground@0.19
Step 3: Set up your IDE

VSCode中打开composer的代码,会自动提示安装插件以支持.cto .qry等文件。

Step 4: Install Hyperledger Fabric

This step gives you a local Hyperledger Fabric runtime to deploy your business networks to.

  1. In a directory of your choice (we will assume ~/fabric-dev-servers), get the .tar.gz file that contains the tools to install Hyperledger Fabric:

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

    A zip is also available if you prefer: just replace the .tar.gz file with fabric-dev-servers.zip and the tar -xvf command with a unzip command in the preceding snippet.

  2. Use the scripts you just downloaded and extracted to download a local Hyperledger Fabric v1.1 runtime:

    cd ~/fabric-dev-servers
    export FABRIC_VERSION=hlfv11
    ./downloadFabric.sh

至此,开发环境已部署好了。

开发及部署

创建业务网络结构(Creating a business network structure)

The key concept for Hyperledger Composer is the business network definition (BND). It defines the data model, transaction logic and access control rules for your blockchain solution. To create a BND, we need to create a suitable project structure on disk.

Create a skeleton business network using Yeoman. This command will require a business network name, description, author name, author email address, license selection and namespace.

yo hyperledger-composer:businessnetwork

然后会有交互式的选项,按实际开发情况填写。此命令用于生成一个BND的框架。

框架结构如下:

models/ (optional)                      # 模型文件 .cto
lib/                                   # 脚本文件 .js
permissions.acl (optional)               # 权限控制
package.json
README.md (optional)

然后根据项目需求进行开发,VSCode中有支持Composer开发的插件。

References

打包业务网络(生成.bna)

开发完,即定义好business network之后,需要将它打包成.bna文件,才能部署。

进入到business network的项目目录,执行以下命令

composer archive create -t dir -n .

然后会在当前目录生成一个.bna文件

部署业务网络

创建好.bna文件之后,可以将业务网络部署到Hyperledger Fabric实例。

将业务网络部署到Fabirc的前提是:已导入PeerAdminCard并开启Fabirc

  • 导入PeerAdminCard
./createPeerAdminCard.sh
  • 开启Fabirc
~/fabric-dev-servers/startFabric.sh
  1. To install the business network, from the tutorial-network directory, run the following command:

    composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna

    The composer network install command requires a PeerAdmin business network card (in this case one has been created and imported in advance), and the the file path of the .bna which defines the business network.

  2. To start the business network, run the following command:

    composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card

    The composer network start command requires a business network card, as well as the name of the admin identity for the business network, the name and version of the business network and the name of the file to be created ready to import as a business network card.

  3. To import the network administrator identity as a usable business network card, run the following command:

    composer card import --file networkadmin.card

    The composer card import command requires the filename specified in composer network start to create a card.

  4. To check that the business network has been deployed successfully, run the following command to ping the network:

    composer network ping --card admin@tutorial-network

    The composer network ping command requires a business network card to identify the network to ping.

自动生成并开启REST服务器

To create the REST API, navigate to the tutorial-network directory and run the following command:

composer-rest-server

然后会出现交互式的设置,按需求配置即可。

开发环境的相关控制

The first time you start up a new runtime, you’ll need to run the start script, then generate a PeerAdmin card:

配置环境变量:

    cd ~/fabric-dev-servers
    export FABRIC_VERSION=hlfv11
开启Fabric:
./startFabric.sh
创建PeerAdminCard
./createPeerAdminCard.sh
启动playground
composer-playground
启动rest-api
composer-rest-server
删除前一个配置

If you’ve previously used an older version of Hyperledger Composer and are now setting up a new install, you may want to kill and remove all previous Docker containers, which you can do with these commands:

    docker kill $(docker ps -q)
    docker rm $(docker ps -aq)
    docker rmi $(docker images dev-* -q)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值