(!!) Some part of the code (shell scripts) may not work since it is developed quite a long time ago.
FYP Project Introduction Website: https://fyp.johnnyip.com
https://fyp-front.johnnyip.com/
Name | Features |
---|---|
Frontend | Developed with React.js |
Backend-Operation | Developed with Spring Boot, Spring Security (JWT), Hibernate (MySQL) |
Backend-Blockchain | Developed with Hyperledger Fabric (private blockchain), using the official tutorial Expose a Spring Boot API endpoint for create and read operations to the blockchain network. |
Developed with React.js
cd frontend
npm install --force
npm run dev
On every commit, the changes will be built into docker image: https://hub.docker.com/r/unclechuen/fyp-frontend
- Developer push changes to GitHub
- Jenkins Server detect changes
- Build the docker image
- Deploy the docker image on the test server at home
- State container across the whole website, more easier to use than Redux
- Adding Styled UI components easily
- Server-side rendering, improve loading speed
- Various Icons
- Making API calls more convenient
Spring Boot, developed with IntelliJ IDEA
https://tomcat.johnnyip.com/fyp-backend/
API Documentation (2. Backend Database Section)
Spring Security (JWT Token) Authenticate users with:
- Username password (Retrieve JWT Token at 1st time)
- JWT Token (Every requests)
Connection with MySQL
- Sprint Data JPA
On every commit, the changes will be deployed to tomcat server: https://tomcat.johnnyip.com/fyp-backend/
- Developer push changes to GitHub
- Jenkins Server detect changes
- Build the .war file
- Deploy the .war file to Tomcat Server
Source codes cloned from official documentation and hyperledger/fabric-samples repository
Endpoint URL: https://tomcat.johnnyip.com/fyp-hyperledger/
API Documentation (3. Blockchain Network Section)
On every commit, the changes will be deployed to tomcat server: https://tomcat.johnnyip.com/fyp-hyperledger/
- Developer push changes to GitHub
- Jenkins Server detect changes
- Build the .war file
- Deploy the .war file to Tomcat Server
Setting up a experimental blockchain network, with 2 peer nodes in a single Linux server, with Docker images
Prerequisite:
- Docker installed on Linux machine
- Folder hyperledger-fabric-scripts is placed inside Linux
- Install dependencies (Docker, git ... ) here and here
#Change directory into scripts folder
cd backend-blockchain/hyperledger-fabric-scripts/scripts
#Add 'execute' right to all users, prevent "Permission denied"
chmod +x network.sh
#Setting up the network
./network.sh up
#Removing the network
./network.sh down
#Restart the containers after a system shutdown
docker restart $(docker ps -a -q)
After the script is successfully ran, 4 docker process should be set up and running
Image name | Description | Ports |
---|---|---|
hyperledger/fabric-tools:latest | A necessary cli tool | - |
hyperledger/fabric-orderer:latest | orderer.example.com | 7050 |
hyperledger/fabric-peer:latest | peer0.org1.example.com | 7051 |
hyperledger/fabric-peer:latest | peer0.org2.example.com | 9051 |
Paths to certificate files:
organizations/peerOrganizations/org1.example.com
organizations/peerOrganizations/org2.example.com
Creating channels and make the 2 peers joining them
#Add 'execute' right to all users, prevent "Permission denied"
chmod +x scripts/*
./network.sh createChannel -c fyp
Meaning of tags
- -ccn: Chaincode Name
- -ccp: Chaincode Source Path
- -ccl: Chaincode language
- -c : Channel to be deployed
#Add 'execute' right to all users, prevent "Permission denied"
chmod +x scripts/deployCC.sh
./network.sh deployCC -ccn orders -ccp ../chaincode-javascript/orders -ccl javascript -c fyp
./network.sh deployCC -ccn deliveryNotes -ccp ../chaincode-javascript/deliveryNotes -ccl javascript -c fyp
./network.sh deployCC -ccn deliveryStatus -ccp ../chaincode-javascript/deliveryStatus -ccl javascript -c fyp
./network.sh deployCC -ccn documents -ccp ../chaincode-javascript/documents -ccl javascript -c fyp
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
#Spreading the cmd above for readability
#Put data into blockchain
peer chaincode invoke \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" \
-C fyp \
-n deliverynotes2 \
--peerAddresses localhost:7051 \
--tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" \
--peerAddresses localhost:9051 \
--tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" \
-c '{"function":"CreateAsset","Args":["1","1","NA","NA","50","2022-06-14","Driver Company","2022-06-14"]}'
#GetAllAssets
peer chaincode query -C orders -n basic -c '{"Args":["GetAllAssets"]}'
Directory: hyperledger-fabric-scripts/mainScripts/organizations/peerOrganizations/org1.example.com/
-
TLS Certificate
- Path: peers/peer0.org1.example.com/tls/ca.crt
-
CA Certificate
- Path: users/[email protected]/msp/signcerts/[email protected]
-
Private Key
- Path: users/[email protected]/msp/keystore/priv_sk