Name: BlockchainEvents-CompositeJourney
Owner: International Business Machines
Description: Part 3 in a series of patterns showing the building blocks of a Blockchain application
Created: 2017-11-29 22:00:15.0
Updated: 2018-05-22 22:34:22.0
Pushed: 2018-05-22 22:34:21.0
Homepage: https://developer.ibm.com/code/patterns/automate-business-processes-via-blockchain-events/
Size: 202
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Read this in other languages: ???,??
Welcome to Part 3 of the Hyperledger Composer Composite Pattern. This is a continuation of Hyperledger Composer - Product Auction Network. This pattern shows how events can be emitted by Hyperledger Composer and subscribed by external applications.
Audience level : Intermediate Developers
If you have an IBM Cloud Lite account, you can also use the Starter Plan for 30 days to do this pattern.
Make sure that you have installed the prerequisites for Hyperledger Composer. Also, make sure that you have installed the development environment which includes Hyperledger Composer, Hyperledger Fabric and the other node modules using these instructions. As a recap for those instructions, you should have done the following:
npm
.createPeerAdminCard.sh
to create a network card that will be used to
install the business network later in this exercise.Clone the repository:
t clone https://github.com/IBM/BlockchainEvents-CompositeJourney.git
To check that the structure of the files is valid, you can now generate a
Business Network Archive (BNA) file for your business network definition. The
.bna
file is the deployable unit – a file that can be deployed to the
Hyperledger Composer runtime for execution.
Use the following command to generate the network archive:
BlockchainEvents-CompositeJourney/Composer
m install
You should see the following output:
dirp ./dist && composer archive create --sourceType dir --sourceName . -a ./dist/events.bna
ting Business Network Archive
ing for package.json of Business Network Definition
Input directory: /Users/ishan/Documents/demo/BlockchainEvents-CompositeJourney/Composer
d:
Description: Sample product auction network with events
Name: events
Identifier: events@0.0.1
ten Business Network Definition Archive file to
Output file: ./dist/events.bna
and succeeded
The composer archive create
command has created a file called events.bna
in
the dist
folder.
You can test the business network definition against the embedded runtime that stores the state of 'the blockchain' in-memory in a Node.js process. From your project working directory, open the file test/productAuction.js and run the following command:
m test
You should see the following output :
ents@0.0.1 test /Users/ishan/Documents/demo/BlockchainEvents-CompositeJourney/Composer
c mocha -t 0 test/*.js
rg.acme.product.auction
? Authorized owner should start the bidding (74ms)
? Members bid for the product (139ms)
? Close bid for the product (175ms)
passing (2s)
------|----------|----------|----------|----------|-------------------|
| % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------|----------|----------|----------|----------|-------------------|
files | 0 | 0 | 0 | 0 | |
------|----------|----------|----------|----------|-------------------|
Make sure that you have started Hyperledger Fabric instance locally on your machine
using these instructions.
Now change directory to the dist
folder containing events.bna
file and execute
the following commands to install/deploy and start the business network on the
local Hyperledger Fabric instance:
BlockchainEvents-CompositeJourney/Composer/dist
mposer network install -c PeerAdmin@hlfv1 -a events.bna
mposer network start -c PeerAdmin@hlfv1 -n events -V 0.0.1 -A admin -S adminpw -f networkadmin.card
mposer card import --file networkadmin.card
You can verify that the network has been deployed by typing:
mposer network ping --card admin@events
You should see the the output as follows:
connection to the network was successfully tested: events
connection to the network was successfully tested: events
Business network version: 0.0.1
Composer runtime version: 0.19.5
participant: org.hyperledger.composer.system.NetworkAdmin#admin
identity:org.hyperledger.composer.system.Identity#e7eaa3bc255f5ded89fd5c25748aca87959c9b3fc6ad6a94c65d679162db84fd
and succeeded
To create the REST API we need to launch the composer-rest-server
and tell it how to connect to our deployed business network. Now launch the server by changing directory to the product-auction folder and type:
BlockchainEvents-CompositeJourney/Composer
mposer-rest-server
ter the name of the business network card to use: admin@events
ecify if you want namespaces in the generated REST API: never use namespaces
ecify if you want to use an API key to secure the REST API: No
ecify if you want to enable authentication for the REST API using Passport: No
ecify if you want to enable event publication over WebSockets: Yes
ecify if you want to enable TLS security for the REST API: No
Test REST API
If the composer-rest-server
started successfully you should see these two lines are output:
server listening at: http://localhost:3000
se your REST API at http://localhost:3000/explorer
In a new terminal window, navigate to Web
directory and launch the node server using command:
lockchainEvents-CompositeJourney/Web
m install
de server.js
Submit transactions for auction network using the instructions in Hyperledger Composer Section. Events are emitted when user submits publishListing
,
makeoffer
and closeBidding
transactions. Web UI for seller and buyer updates
on the event emitted from the Hyperledger Fabric network.
You can submit the transactions either by using Hyperledger Composer REST API or Hyperledger Composer Playground running locally.
Open a web browser and navigate to http://localhost:3000/explorer
.
You can Install the Hyperledger Composer Playground locally as shown below:
m install -g composer-playground
And, run the Hyperledger Composer Playground locally using:
mposer-playground
Navigate to http://localhost:8000/seller.html
and http://localhost:8000/buyer.html
to view the dashboards for Seller and Buyer events.