Skip to content

Commit

Permalink
Fix issue with native token tx being executed as it was an erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
Giacomo Licari committed Mar 7, 2024
1 parent 4b3c889 commit de5881e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Samples below:
```
cd /api
flask -A api create_enabled_token GNO 10200 0x19C653Da7c37c66208fbfbE8908A5051B57b4C70 0.01 erc20
flask -A api create_enabled_token GNO 10200 0x0000000000000000000000000000000000000000 0.01 native
flask -A api create_enabled_token xDAI 10200 0x0000000000000000000000000000000000000000 0.01 native
```

Once enabled, the token wil appear in the list of enabled tokens on the endpoint `api/v1/info`.
Expand Down
5 changes: 3 additions & 2 deletions api/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _ask(request_data, validate_captcha=True, access_key=None):
if transaction:
time_diff_seconds = (datetime.utcnow() - transaction.created).total_seconds()
if time_diff_seconds < current_app.config['FAUCET_RATE_LIMIT_TIME_LIMIT_SECONDS']:
time_diff_hours = time_diff_seconds/(24*60)
time_diff_hours = 24-(time_diff_seconds/(24*60))
return jsonify(errors=['recipient: you have exceeded the limit for today. Try again in %d hours' % time_diff_hours]), 429

# convert amount to wei format
Expand All @@ -144,7 +144,8 @@ def _ask(request_data, validate_captcha=True, access_key=None):

w3 = Web3Singleton(current_app.config['FAUCET_RPC_URL'], current_app.config['FAUCET_PRIVATE_KEY'])

if token_address == 'native':
token = Token.get_by_address(token_address)
if token.type == 'native':
tx_hash = claim_native(w3, current_app.config['FAUCET_ADDRESS'], recipient, amount_wei)
else:
tx_hash = claim_token(w3, current_app.config['FAUCET_ADDRESS'], recipient, amount_wei, token_address)
Expand Down

0 comments on commit de5881e

Please sign in to comment.