Skip to content

Commit

Permalink
Initial indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Jul 18, 2024
1 parent bc58adb commit 8877fef
Show file tree
Hide file tree
Showing 13 changed files with 4,877 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compliant-reward-distribution/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/target
**/node_modules
55 changes: 55 additions & 0 deletions compliant-reward-distribution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Track and Trace Project

## Hosted front end

[Hosted front end link](https://trackntrace.testnet.concordium.com/)

## Overview

This project contains a complete implementation of a track and trace solution with [CIS-3](https://proposals.concordium.software/CIS/cis-3.html) compliant sponsored transactions.

It has five primary components.

- A [smart contract](./smart-contract/README.md), located in `./smart-contract`
- A [frontend](./frontend/README.md), located in `./frontend`
- An [indexer](./indexer/README.md) service, located in `./indexer`
- A [sponsored transaction service](./sponsored-transaction-service/README.md), located in `./sponsored-transaction-service`
- This service is generic and compatible with any CIS-3 contracts.
- A [server](./indexer/README.md) that hosts the frontend, located in `./indexer`

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

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. Deploy and initialize your version of the Track and Trace smart contract.
2. [Export your account keys from the Browser Wallet](https://developer.concordium.software/en/mainnet/net/guides/export-key.html) and generate a `./private-keys` folder to save the key file into it.
3. Set the following environment variables:
- Set the `TRACK_AND_TRACE_CONTRACT_ADDRESS` variable to the contract address of your contract instance.
- Set the `TRACK_AND_TRACE_PRIVATE_KEY_FILE` variable to the path of your keys from step 2.
- (Optional) Set the `TRACK_AND_TRACE_NETWORK` variable to the correct net (testnet/mainnet). Defaults to testnet.
- (Optional) Set the `TRACK_AND_TRACE_NODE` to the gRPC endpoint of the node you want to use. Make sure it runs on the right net, i.e., testnet or mainnet. Defaults to `https://grpc.testnet.concordium.com:20000`.
4. Run `docker-compose up` to build and start all the services.

e.g.

```bash
TRACK_AND_TRACE_CONTRACT_ADDRESS="<8901,0>" TRACK_AND_TRACE_PRIVATE_KEY_FILE="./private-keys/4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export" docker-compose up
```

5. Access the frontend at `http://localhost:8080`
- The sponsored transaction service runs on port `8000` by default, and the postgres database runs on `5432`. Both are configurable in the `./docker-compose.yml` file.

## Switching to a different contract address

The indexer service saves the contract address used into the underlying PostgreSQL database.
If you want to use a different contract address than initially set up, you therefore need to delete the PostgreSQL database before running the `docker-compose up` command again.

To do so, run the following command:

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

# This docker compose setup expects the following environment variables to be present:
# - `TRACK_AND_TRACE_CONTRACT_ADDRESS`: The address of the track and trace contract instance. (Format: '<1234,0>')
# - `TRACK_AND_TRACE_PRIVATE_KEY_FILE`: A path to the account keys used to sponsor the transactions. (For example './private-keys/my-account.export')
#
# The following optional environment variables can be set:
# - `TRACK_AND_TRACE_NETWORK`: The network to run the services on. Either 'mainnet' or 'testnet'. (Defaults to 'testnet')
# - `TRACK_AND_TRACE_NODE`: The gRPC interface of a node on the correct network. (Defaults to 'https://grpc.testnet.concordium.com')

services:
sponsored-transaction-service:
build:
context: ../
dockerfile: ./trackAndTrace/dockerfiles/sponsored-transaction-service.Dockerfile
restart: always
ports:
- 8000:8000
volumes:
- ${TRACK_AND_TRACE_PRIVATE_KEY_FILE:?Please specify the private key file of the sponsor account.}:/private-keys/sponsor-account.export
environment:
CCD_SPONSORED_TRANSACTION_SERVICE_ALLOWED_ACCOUNTS: Any # This should ideally be limited to avoid draining the sponsor account funds.
CCD_SPONSORED_TRANSACTION_SERVICE_ALLOWED_CONTRACTS: ${TRACK_AND_TRACE_CONTRACT_ADDRESS:?Please specify the Track and Trace contract instance address (format <1234,0>)}
CCD_SPONSORED_TRANSACTION_SERVICE_PRIVATE_KEY_FILE: /private-keys/sponsor-account.export
CCD_SPONSORED_TRANSACTION_SERVICE_LISTEN_ADDRESS: 0.0.0.0:8000
CCD_SPONSORED_TRANSACTION_SERVICE_NODE: ${TRACK_AND_TRACE_NODE:-https://grpc.testnet.concordium.com:20000}

server:
build:
context: ../
dockerfile: ./trackAndTrace/dockerfiles/server.Dockerfile
restart: always
environment:
CCD_SERVER_DB_CONNECTION: "host=postgres dbname=indexer user=postgres password=password port=5432"
CCD_SERVER_CONTRACT_ADDRESS: ${TRACK_AND_TRACE_CONTRACT_ADDRESS:?Please specify the Track and Trace contract instance address (format <1234,0>)}
CCD_SERVER_SPONSORED_TRANSACTION_BACKEND: "http://localhost:8000"
CCD_SERVER_NETWORK: ${TRACK_AND_TRACE_NETWORK:-testnet}
CCD_SERVER_NODE: ${TRACK_AND_TRACE_NODE:-https://grpc.testnet.concordium.com:20000}
ports:
- 8080:8080
depends_on:
- postgres
- indexer

indexer:
build:
context: ../
dockerfile: ./trackAndTrace/dockerfiles/indexer.Dockerfile
restart: always
environment:
CCD_INDEXER_CONTRACT: ${TRACK_AND_TRACE_CONTRACT_ADDRESS:?Please specify the Track and Trace contract instance address (format <1234,0>)}
CCD_INDEXER_NODE: ${TRACK_AND_TRACE_NODE:-https://grpc.testnet.concordium.com:20000}
CCD_INDEXER_DB_CONNECTION: "host=postgres dbname=indexer user=postgres password=password port=5432"
depends_on:
- postgres

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

volumes:
postgres_data:
5 changes: 5 additions & 0 deletions compliant-reward-distribution/indexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Unreleased changes

## 0.1.0

- Initial `indexer` and `server`.
Loading

0 comments on commit 8877fef

Please sign in to comment.