Skip to content

[UOW] A fullstack project, with React.js, Spring boot and Hyperledger Fabric (Private Blockchain)

Notifications You must be signed in to change notification settings

uowchk-group2/FYP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(!!) 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

URL to demonstration

https://fyp-front.johnnyip.com/

Summary

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.

Table of Content (Click and jump to section)

Frontend

Developed with React.js

How to start test env

cd frontend
npm install --force
npm run dev

CI/CD Pipeline

On every commit, the changes will be built into docker image: https://hub.docker.com/r/unclechuen/fyp-frontend

Steps

  1. Developer push changes to GitHub
  2. Jenkins Server detect changes
  3. Build the docker image
  4. Deploy the docker image on the test server at home

Library Used

  • 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

Backend-Operation

Spring Boot, developed with IntelliJ IDEA

Endpoint URL:

https://tomcat.johnnyip.com/fyp-backend/

API Documentation (2. Backend Database Section)

Main Features

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

CI/CD Pipeline

On every commit, the changes will be deployed to tomcat server: https://tomcat.johnnyip.com/fyp-backend/

Steps

  1. Developer push changes to GitHub
  2. Jenkins Server detect changes
  3. Build the .war file
  4. Deploy the .war file to Tomcat Server

Backend-Blockchain

What is included

1. Bash Scripts for setting up test Hyperledger Fabric network

Source codes cloned from official documentation and hyperledger/fabric-samples repository

2. Spring Boot - REST API server

Endpoint URL: https://tomcat.johnnyip.com/fyp-hyperledger/

API Documentation (3. Blockchain Network Section)

CI/CD Pipeline

On every commit, the changes will be deployed to tomcat server: https://tomcat.johnnyip.com/fyp-hyperledger/

Steps

  1. Developer push changes to GitHub
  2. Jenkins Server detect changes
  3. Build the .war file
  4. Deploy the .war file to Tomcat Server

1. Setting up test Hyperledger Fabric network with bash scripts

a. Setup

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

b. Creating channels

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

c. Deploy chaincode

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


d. Invoking chaincode

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"]}'

2. Spring Boot API server for executing transactions in Hyperledger Fabric

a. Copy the required certificates from linux

Directory: hyperledger-fabric-scripts/mainScripts/organizations/peerOrganizations/org1.example.com/

Put all files into: src/main/resources/certs

About

[UOW] A fullstack project, with React.js, Spring boot and Hyperledger Fabric (Private Blockchain)

https://fyp.johnnyip.com

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages