Skip to content

Commit

Permalink
devnet and simnet support
Browse files Browse the repository at this point in the history
  • Loading branch information
lAmeR1 committed May 7, 2024
1 parent c818d45 commit d617020
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
27 changes: 21 additions & 6 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import os

IS_TESTNET = os.getenv('TESTNET', 'false').lower() == 'true'
REGEX_KASPA_ADDRESS = "^kaspa:[a-z0-9]{61,63}$" if not IS_TESTNET else "^kaspatest:[a-z0-9]{61,63}$"
NETWORK_TYPE = os.getenv('NETWORK_TYPE', 'mainnet').lower()

# address constants
ADDRESS_PREFIX = "kaspatest" if IS_TESTNET else "kaspa"
ADDRESS_EXAMPLE = "kaspatest:qpqz2vxj23kvh0m73ta2jjn2u4cv4tlufqns2eap8mxyyt0rvrxy6ejkful67" if IS_TESTNET \
else "kaspa:qqkqkzjvr7zwxxmjxjkmxxdwju9kjs6e9u82uh59z07vgaks6gg62v8707g73"
match NETWORK_TYPE:
case "mainnet":
address_prefix = "kaspa"
address_example = "kaspa:qqkqkzjvr7zwxxmjxjkmxxdwju9kjs6e9u82uh59z07vgaks6gg62v8707g73"
case "testnet":
address_prefix = "kaspatest"
address_example = "kaspatest:qpqz2vxj23kvh0m73ta2jjn2u4cv4tlufqns2eap8mxyyt0rvrxy6ejkful67"
case "simnet":
address_prefix = "kaspasim"
address_example = "kaspasim:qpqz2vxj23kvh0m73ta2jjn2u4cv4tlufqns2eap8mxyyt0rvrxy6ejkful67"
case "devnet":
address_prefix = "kaspadev"
address_example = "kaspadev:qpqz2vxj23kvh0m73ta2jjn2u4cv4tlufqns2eap8mxyyt0rvrxy6ejkful67"
case _:
raise ValueError(f'Network type {NETWORK_TYPE} not supported.')

ADDRESS_PREFIX = address_prefix
ADDRESS_EXAMPLE = address_example

REGEX_KASPA_ADDRESS = f"^{ADDRESS_PREFIX}:[a-z0-9]{61, 63}$"
4 changes: 2 additions & 2 deletions endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import HTTPException
from functools import wraps

from constants import IS_TESTNET
from constants import NETWORK_TYPE


def filter_fields(response_dict, fields):
Expand All @@ -29,7 +29,7 @@ async def wrapper(*args, **kwargs):
def mainnet_only(func):
@wraps(func)
async def wrapper(*args, **kwargs):
if IS_TESTNET:
if NETWORK_TYPE != "mainnet":
raise HTTPException(status_code=503, detail="Endpoint not available. "
"This endpoint is only available in mainnet.")
return await func(*args, **kwargs)
Expand Down
3 changes: 1 addition & 2 deletions endpoints/get_balance.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# encoding: utf-8
import os
from fastapi import Path, HTTPException
from pydantic import BaseModel

from constants import ADDRESS_EXAMPLE, REGEX_KASPA_ADDRESS, IS_TESTNET
from constants import ADDRESS_EXAMPLE, REGEX_KASPA_ADDRESS
from server import app, kaspad_client


Expand Down

0 comments on commit d617020

Please sign in to comment.