/blockchainProject

work in progress

Primary LanguagePythonMIT LicenseMIT

Social Network

Smart Contracts test Django project tests

This is a work in progress

Table of Contents

Requirements

  • Docker and Docker-compose (sudo apt install docker docker-compose)

socialNetwork (Django project)

  • Python 3.6 (sudo apt install python3.6)
  • Celery (sudo apt install python-celery-common)
  • Requirements (inside socialNetwork directory with the virtual environment activated, pip install -r requirements.txt)

blockchain (truffle project)

  • Node (>= v8.17.0)
  • npm (>= v6.13.4)
  • Truffle (npm install -g truffle)
  • Install requirements (inside blockchain directory npm install)

Set up

Database

First, we need a postgres database. We can easy create one with this docker command.

# This creates the container, not the database
docker run --name socialNetwork_db -d -p 5432:5432 -e POSTGRES_PASSWORD="socialNetwork" postgres:9.6.17-alpine

Then we need to create the database inside the container.

docker exec -it socialNetwork_db createdb socialNetwork -U postgres

In addition, if we want to enter the terminal inside our postgres, we can do it with this command:

docker exec -it socialNetwork_db psql -U postgres

Virtual environment

You need to create a python virtual environment. If you don't know how, follow this steps.

  1. Install virtualenv and virtualenvwrapper following this gist.
  2. Create the environment with this command.
# This will create a virtual environment called "socialNetwork"
mkvirtualenv --python=/usr/bin/python3.6 socialNetwork

In order to activate the environment you just need to execute workon socialNetwork, and to deactivate it, just type deactivate.

Redis (Broker) and celery (Task queue)

In order to set up our redis, we just need to run this docker command:

docker run --name socialNetwork_redis -p 6379:6379  redis:6.0-alpine

At the moment, we have not dockerized celery, so we can start our celery running this command in a terminal (don't kill this terminal).

cd socialNetwork
celery worker -A socialNetwork --loglevel=info

Ganache-cli (personal blockchain for Ethereum)

We can easily set up our local blockchain with this docker command:

docker run --name ganache-cli -d -p 8545:8545 trufflesuite/ganache-cli:latest

How to run the app

Before running this app, you need to install all requirements and do the set up.

If so, just follow this steps:

  1. Be sure ganache-cli docker is running.
  2. Go into the blockchain directory and deploy the contracts with truffle deploy.
  3. Be sure the database is up.
  4. Go to the socialNetwork directory and stay there.
  5. Activate your virtual environment.
  6. Be sure redis and celery are running.
  7. Do the migrations if needed (python manage.py makemigrations and python manage.py migrate)
  8. Flush the database python manage.py flush (this cleans the database, so there will be no conflicts with the Smart Contracts)
  9. Finally, run the server with python manage.py runserver and go to http://127.0.0.1:8000.

License

MIT License. See more here.

Contributors