• teague_dai
    了解作者
  • Node.js
    开发工具
  • 232KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 4
    下载次数
  • 2020-08-30 10:56
    上传日期
探索一个用例和详细的应用程序开发教程,其中两个组织使用区块链网络来交易商业票据。
commercial-paper.zip
内容介绍
# Commercial Paper Tutorial This folder contains the code for an introductory tutorial to Smart Contract development. It is based around the scenario of Commercial Paper. The full tutorial, including full scenario details and line by line code walk-through is in the [Hyperledger Fabric Commercial Paper Tutorial](https://hyperledger-fabric.readthedocs.io/en/latest/tutorial/commercial_paper.html). ## Scenario In this tutorial two organizations, MagnetoCorp and DigiBank, trade commercial paper with each other using 'PaperNet', a Hyperledger Fabric blockchain network. Once you’ve set up a basic network, you’ll act as Isabella, an employee of MagnetoCorp, who will issue a commercial paper on its behalf. You’ll then switch hats to take the role of Balaji, an employee of DigiBank, who will buy this commercial paper, hold it for a period of time, and then redeem it with MagnetoCorp for a small profit. ![](https://hyperledger-fabric.readthedocs.io/en/latest/_images/commercial_paper.diagram.1.png) ## Quick Start You are strongly advised to read the full tutorial to get information about the code and the scenario. Below are the quick start instructions for running the tutorial, but without extensive details of what is happening. This `README.md` file is in the `commercial-paper` directory, the source code for client applications and the contracts is in the `organization` directory. ### Steps 1) Start the Hyperledger Fabric infrastructure The 'test-network' will be used - this has two organizations 'org1' and 'org2' DigiBank will be org1, and MagnetoCorp will be org2. 2) Install and Instantiate the Contracts 3) Run client applications in the roles of MagnetoCorp and DigiBank to trade the commercial paper - Issue the Paper as Magnetocorp (org2) - Buy the paper as DigiBank (org1) - Redeem the paper as DigiBank (org1) ## Setup You will need a machine with the following - Docker and docker-compose installed - Node.js v12 if you want to run JavaScript client applications - Java v8 if you want to run Java client applications - Maven to build the Java applications You will need to install the peer cli binaries and this fabric-samples repository available. For more information [Install the Samples, Binaries and Docker Images](https://hyperledger-fabric.readthedocs.io/en/latest/install.html) in the Hyperledger Fabric documentation. It is advised to have 3 console windows open; one to monitor the infrastructure and one each for MagnetoCorp and DigiBank. Once you've cloned the fabric-samples - change to the commercial-paper directory in each window. ``` cd fabric-samples/commercial-paper ``` ## Running the Infrastructure In one console window, run the `./network-starter.sh` script; this will start the basic infrastructure. You can re-use this console window if you wish, but it is recommended to run a docker container monitoring script. This will let you view what Fabric is doing and help diagnose any failures. ```bash ./organization/magnetocorp/configuration/cli/monitordocker.sh net_test ``` ### Setup the Organizations' environments The contract code is available as either JavaScript, Java or Go. You can use either one, and the choice of contract language does not affect the choice of client language. With the v2.0 Fabric chaincode lifecycle, this requires operations for both MagnetoCorp and Digibank admin. Open two windows in the fabric-samples/commercial paper directory, one for each organization. In your 'MagnetoCorp' window run the following commands, to show the shell environment variables needed to act as that organization. ``` cd fabric-samples/commercial-paper/organization/magnetocorp ./magnetocorp.sh ``` You can either copy and paste them directly into the terminal, or invoke directly in your own command shell. For example if you are using bash or zsh on Linux you can use this command. ``` source <(./magnetocorp.sh) ``` Similarly in your 'DigiBank' window run the following command ``` cd fabric-samples/commercial-paper/organization/digibank ./digibank.sh ``` ### Deploy the smart contract to the channel You need to perform similar operations for both organizations. For different contract languages the steps are very similar. The steps for JavaScript are shown first, with the details of different languages afterwards. **For a JavaScript Contract** Running in MagnetoCorp: ``` # MAGNETOCORP peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0 peer lifecycle chaincode install cp.tar.gz export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') echo $PACKAGE_ID peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ --channelID mychannel \ --name papercontract \ -v 0 \ --package-id $PACKAGE_ID \ --sequence 1 \ --tls \ --cafile $ORDERER_CA peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 ``` Running in Digibank ``` # DIGIBANK peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0 peer lifecycle chaincode install cp.tar.gz export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id') echo $PACKAGE_ID peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ --channelID mychannel \ --name papercontract \ -v 0 \ --package-id $PACKAGE_ID \ --sequence 1 \ --tls \ --cafile $ORDERER_CA peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name papercontract -v 0 --sequence 1 ``` Once both organizations have installed, and approved the chaincode, it can be committed. ``` # MAGNETOCORP peer lifecycle chaincode commit -o localhost:7050 \ --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ --ordererTLSHostnameOverride orderer.example.com \ --channelID mychannel --name papercontract -v 0 \ --sequence 1 \ --tls --cafile $ORDERER_CA --waitForEvent ``` To test try sending some simple transactions. ``` peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} \ --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} \ --channelID mychannel --name papercontract \ -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' ${PEER_ADDRESS_ORG1} ${PEER_ADDRESS_ORG2} \ --tls --cafile $ORDERER_CA --waitForEvent peer chaincode query -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com \ --channelID mychannel \ --name papercontract \ -c '{"Args":["org.hyperledger.fabric:GetMetadata"]}' \ --peerAddresses
评论
    相关推荐
    • hyperledger-fabric-desktop:general-purpose hyperledger-fabric de
      Hyperledger Fabric桌面 Hyperledger Fabric Desktop是一个开箱即用的桌面应用程序,旨在帮助人们轻松使用和管理Fabric网络。 主要特点 跨平台:适用于Windows,Mac和Linux。 易于安装。 用户友好的GUI:易于使用。...
    • hyperledger-fabric
      超级账本织物 Hyperledger Fabric 2.2版课程信息(2021年5月)
    • hyperledger fabric 1.2.0版本.rar
      Hyperledge fabric 环境搭建需要的2个二进制文件,1.2.0版本的(包含:hyperledger-fabric-linux-amd64-1.2.0.tar.gz 和 hyperledger-fabric-ca-linux-amd64-1.2.0.tar),官方下载,哇~~,真是慢的要死啦。...
    • gohfc:Go编写的Hyperledger Fabric SDK
      GOHFC-Golang Hyperledger Fabric客户端 这是使用最低要求以纯Golang编写的Hyperledger Fabric的SDK。 这不是官方的SDK,也不遵循Hyperledger团队提供的官方SDK API准则。 有关官方SDK的列表,请参考官方Hyperledger...
    • hyperledger fabric nodejs
      超级账本fabric nodejs接口程序,参考fabric-samples实例
    • Hyperledger Fabric 源码 例子 依赖工具
      Hyperledger Fabric 源码 例子 依赖工具 其中包含自动搭建开发环境脚本
    • hyperledger-fabric环境
      hyperledger-fabric1.0搭建好的环境,里面有bin文件夹,以及其他生成的文件
    • generator-fabric:Hyperledger Fabric的Yeoman生成器
      Hyperledger Fabric的Yeoman生成器。 该Yeoman生成器可用于生成Hyperledger Fabric的链码或智能合约。 可以生成用Go或JavaScript编写的链码,同时还提供实验性TypeScript支持。 安装 您必须安装Yeoman,这很容易: ...
    • hyperledger-fabricHyperledger结构
      Hyperledger Fabric 1.4.0 先决条件 帕拉facilitar,disponibilizei OS comandosnecessários对configurarØAMBIENTE德desenvolvimento,MAS recomendo fortemente阙acesse对SE familiarizar COM口requisitosbá...