-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from gnosischain/dev
Dev
- Loading branch information
Showing
27 changed files
with
657 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,8 @@ | ||
# Python | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
.Python | ||
env | ||
.env | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
.tox | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.log | ||
.git | ||
.mypy_cache | ||
.pytest_cache | ||
.hypothesis | ||
# Ignore everything | ||
* | ||
|
||
# Allow files and directories | ||
!/api | ||
!/scripts | ||
!/migrations | ||
!/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
FROM python:3.8-alpine | ||
FROM python:3.10-alpine | ||
|
||
COPY requirements.txt /tmp/requirements.txt | ||
RUN pip install --no-cache-dir -r /tmp/requirements.txt | ||
|
||
COPY . /api | ||
ENV PYTHONUNBUFFERED 1 | ||
WORKDIR /api | ||
|
||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "api:create_app()"] | ||
COPY requirements.txt ./ | ||
|
||
# Signal handling for PID1 https://github.com/krallin/tini | ||
RUN apk add --update --no-cache tini libpq && \ | ||
apk add --no-cache --virtual .build-dependencies alpine-sdk libffi-dev && \ | ||
pip install --no-cache-dir -r requirements.txt && \ | ||
apk del .build-dependencies && \ | ||
find /usr/local \ | ||
\( -type d -a -name test -o -name tests \) \ | ||
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ | ||
-exec rm -rf '{}' + | ||
|
||
COPY . . | ||
|
||
ENTRYPOINT ["/sbin/tini", "--"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
NATIVE_TOKEN_ADDRESS='native' | ||
from enum import Enum | ||
|
||
NATIVE_TOKEN_ADDRESS = 'native' | ||
DEFAULT_NATIVE_MAX_AMOUNT_PER_DAY = 0.01 | ||
DEFAULT_ERC20_MAX_AMOUNT_PER_DAY = 0.01 | ||
|
||
CHAIN_NAMES = { | ||
1: 'ETHEREUM MAINNET', | ||
100: 'GNOSIS CHAIN', | ||
10200: 'CHIADO CHAIN' | ||
} | ||
|
||
|
||
class FaucetRequestType(Enum): | ||
web = 'web' | ||
cli = 'cli' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import logging | ||
|
||
import click | ||
from flask import current_app | ||
from flask.cli import with_appcontext | ||
|
||
from .services import Web3Singleton | ||
from .services.database import AccessKey, AccessKeyConfig, Token | ||
from .utils import generate_access_key | ||
|
||
|
||
@click.command(name='create_access_keys') | ||
@with_appcontext | ||
def create_access_keys_cmd(): | ||
access_key_id, secret_access_key = generate_access_key() | ||
access_key = AccessKey() | ||
access_key.access_key_id = access_key_id | ||
access_key.secret_access_key = secret_access_key | ||
access_key.save() | ||
|
||
config = AccessKeyConfig() | ||
config.access_key_id = access_key.access_key_id | ||
config.chain_id = current_app.config["FAUCET_CHAIN_ID"] | ||
config.save() | ||
|
||
logging.info(f'Access Key ID : ${access_key_id}') | ||
logging.info(f'Secret access key: ${secret_access_key}') | ||
|
||
|
||
@click.command(name='create_enabled_token') | ||
@click.argument('name') | ||
@click.argument('chain_id') | ||
@click.argument('address') | ||
@click.argument('max_amount_day') | ||
@click.argument('type') | ||
@with_appcontext | ||
def create_enabled_token_cmd(name, chain_id, address, max_amount_day, type): | ||
w3 = Web3Singleton( | ||
current_app.config['FAUCET_RPC_URL'], | ||
current_app.config['FAUCET_PRIVATE_KEY'] | ||
) | ||
|
||
# check if Token already exists | ||
check_token = Token.get_by_address(w3.to_checksum_address(address)) | ||
|
||
if check_token: | ||
raise Exception('Token %s already exists' % address) | ||
|
||
# Checks | ||
if type.lower() not in ('native', 'erc20'): | ||
raise Exception('Type must be any of (erc20, native) got %s' % type) | ||
if float(max_amount_day) <= 0: | ||
raise Exception('Max amount per day must be greater than 0, got %d' % float(max_amount_day)) | ||
|
||
token = Token() | ||
token.name = name | ||
token.chain_id = chain_id | ||
token.address = w3.to_checksum_address(address) | ||
token.max_amount_day = float(max_amount_day) | ||
token.type = type | ||
token.enabled = True | ||
token.save() | ||
|
||
logging.info('Token created successfully') |
Oops, something went wrong.