Team 12 - Blockchain project repository
The repository is split into three parts:
- Hyperledger part that includes chaincode and the node.js restful API,
- User interface components
- Reports and presentations.
There are extended readmes available under some of the folders.
The hyperledger part is located in the fabric_network folder. This contains both the restful API and chaincode. Key parts of this folder:
- /models/nl.tudelft.blockchain.logistics.cto - contains general model descriptions for the whole application
- /lib/logic.js - contains the chaincode itself. This is the code that will be run on the blockchain.
- /rest_client - contains the entire restful application. This includes javascript models, services, app.js entrypoint, test initialization classes, routing.
After installing everything (see below), this would be the normal flow you should follow when developing chaincode and REST api.
Key files that you would need to modify in order to change chaincode are:
logic.js
mentioned above.- Model file mentioned above
queries.qry
file contains query definition for querying blockchain information.permissions.acl
permission list for different users
If you turned on the computer you need to run our start_network.sh
script that initializes everything for testing.
After making any modifications to these files, you would need to run update_network.sh
. Your network will then run on the new code.
Found in the /rest_client
folder this is a basic node.js implementation.
In order to run it, navigate to that folder and run:
node app.js
Then your api will be accessible at:
localhost:8081/
After making changes, save the files, stop node.js and run the same command again.
The user interface is hosted on web and is ready to use without any installation. The UI for shipper and trucker can be found on following links.
Shipper UI: https://yugdeep.shinyapps.io/ShipperUI/ Trucker UI: https://yugdeep.shinyapps.io/TruckerUI/
Each of the above UI is developed using a single R script named app.R
available in TruckerUI
and ShipperUI
folders of the repository.
The UI can be reproduced using the above mentioned scripts on a sytem with R (version 3.4 or greater) installed.
This contains:
- All of the reports that we have written during the course.
- Notes we have taken during the meetings
- Diagrams
- Presentations
In order to run the application locally, and start the development follow these steps (we have developed on linux. Running on windows is possible but you need to figure out the setup yourself):
Run the following commands:
curl -O https://hyperledger.github.io/composer/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
./prereqs-ubuntu.sh
- Install NVM (node version manager)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
This will git clone & install NVM in ~/.nvm dir, re-open terminal after install and verify installation withcommand -v nvm
, should outputnvm
(https://github.com/creationix/nvm/blob/master/README.md#installation)
- Upgrade/Install NPM with NVM
nvm install node
- Install all the composer npm stuff (note: some packages will start compiling C-code! Don't be scared by strange looking output, it's not running Fabric)
npm install -g composer-cli@next
npm install -g generator-hyperledger-composer@next
npm install -g composer-rest-server@next
- Install Yeoman, code generation tool
npm install -g yo
- (Optional) Composer Playground, this is basically a site that allows you to create Business Network Defitions from your browser and execute some simple low-level commands such as asset creation. The "test"-area is very much like a SQL Workbench. Having gotten some grips with Composer, I have to say the playground is quite essential to my current dev workflow. The big changes I do locally in Sublime then just pase the code over and do the necessary fixes there. Once no errors there, I copy back and commit. This is much faster to do than running the Composer archive command (it checks your code and outputs detected errors in terminal)
npm install -g composer-playground@next
- Fabric-tools install:
mkdir ~/fabric-tools && cd ~/fabric-tools
curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
unzip fabric-dev-servers.zip
- Fabric dev environment initial setup:
export FABRIC_VERSION=hlfv11
cd ~/fabric-tools
./downloadFabric.sh
./startFabric.sh
./createPeerAdminCard.sh
Now you have a dev environment for the two test networks, Rotterdam Logistics manual will follow. runYou can either run the following commands, or run the script named start_network.sh
- Install the composer runtime for our rotterdam_logistics_blocklab business network
composer runtime install --card PeerAdmin@hlfv1 --businessNetworkName rotterdam_logistics_blocklab
- Deploy the network from the business network archive
composer network start --card PeerAdmin@hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile [email protected] --file networkadmin.card
This will also create a networkadmin.card file in your current directory. Please do not commit this file.
- Import the newly created Network Administrator card
composer card import --file networkadmin.card
- Check if network is running
composer network ping --card admin@rotterdam_logistics_blocklab
Your first installation should already have the latest version. However if there is a new one released in the future, you can use these steps to update:
- Remove composer cards/connection profiles
composer card list
composer card delete --name admin@rotterdam_logistics_blocklab
composer card delete --name PeerAdmin@hlfv1
- Delete the cards in /tmp/ (typed this from memory, name and/or extension might differ!)
rm /tmp/[email protected]
rm /tmp/admin@rotterdam_logistics_blocklab.card
- Flush cards from local store (the composer commands didn't remove anything for me initially)
rm ~/.composer/cards -rf
- Remove previous composer versions
npm uninstall -g composer-cli
npm uninstall -g composer-rest-server
npm uninstall -g generator-hyperledger-composer
npm uninstall -g composer-playground
- Remove Fabric
cd ~/fabric-tools
(assuming this is where you initially extracted the fabric-tools archive)./teardownAllDocker.sh
(choose option 2)
- Remove Tools
rm ~/fabric-tools -rf
- Perform steps 3 and 5 in the initial setup
- Perform step 6 of initial setup
- run
start_test_network.sh
- enjoy!