Skip to content

Commit

Permalink
Devnet simnet support (#41)
Browse files Browse the repository at this point in the history
* devnet and simnet support

* fix docker build for main

---------

Co-authored-by: lAmeR1 <[email protected]>
  • Loading branch information
lAmeR1 and lAmeR1 authored May 7, 2024
1 parent c818d45 commit 9c45ebb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 25 deletions.
46 changes: 32 additions & 14 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
name: Docker Image CI

name: Docker Image
on:
release:
types: [ published ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ ubuntu-latest ]
arch: [ amd64, arm64 ]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: lamer1
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: supertypo/kaspa-rest-server:${{github.ref_name}}, supertypo/kaspa-rest-server:latest
file: ./docker/Dockerfile
build-args: |
version=${{github.ref_name}}

- name: Set up QEMU (for ARM64 emulation)
if: matrix.arch == 'arm64'
run: |
sudo apt-get install -y qemu-user-static
- name: Set up Docker Buildx (for multi-platform builds)
uses: docker/setup-buildx-action@v1

- name: Build and push Docker image
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t supertypo/kaspa-rest-server:${{github.ref_name}} \
-t supertypo/kaspa-rest-server:latest
--build-arg version=${{github.ref_name}}
--push .
docker buildx imagetools inspect supertypo/kaspa-rest-server:${SHORT_SHA}
2 changes: 1 addition & 1 deletion .github/workflows/docker-testimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2

Expand Down
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 9c45ebb

Please sign in to comment.