This is the back-end service for the framework.
The trust score can be generated by making the following API call:
http://localhost:8000/trust_scoring/get_trust_score/?address=<ethereum_address>
Just replace the <ethereum_address> with the address from the main-net and the app will generate the trust score for it.
- Create a python virtual environment by running:
virtualenv venv - Install the requirements by running:
pip3 install -r requirements.txt - Create a
.envfile and set the environment variables (check the next sub-section for a sample) - Create a new package called
app_secretsand a file calledcookies.pyand add the GitHub cookies in it - (Required only if you have set the environment variable named
ENV_TYPEtoProd)- Go to
contractsecurityapp/settings.py - Look for the following snippet of code and set the Postgres properties for the app to point to your own Postgres Database:
- Go to
docker_envs = ["Prod", "Docker", "local_prod"]
if ENV_TYPE in docker_envs:
print("Connecting to Postgres")
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
- Migrate the DB structure to your database by running:
python manage.py migrate- Note: If you haven't connected to Postgres, the app will create an SQLite DB for you within the main directory
- Start the server by running:
python manage.py runserver- Check out the Django Documentation for more options on running the Django server
- For generating the DApp trust score, you also need to be running RabbitMQ on your PC and also start the celery workers by running the command
celery -A contractsecurityapp worker --autoscale=10,1 --loglevel=info. The celery works must run in parallel to the main app.
PYTHONUNBUFFERED=1
DJANGO_SETTINGS_MODULE=contractsecurityapp.settings
ENV_TYPE=local
INFURA_KEY_URL=https://mainnet.infura.io/v3/<your_API_key_from_Infura>
ETHERSCAN_API_KEY=<your_API_key_from_Etherscan>
GANACHE_RPC_URL=http://127.0.0.1:8545 # This is optional
github_cookie = '<your_github_cookie_string>'
github_header = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
# 'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://github.com/',
'DNT': '1',
'Connection': 'keep-alive',
'Cookie': '<your_github_cookie_string>'
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'If-None-Match': 'W/"something"',
# Requests doesn't support trailers
# 'TE': 'trailers',
}
- Log into your GitHub account
- Open the
inspecttab on your browser and look for thenetworksection within it - Right-click on one of the requests and select
copy as cURL - Use an online cURL to Python converter (such as: https://curlconverter.com)
- Copy the cookie string and the header dictionary and paste it in
app_secrets/cookies.py