Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
HyP-183 Offline compatible (#140)
Browse files Browse the repository at this point in the history
* Added onerror fallback functions

* Removed react and react-dom from webpack config and from index html.

* Change to digicatapult/sqnc-hyproof-api:v0.13.25 , knex@3.1.0 , sqnc-process-management@2.2.30

* Changed to digicatapult/sqnc-identity-service:v1.12.0

* Change to digicatapult/sqnc-ipfs:v2.10.20

* Changed to digicatapult/sqnc-node:v11.3.0 and added open ports to view the blockchain w/ polkadot js

* Changed to digicatapult/veritable-cloudagent:v0.5.1

* Added fall back block of code for off line mode

* Init script small fixes

* Update readme with non-production notice

* Bumped up version

* Removed some left over comments

* Bumped up version

* Removed comments

* Added the new versions in order to allow docker to pull the right versions for all the images it needs.

* Updated process manager

* Fixed incorrect url

* Changed the code and added the then catch pattern to seed up the init script process to under 1 min.

* Moved get hardcoded factor out of then catch

* Better hardcoded factor function

* Added options as second arg to fetch issuance call

* Added issueAndWaitForComplete function

* Removed comments

* UpdatedApi

* Changed process manager ver

* UpdatedIdentitiImage

* UpdatedIpfsImg

---------

Co-authored-by: rmlearney-digicatapult <robert.learney@digicatapult.org.uk>
  • Loading branch information
dc-andysign and rmlearney-digicatapult authored May 8, 2024
1 parent 6cd695b commit 7d04a90
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 63 deletions.
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SQNC HyProof Client

# This repository is not production software. It should be used for investigation and demonstration purposes only

This repository contains the code for the HyProof front-end (HyProof Client).

Instructions for running the **Demonstrator** can be found in `/demo/hyproof-demo.md`
Expand All @@ -10,14 +12,11 @@ This repository contains the front-end for the **HyProof** proof of concept proj

**HyProof** is a DLT-based _MVP_ delivered as part of the wider **HII Seed** initiative which aims to push the boundaries when it comes to building the socio-technical acceptability and business implications of a fully digitised UK certification infrastructure for verifiable hydrogen provenance ( e.g: green hydrogen, etc ).

---

## Configuration

At the moment, this project is configured to use environment variables in a _dot env_ ( `.env` ) file at root level ( although no env variables are need at the moment ).

---

## Installation

```sh
Expand All @@ -26,7 +25,6 @@ npm i

Installs dependencies from **`package.json`**.

---

## Usage

Expand All @@ -39,8 +37,6 @@ Runs the application using the default port.

Open **[http://localhost:3000](http://localhost:3000)** to view it in the Browser.

---

## Dev Usage

```sh
Expand All @@ -51,8 +47,6 @@ Runs the application using the default port in dev mode.

Open **[http://localhost:3000](http://localhost:3000)** to view it in the Browser.

---

## Build

```sh
Expand All @@ -61,22 +55,14 @@ npm run build

Builds the app for production to the build folder.

---

## Assets

In terms of assets, this project contains the following:
This project contains the following assets:

* fonts are stored in **[src/assets/fonts](./src/assets/fonts/)** and imported globally in **[src/index.js](./src/index.js)**

* images are stored in **[src/assets/images](./src/assets/images/)** and loaders configured in **[webpack.config](./webpack.config)**

---

## License

This project is licensed under the **Apache 2.0** license.

---

---
14 changes: 7 additions & 7 deletions docker/hyproof-apis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ services:

hydrogen-producer-hyproof-api:
container_name: hydrogen-producer-hyproof-api
image: digicatapult/sqnc-hyproof-api:latest
image: digicatapult/sqnc-hyproof-api:v0.13.36
command: /bin/sh -c "
sleep 10 &&
npx knex migrate:latest --knexfile build/lib/db/knexfile &&
npx @digicatapult/sqnc-process-management@latest create -h hydrogen-producer-node -p 9944 -u //Alice -f ./processFlows.json &&
npx knex@3.1.0 migrate:latest --knexfile build/lib/db/knexfile &&
npx @digicatapult/sqnc-process-management@2.2.37 create -h hydrogen-producer-node -p 9944 -u //Alice -f ./processFlows.json &&
npm start"
environment:
- PORT=8000
Expand Down Expand Up @@ -77,10 +77,10 @@ services:

energy-owner-hyproof-api:
container_name: energy-owner-hyproof-api
image: digicatapult/sqnc-hyproof-api:latest
image: digicatapult/sqnc-hyproof-api:v0.13.36
command: /bin/sh -c "
sleep 10 &&
npx knex migrate:latest --knexfile build/lib/db/knexfile &&
npx knex@3.1.0 migrate:latest --knexfile build/lib/db/knexfile &&
npm start"
environment:
- PORT=8010
Expand Down Expand Up @@ -134,10 +134,10 @@ services:

regulator-hyproof-api:
container_name: regulator-hyproof-api
image: digicatapult/sqnc-hyproof-api:latest
image: digicatapult/sqnc-hyproof-api:v0.13.36
command: /bin/sh -c "
sleep 10 &&
npx knex migrate:latest --knexfile build/lib/db/knexfile &&
npx knex@3.1.0 migrate:latest --knexfile build/lib/db/knexfile &&
npm start"
environment:
- PORT=8020
Expand Down
6 changes: 3 additions & 3 deletions docker/identity-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
networks: ['hydrogen-producer']

hydrogen-producer-identity:
image: digicatapult/sqnc-identity-service:latest
image: digicatapult/sqnc-identity-service:v1.12.5
container_name: hydrogen-producer-identity
command: /bin/sh -c "
sleep 10 &&
Expand Down Expand Up @@ -66,7 +66,7 @@ services:
networks: ['energy-owner']

energy-owner-identity:
image: digicatapult/sqnc-identity-service:latest
image: digicatapult/sqnc-identity-service:v1.12.5
container_name: energy-owner-identity
command: /bin/sh -c "
sleep 10 &&
Expand Down Expand Up @@ -114,7 +114,7 @@ services:
networks: ['regulator']

regulator-identity:
image: digicatapult/sqnc-identity-service:latest
image: digicatapult/sqnc-identity-service:v1.12.5
container_name: regulator-identity
command: /bin/sh -c "
sleep 10 &&
Expand Down
6 changes: 3 additions & 3 deletions docker/ipfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
##################################################################################

hydrogen-producer-ipfs:
image: digicatapult/sqnc-ipfs:latest
image: digicatapult/sqnc-ipfs:v2.10.25
container_name: hydrogen-producer-ipfs
depends_on:
hydrogen-producer-node:
Expand Down Expand Up @@ -39,7 +39,7 @@ services:
##################################################################################

energy-owner-ipfs:
image: digicatapult/sqnc-ipfs:latest
image: digicatapult/sqnc-ipfs:v2.10.25
container_name: energy-owner-ipfs
depends_on:
energy-owner-node:
Expand Down Expand Up @@ -69,7 +69,7 @@ services:
##################################################################################

regulator-ipfs:
image: digicatapult/sqnc-ipfs:latest
image: digicatapult/sqnc-ipfs:v2.10.25
container_name: regulator-ipfs
depends_on:
regulator-node:
Expand Down
18 changes: 15 additions & 3 deletions docker/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ services:
##################################################################################

hydrogen-producer-node:
image: digicatapult/sqnc-node:latest
image: digicatapult/sqnc-node:v11.3.0
container_name: hydrogen-producer-node
command: --base-path /data
--alice
--unsafe-rpc-external
--rpc-cors all
--node-key 0000000000000000000000000000000000000000000000000000000000000001
ports:
- 30333:30333
- 9944:9944
- 9933:9933
volumes:
- hydrogen-producer-node:/data
restart: on-failure
Expand All @@ -26,14 +30,18 @@ services:
##################################################################################

energy-owner-node:
image: digicatapult/sqnc-node:latest
image: digicatapult/sqnc-node:v11.3.0
container_name: energy-owner-node
command: --base-path /data/
--bob
--unsafe-rpc-external
--rpc-cors all
--node-key 0000000000000000000000000000000000000000000000000000000000000002
--bootnodes /dns4/alice/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
ports:
- 31333:30333
- 10044:9944
- 10033:9933
volumes:
- energy-owner-node:/data
restart: on-failure
Expand All @@ -44,14 +52,18 @@ services:
##################################################################################

regulator-node:
image: digicatapult/sqnc-node:latest
image: digicatapult/sqnc-node:v11.3.0
container_name: regulator-node
command: --base-path /data/
--charlie
--unsafe-rpc-external
--rpc-cors all
--node-key 0000000000000000000000000000000000000000000000000000000000000003
--bootnodes /dns4/alice/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
ports:
- 32333:30333
- 10144:9944
- 10133:9933
volumes:
- regulator-node:/data
restart: on-failure
Expand Down
6 changes: 3 additions & 3 deletions docker/veritable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
##################################################################################

hydrogen-producer-veritable:
image: digicatapult/veritable-cloudagent:latest
image: digicatapult/veritable-cloudagent:v0.6.0
container_name: hydrogen-producer-veritable
depends_on:
hydrogen-producer-ipfs:
Expand Down Expand Up @@ -38,7 +38,7 @@ services:
##################################################################################

energy-owner-veritable:
image: digicatapult/veritable-cloudagent:latest
image: digicatapult/veritable-cloudagent:v0.6.0
container_name: energy-owner-veritable
depends_on:
energy-owner-ipfs:
Expand Down Expand Up @@ -67,7 +67,7 @@ services:
##################################################################################

regulator-veritable:
image: digicatapult/veritable-cloudagent:latest
image: digicatapult/veritable-cloudagent:v0.6.0
container_name: regulator-veritable
depends_on:
regulator-ipfs:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/sqnc-hyproof-client",
"version": "0.5.38",
"version": "0.5.39",
"description": "User interface for HyProof",
"homepage": "https://github.com/digicatapult/sqnc-hyproof-client",
"main": "src/index.js",
Expand All @@ -11,7 +11,7 @@
"init": "./scripts/initialise_demo.mjs",
"dev": "webpack-dev-server --mode=development",
"start": "serve -s ./build",
"build": "./node_modules/.bin/webpack --mode=production",
"build": "$(npm root)/.bin/webpack --mode=production",
"depcheck": "depcheck",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
59 changes: 43 additions & 16 deletions scripts/initialise_demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function waitForCertificateState(certificateId, state, port) {
if (body.state === state) {
return body
}
await await delay(100)
await delay(100)
}
const message = `Timeout waiting for state ${state} on certificate ${certificateId} for port ${port}`
console.error(message)
Expand Down Expand Up @@ -209,29 +209,56 @@ async function issueCertificate(
}

const issueEndpoint = `http://localhost:${energyProviderPort}/v1/certificate/${id}/issuance`
const issueResult = await fetch(issueEndpoint, {

const carbonIntensityApiUrl = `https://api.carbonintensity.org.uk/intensity/${new Date(production_end_time).toISOString()}/${new Date(production_start_time).toISOString()}`

const hardcodedFactor = (gap) => Math.random() * (gap[1] - gap[0]) + gap[0]
const hardcodedEco2 = (e) => Math.floor(hardcodedFactor([0.03, 0.11]) * e)

const defaultCertOptions = {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({}),
})
if (!issueResult.ok) {
const message = `Error issuing certificate ${id} on port ${energyProviderPort}. Error was ${issueResult.statusText}`
console.error(message)
throw new Error(message)
}

const waitForComplete = async () => {
await waitForCertificateState(id, 'issued', energyProviderPort)
const finalCert = await waitForCertificateState(
id,
'issued',
hydrogenProducerPort
)
return finalCert
const hardcodedCertOptions = {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
embodied_co2: hardcodedEco2(energy_consumed_wh),
}),
}

const issueAndWaitForComplete = async (options) => {
const issueResult = await fetch(issueEndpoint, options)
if (!issueResult.ok) {
const message = `Error issuing certificate ${id} on port ${energyProviderPort}. Error was ${issueResult.statusText}`
console.error(message)
throw new Error(message)
}
const waitForComplete = async () => {
await waitForCertificateState(id, 'issued', energyProviderPort)
const finalCert = await waitForCertificateState(
id,
'issued',
hydrogenProducerPort
)
return finalCert
}
return waitForComplete
}

try {
await fetch(carbonIntensityApiUrl)
return issueAndWaitForComplete(defaultCertOptions)
} catch (e) {
console.log('Detected off-line mode when using fetch. Using random vals.')
return issueAndWaitForComplete(hardcodedCertOptions)
}
return waitForComplete
}

const healthChecks = await Promise.all([
Expand Down
2 changes: 0 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src='/config.js' type='module'></script>
<base href="/" />

Expand Down
Loading

0 comments on commit 7d04a90

Please sign in to comment.