Skip to content

Commit

Permalink
Add flask command to create supported tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Giacomo Licari committed Mar 7, 2024
1 parent 731b2bc commit 34d10ae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
1 change: 0 additions & 1 deletion api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion api/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 33 additions & 1 deletion api/api/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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')

0 comments on commit 34d10ae

Please sign in to comment.