Genesis Dao Service
April 30, 2023 ยท View on GitHub
Installation
Setup
cp .env.example .env
Adjust the .env values according to your needs, source it, so it is available in your current environment.
source .env
If using zsh (for example, on macOS), you may need to mark variables for export,
before calling any make target:
set -a; source .env; set +a
Quickstart using Docker
docker compose build
docker compose up
Development Setup
Prerequisites
- Install Python 3.11 or greater
- Install pip
- Install virtualenv
- Install sqlite-devel / libsqlite3-dev
- Docker daemon must be available for development
Create and activate Python venv
make venv
Activate this virtual environment:
source venv/bin/activate
Execute deactivate to exit out of the virtual environment.
Get and Build Python Requirements
Then use the build Make target to get all requirements fetched and compiled:
make build
Start databases
Make sure you have:
- Docker running
- and the environment is loaded
The following starts the data stores used by this project: PostgreSQL.
make start-postgres
The following starts the data stores used by this project: Redis.
make start-redis
Both together:
make start-databases
To stop the data stores, use Docker Compose:
docker-compose down postgres
docker-compose down redis
Start App
make start-dev
Some make commands can be used w/ or w/o docker for the app container:
start-app,start-dev,test,run-migration- (when using docker the envvar
DATABASE_HOSThas to point to the name of the postgres container:DATABASE_HOST=postgres)
- e.g.:
make test
make test use-docker=true
Syncing the Database with the Blockchain
If your blockchain is running and setup in .env under BLOCKCHAIN_URL you can start the event listener by running:
make start-listener
It will sync the database with the chain and try to fetch a new block every BLOCK_CREATION_INTERVAL seconds.
Documentation
API documentation: /redoc/
- default: http://127.0.0.1:8000/redoc/
Environments Variables
Base Setup
- APPLICATION_STAGE
- type: str
- default:
development - use
productionfor prod
- BASE_PORT
- type: int
- default:
8000
- BASE_URL
- type: str
- default:
http://127.0.0.1:8000
- DATABASE_HOST
- type: str
- default:
0.0.0.0 - use
postgreswhen working w/ docker
- DATABASE_NAME
- type: str
- default:
core
- DATABASE_PORT
- type: int
- default:
5432
- DATABASE_USER
- type: str
- default:
postgres
- DATABASE_PASSWORD
- type: str
- default:
postgres
Blockchain
- BLOCKCHAIN_URL
- type: str
- BLOCK_CREATION_INTERVAL
- type: int
- default:
6seconds - minimum time the event listener waits before trying to fetch the newest block from the chain
- RETRY_DELAYS
- type: str
- default
5,10,30,60,120seconds - comma separated list
- increasing retry delays for blockchain actions
- the last value will be used for all further retries
Storage
- FILE_UPLOAD_CLASS:
- type: str
- default:
"core.file_handling.aws.s3_client" - Class used to upload metadata. Requires a method:
def upload_file(self, file, storage_destination=None) -> Optional[str]: """ Args: file: file to upload (file-like obj, readable) storage_destination: pathstr / folder name. e.g.: "folder_1/folder_2/my_file.jpeg" Returns: url of uploaded file """
- ENCRYPTION_ALGORITHM:
- type: str
- default: "sha3_256"
- Hashlib encryption algorithm used to hash the uploaded metadata. Uses
hexdigest().
- MAX_LOGO_SIZE:
- type: int
- default:
2_000_0002 mb - maximum allowed logo size
- these are only required when using the
FILE_UPLOAD_CLASS:core.file_handling.aws.s3_client- AWS_STORAGE_BUCKET_NAME
- type: str
- Name of the AWS bucket to store metadata in.
- AWS_REGION
- type: str
- AWS region of said bucket.
- AWS_S3_ACCESS_KEY_ID
- type: str
- AWS access key to access said bucket.
- AWS_S3_SECRET_ACCESS_KEY
- type: str
- AWS secret access key to access said bucket.
- or similar aws authentication method using boto3
- AWS_STORAGE_BUCKET_NAME