diff --git a/api/.env.example b/api/.env.example index 69890e1..0d7993e 100644 --- a/api/.env.example +++ b/api/.env.example @@ -3,6 +3,5 @@ FAUCET_PRIVATE_KEY=0x00000000000000000000000000000000000000000000000000000000000 FAUCET_RPC_URL=https://rpc.chiadochain.net FAUCET_CHAIN_ID=10200 FAUCET_DATABASE_URI=sqlite:// -FAUCET_ENABLED_TOKENS="[{\"address\": \"0x19C653Da7c37c66208fbfbE8908A5051B57b4C70\", \"name\":\"GNO\", \"maximumAmount\": 0.5}]" CAPTCHA_VERIFY_ENDPOINT=https://api.hcaptcha.com/siteverify CAPTCHA_SECRET_KEY=0x0000000000000000000000000000000000000000 \ No newline at end of file diff --git a/api/api/api.py b/api/api/api.py index 201a764..1152ddb 100644 --- a/api/api/api.py +++ b/api/api/api.py @@ -4,7 +4,7 @@ from flask_cors import CORS from flask_migrate import Migrate -from .manage import create_access_keys_cmd +from .manage import create_access_keys_cmd, create_enabled_token_cmd from .routes import apiv1 from .services import Web3Singleton from .services.database import db @@ -38,6 +38,7 @@ def create_app(): app.register_blueprint(apiv1, url_prefix="/api/v1") # Add cli commands app.cli.add_command(create_access_keys_cmd) + app.cli.add_command(create_enabled_token_cmd) with app.app_context(): db.init_app(app) diff --git a/api/api/manage.py b/api/api/manage.py index 451b591..82969f2 100644 --- a/api/api/manage.py +++ b/api/api/manage.py @@ -4,7 +4,8 @@ from flask import current_app from flask.cli import with_appcontext -from .services.database import AccessKey, AccessKeyConfig +from .services import Web3Singleton +from .services.database import AccessKey, AccessKeyConfig, Token from .utils import generate_access_key @@ -24,3 +25,34 @@ def create_access_keys_cmd(): 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'] + ) + + # Checks + if type.lower() != 'native' or type.lower() != 'erc20': + raise Exception('Type must be any of (erc20, native)') + if float(max_amount_day) <= 0: + raise Exception('Max amount per day must be greater than 0') + + 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')