Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial template #100

Merged
merged 27 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ jobs:
# Don't run on draft pull requests
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
strategy:
matrix:
directories:
- trackAndTrace
- compliant-reward-distribution

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Build with docker compose
working-directory: trackAndTrace
working-directory: ${{ matrix.directories }}
env:
# Dummy values set because `docker compose build` enforces the variables only needed on runtime when building.
# Dummy values are set for the `trackAndTrace` run because `docker compose build`
# enforces the presence of environment variables during the build phase,
# even though these variables are only needed at runtime.
TRACK_AND_TRACE_CONTRACT_ADDRESS: "<8351,0>"
TRACK_AND_TRACE_PRIVATE_KEY_FILE: "./trackAndTrace/README.md"
run:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/yarn-build-fmt-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

pull_request:
branches: main

env:
NODE_VERSION: "lts/*"

Expand All @@ -29,6 +29,7 @@ jobs:
- sponsoredTransactionsAuction/frontend
- trackAndTrace/frontend
- testnet-faucet
- compliant-reward-distribution/frontend

steps:
- name: Checkout
Expand Down Expand Up @@ -71,6 +72,7 @@ jobs:
- sponsoredTransactionsAuction/frontend
- trackAndTrace/frontend
- testnet-faucet
- compliant-reward-distribution/frontend

steps:
- name: Checkout
Expand All @@ -93,7 +95,7 @@ jobs:
- name: Run Prettier
working-directory: ${{ matrix.packages }}
run: yarn prettier -c .

build:
name: Building Frontend
# Don't run on draft pull requests
Expand All @@ -115,6 +117,7 @@ jobs:
- sponsoredTransactionsAuction/frontend
- trackAndTrace/frontend
- testnet-faucet
- compliant-reward-distribution/frontend

steps:
- name: Checkout
Expand Down
Binary file added compliant-reward-distribution/Architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions compliant-reward-distribution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Compliance Reward Distribution Dapp

## Architecture

![Architecture](./Architecture.png)

## Hosted front end

[Soon](https://github.com/Concordium/concordium-dapp-examples)

## Overview

The project has three primary components.

- A [frontend](./frontend/README.md), located in `./frontend`
- An [indexer](./indexer-and-server/README.md) service, located in `./indexer-and-server`
- A [server](./indexer-and-server/README.md) that hosts the frontend, located in `./indexer-and-server`

Explanations for each component reside in README.md files inside their respective folder.

## Docker files

You can run the services and servers manually as explained in the READMEs or use the docker files in `./dockerfiles`.

However, the easiest option is to use [docker-compose](https://docs.docker.com/compose/) with the configuration file `./docker-compose.yml`.

For this to work, you should do the following:

1. Set the following environment variables:
- (Optional) Set the `ADMIN_ACCOUNT` variable to an account address. This account can read and write to the database.
- (Optional) Set the `CONCORDIUM_NODE` to the gRPC endpoint of the node you want to use. Defaults to `https://grpc.testnet.concordium.com:20000`.
2. Run `docker-compose up` to build and start all the services.

e.g.

```bash
ADMIN_ACCOUNT="4dT5vPrnnpwVrXZgmYLtHrDLvBYhtzheaK4fDWbJewqRCGQKWz" CONCORDIUM_NODE="https://grpc.mainnet.concordium.software:20000" docker-compose up
```

You might need to run the above command twice, if the postgres database container is too slow
to be set up for the first time and as a result the indexer or server throw an error because
they are already trying to connect. Stopping the command and re-running the command will load
the already setup postgres database container.

3. Access the frontend at `http://localhost:8080`
- The postgres database runs on port `5432`. It is configurable in the `./docker-compose.yml` file.

### Restarting

Restaring the services with the `docker-compose up` command will load the old `compliant-reward-distribution_postgres_data`.
If you want to restart the containers with an empty database, stop and remove all containers, and delete the PostgreSQL database before running the `docker-compose up` command again.

To delete the volume, run the following command:

``` shell
docker volume rm compliant-reward-distribution_postgres_data
```

48 changes: 48 additions & 0 deletions compliant-reward-distribution/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.8'

# The following optional environment variables can be set:
# - `ADMIN_ACCOUNT`: An admin account that can read and write to the database.
# - `CONCORDIUM_NODE`: The gRPC interface of a node on the correct network. (Defaults to 'https://grpc.testnet.concordium.com')

services:
postgres:
image: postgres:latest
ports:
- 5432:5432
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: indexer
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password

indexer:
build:
context: ../
dockerfile: ./compliant-reward-distribution/dockerfiles/indexer.Dockerfile
restart: always
environment:
CCD_INDEXER_DB_CONNECTION: "host=postgres dbname=indexer user=postgres password=password port=5432"
CCD_INDEXER_NODE: ${CONCORDIUM_NODE:-https://grpc.testnet.concordium.com:20000}

depends_on:
- postgres

server:
build:
context: ../
dockerfile: ./compliant-reward-distribution/dockerfiles/server.Dockerfile
restart: always
environment:
CCD_SERVER_DB_CONNECTION: "host=postgres dbname=indexer user=postgres password=password port=5432"
CCD_SERVER_NODE: ${CONCORDIUM_NODE:-https://grpc.testnet.concordium.com:20000}
CCD_SERVER_ADMIN_ACCOUNTS: ${ADMIN_ACCOUNT}
ports:
- 8080:8080
depends_on:
- postgres
- indexer

volumes:
postgres_data:
20 changes: 20 additions & 0 deletions compliant-reward-distribution/dockerfiles/indexer.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file should be executed from the `compliant-reward-distribution` directory.

ARG RUST_IMAGE=rust:1.74-bookworm

# Build indexer
FROM ${RUST_IMAGE} as build
WORKDIR /indexer
COPY ./compliant-reward-distribution/indexer-and-server ./
COPY ./deps/concordium-rust-sdk /deps/concordium-rust-sdk
RUN cargo build --release

FROM debian:bookworm

# In order to use TLS when connecting to the node we need certificates.
RUN apt-get update && apt-get install -y ca-certificates

COPY --from=build ./indexer/target/release/indexer /indexer

# Run indexer
CMD ["./indexer"]
29 changes: 29 additions & 0 deletions compliant-reward-distribution/dockerfiles/server.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file should be executed from the `compliant-reward-distribution` directory.

ARG RUST_IMAGE=rust:1.74-bookworm
ARG NODE_IMAGE=node:18-slim

# Build frontend
FROM ${NODE_IMAGE} AS frontend
WORKDIR /frontend
COPY ./compliant-reward-distribution/frontend ./
RUN yarn
RUN yarn build

# Build server
FROM ${RUST_IMAGE} AS server
WORKDIR /server
COPY ./compliant-reward-distribution/indexer-and-server ./
COPY ./deps/concordium-rust-sdk /deps/concordium-rust-sdk
RUN cargo build --release

FROM debian:bookworm

# In order to use TLS when connecting to the node we need certificates.
RUN apt-get update && apt-get install -y ca-certificates

COPY --from=frontend ./frontend/dist ./frontend/dist
COPY --from=server ./server/target/release/server ./server

# Run server
CMD ["./server"]
4 changes: 4 additions & 0 deletions compliant-reward-distribution/frontend/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.eslintrc.cjs
.yarn/
node_modules/
dist/
32 changes: 32 additions & 0 deletions compliant-reward-distribution/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
// React plugins
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
// Other plugins:
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint'],
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
settings: {
react: {
version: 'detect',
},
},
rules: {
'@typescript-eslint/no-unused-vars': 'warn',
},
};
31 changes: 31 additions & 0 deletions compliant-reward-distribution/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
node_modules

dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions compliant-reward-distribution/frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vite
1 change: 1 addition & 0 deletions compliant-reward-distribution/frontend/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
5 changes: 5 additions & 0 deletions compliant-reward-distribution/frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Unreleased changes

## 1.0.0

- Initial `front end`.
68 changes: 68 additions & 0 deletions compliant-reward-distribution/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Front end

## Setup

Make sure to have the following installed:

- [NodeJs](https://nodejs.org).
- [yarn](https://yarnpkg.com/getting-started/install) or a similar package manager.
- Rust and cargo (Recommended to install using [rustup](https://rustup.rs)).

## Frontend

To setup and install dependencies for the frontend navigate to the `frontend` directory and run:

```bash
yarn install
```

### Development

Set the environment variable `NETWORK` and `CONCORDIUM_NODE`, or prefix it before the `yarn dev` call.
Not setting the environment variables will run the frontend with the default `testnet` configuration.

```bash
yarn dev
```

or

```bash
NETWORK="mainnet" CONCORDIUM_NODE="https://grpc.mainnet.concordium.software:20000" yarn dev
```

This will launch a development server with hot module replacement enabled.

_Please note that calls to the backend server do not work in the development setup._

If you want to set up the whole project together with running the backend services so that the endpoints work. Follow the instructions in the project's [README.md](../indexer-and-server/README.md).

This frontend calls following backend endpoints:

- `api/setClaimed`
- `api/getPendingApprovals`
- `api/getAccountData`
- `api/getZKProofStatements`
- `api/postTweet`
- `api/postZKProof`

from the [backend server](../indexer-and-server)

### Environment variables

These environment variables are available in the frontend.

When hosting the frontend via the [backend server](../indexer-and-server), the values of the environment variables are passed in via the server.

```bash
NETWORK=testnet # The network to use mainnet/testnet (defaults to 'testnet')
CONCORDIUM_NODE=https://grpc.testnet.concordium.com:20000 # The gRPC endpoint of a node in the chosen network (defaults to 'https://grpc.testnet.concordium.com:20000')
```

### Build

```bash
yarn build
```

This will bundle the project into `frontend/dist` directory which should be hosted by the [backend server](../indexer-and-server).
Loading
Loading