`
Tzhennan
  • 浏览: 55583 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Hyperledger Composer使用

 
阅读更多

内存要求:

To run Hyperledger Composer and Hyperledger Fabric, we recommend you have at least 4Gb of memory.

 

开发工具:

Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or Mac OS 10.12

Docker Engine: Version 17.03 or higher

Docker-Compose: Version 1.8 or higher

Node: 8.9 or higher (note version 9 is not supported)

npm: v5.x

git: 2.9.x or higher

Python: 2.7.x

 

如果系统是Ubuntu,可以使用以下命令安装相应工具:

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

$ chmod u+x prereqs-ubuntu.sh

$ ./prereqs-ubuntu.sh

 

开发环境

CLI tools:

$ npm install -g composer-cli

REST Server:

$ npm install -g composer-rest-server

generating application assets:

$ npm install -g generator-hyperledger-composer

Yeoman:

$ npm install -g yo

 

浏览器应用(可选):

$ npm install -g composer-playground

启动composer-playground:

$ composer-playground

 

安装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.tar.gz

$ tar -zxvf fabric-dev-servers.tar.gz

下载本地Hyperledger Fabric runtime:

$ ./downloadFabric.sh

启动Hyperledger Fabric

$ ./startFabric.sh

生成PeerAdmin card

$ ./createPeerAdminCard.sh

 

======================================================================

Start a clean Hyperledger Fabric by running the following commands:

$ cd ~/fabric-tools

$ ./stopFabric.sh

#$ ./teardownFabric.sh

#$ ./downloadFabric.sh

$ ./startFabric.sh

 

Delete any business network cards that may exist in your wallet. It is safe to ignore any errors that state that the business network cards cannot be found:

$ composer card delete -n PeerAdmin@fabric-network

$ composer card delete -n admin@tutorial-network

======================================================================

 

Step 1: Creating a business network structure.

1、Create a skeleton business network using Yeoman

$ yo hyperledger-composer:businessnetwork

2、Enter tutorial-network for the network name, and desired information for description, author name, and author email.

3、Select Apache-2.0 as the license.

4、Select org.acme.biznet as the namespace.

 

Step 2: Defining a business network

1、Open the org.acme.biznet.cto model file.

2、Replace the contents with the following:

/**

 * My commodity trading network

 */

namespace org.acme.biznet

asset Commodity identified by tradingSymbol {

    o String tradingSymbol

    o String description

    o String mainExchange

    o Double quantity

    --> Trader owner

}

participant Trader identified by tradeId {

    o String tradeId

    o String firstName

    o String lastName

}

transaction Trade {

    --> Commodity commodity

    --> Trader newOwner

}

3、save

 

1、Open the logic.js script file.

2、Replace the contents with the following:

/**

 * Track the trade of a commodity from one trader to another

 * @param {org.acme.biznet.Trade} trade - the trade to be processed

 * @transaction

 */

function tradeCommodity(trade) {

    trade.commodity.owner = trade.newOwner;

    return getAssetRegistry('org.acme.biznet.Commodity')

        .then(function (assetRegistry) {

            return assetRegistry.update(trade.commodity);

        });

}

3、save

 

1、Create a permissions.acl file in the tutorial-network directory.

2、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

}

3、save

 

Step 3: Generate a business network archive

1、Using the command line, navigate to the tutorial-network directory.

2、From the tutorial-network directory, run the following command:

$ composer archive create -t dir -n .

会生成 tutorial-network@0.0.1.bna 文件

 

Step 4: Building a connection profile

1、Create a connection profile file called connection.json.

2、example

{

  "name": "fabric-network",

  "type": "hlfv1",

  "mspID": "Org1MSP",

  "peers": [

      {

          "requestURL": "grpc://localhost:7051",

          "eventURL": "grpc://localhost:7053"

      }

  ],

  "ca": {

      "url": "http://localhost:7054",

      "name": "ca.org1.example.com"

  },

  "orderers": [

      {

          "url" : "grpc://localhost:7050"

      }

  ],

  "channel": "composerchannel",

  "timeout": 300

}

3、save

 

Step 5: Locating the certificate and private key for the Hyperledger Fabric administrator

为方便操作,可将以下文件拷贝到同一个目录

文件1:connection.json

文件2:Admin@org1.example.com-cert.pem 位置(~/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem)

文件3:xxxx_sk 位置(~/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk)

 

Step 6: Creating a business network card for the Hyperledger Fabric administrator

$ composer card create -p connection.json -u PeerAdmin -c Admin@org1.example.com-cert.pem -k 114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk -r PeerAdmin -r ChannelAdmin

会生成PeerAdmin@fabric-network.card文件

 

 

Step 7: Importing the business network card for the Hyperledger Fabric administrator

$ composer card import -f PeerAdmin@fabric-network.card

 

Step 8: Installing the Hyperledger Composer runtime onto the Hyperledger Fabric peer nodes

即:Install Chaincode

$ composer runtime install -c PeerAdmin@fabric-network -n tutorial-network

 

Step 9: Starting the blockchain business network

即:Instantiate Chaincode

$ composer network start -c PeerAdmin@fabric-network -a tutorial-network@0.0.1.bna -A admin -S adminpw

会生成admin@tutorial-network.card文件

 

Step 10: Importing the business network card for the business network administrator

$ composer card import -f admin@tutorial-network.card

 

Step 11: Testing the connection to the blockchain business network

$ composer network ping -c admin@tutorial-network

 

Step 12: Generating a REST server

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

$ composer-rest-server

2、Enter admin@tutorial-network as the card name.

3、Select never use namespaces when asked whether to use namespaces in the generated API.

4、Select No when asked whether to secure the generated API.

5、Select Yes when asked whether to enable event publication.

6、Select No when asked whether to enable TLS security.

 

=====================================================================

Appendix: destroy a previous setup

$ docker kill $(docker ps -q)

$ docker rm $(docker ps -aq)

$ docker rmi $(docker images dev-* -q)

=====================================================================

 

=====================================================================

After changing the files in a business network, the business network must be repackaged as a business network archive (.bna) and redeployed to the Hyperledger Fabric instance.

Regenerate your business network archive

$ composer archive create --sourceType dir --sourceName . -a tutorial-network@0.0.1.bna

 

Deploy the updated business network definition

$ composer network update -a tutorial-network@0.0.1.bna -c admin@tutorial-network

 

Test that the network is deployed

$ composer network ping -c admin@tutorial-network

=====================================================================

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics