Skip to content

Commit

Permalink
Merge pull request #608 from BoostryJP/dev-24.3
Browse files Browse the repository at this point in the history
Release v24.3.0
  • Loading branch information
YoshihitoAso authored Mar 30, 2024
2 parents c434008 + 25a4126 commit a996947
Show file tree
Hide file tree
Showing 365 changed files with 30,089 additions and 9,813 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ jobs:
- uses: actions/checkout@v4
- name: run unit test using postgres
run: docker-compose run ibet-prime-postgres
migration-test-postgres:
name: 'Migration tests (PostgreSQL)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: run unit test using postgres
run: docker-compose run ibet-prime-postgres bash --login -c "cd /app/ibet-Prime && pytest -vv --test-alembic -m 'alembic'"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.1.1
hooks:
- id: black
language_version: python3.11
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

# make application directory
RUN mkdir -p /app/ibet-Prime/
Expand All @@ -11,6 +11,7 @@ RUN groupadd -g 1000 apl \

# install packages
RUN apt-get update -q \
&& apt-get upgrade -qy \
&& apt-get install -y --no-install-recommends \
unzip \
build-essential \
Expand Down Expand Up @@ -57,7 +58,7 @@ RUN . ~/.bash_profile \

# install poetry
RUN . ~/.bash_profile \
&& python -m pip install poetry==1.6.1
&& python -m pip install poetry==1.7.1
RUN . ~/.bash_profile \
&& poetry config virtualenvs.create false

Expand Down Expand Up @@ -90,6 +91,7 @@ RUN . ~/.bash_profile \
&& poetry install --only main --no-root -E ibet-explorer \
&& rm -f /app/ibet-Prime/pyproject.toml \
&& rm -f /app/ibet-Prime/poetry.lock
ENV PYTHONPATH /app/ibet-Prime

# command deploy
USER apl
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ black:
test:
pytest tests/

test_migrations:
poetry run pytest -vv --test-alembic -m "alembic"

run:
poetry run gunicorn --worker-class server.AppUvicornWorker app.main:app
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<p align="center">
<img width="33%" src="https://user-images.githubusercontent.com/963333/71672471-6383c080-2db9-11ea-85b6-8815519652ec.png"/>
</p>

# ibet-Prime

<p>
<img alt="Version" src="https://img.shields.io/badge/version-23.12-blue.svg?cacheSeconds=2592000" />
<img alt="Version" src="https://img.shields.io/badge/version-24.3-blue.svg?cacheSeconds=2592000" />
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</p>

English | [日本語](./README_JA.md)

<img width="33%" align="right" src="https://user-images.githubusercontent.com/963333/71672471-6383c080-2db9-11ea-85b6-8815519652ec.png"/>

**The ibet-Prime security token management system for ibet network.**

## Features
Expand All @@ -29,7 +31,7 @@ English | [日本語](./README_JA.md)

## Supported ibet smart contract version

* ibet-SmartContract: version 22.12.0
* ibet-SmartContract: Supports the latest version of contract specifications.
* See [details](./contracts/contract_version.md).


Expand Down
10 changes: 6 additions & 4 deletions README_JA.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<p align="center">
<img width="33%" src="https://user-images.githubusercontent.com/963333/71672471-6383c080-2db9-11ea-85b6-8815519652ec.png"/>
</p>

# ibet-Prime

<p>
<img alt="Version" src="https://img.shields.io/badge/version-23.12-blue.svg?cacheSeconds=2592000" />
<img alt="Version" src="https://img.shields.io/badge/version-24.3-blue.svg?cacheSeconds=2592000" />
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</p>

[English](./README.md) | 日本語

<img width="33%" align="right" src="https://user-images.githubusercontent.com/963333/71672471-6383c080-2db9-11ea-85b6-8815519652ec.png"/>

**ibet-Prime は ibet network 向けの証券トークン管理システムです。**

## 機能概要
Expand All @@ -29,7 +31,7 @@

## コントラクトのバージョン

* ibet-SmartContract: バージョン 22.12.0
* ibet-SmartContract: 最新バージョンのコントラクトの仕様をサポートしています。
* [詳細](./contracts/contract_version.md)を参照ください。

## セットアップ
Expand Down
82 changes: 68 additions & 14 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,72 @@
SPDX-License-Identifier: Apache-2.0
"""

from typing import Annotated

from fastapi import Depends
from sqlalchemy import create_engine
from sqlalchemy import AsyncAdaptedQueuePool, create_engine
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import Session, sessionmaker

from config import DATABASE_SCHEMA, DATABASE_URL, DB_ECHO

options = {
"pool_recycle": 3600,
"pool_size": 10,
"pool_timeout": 30,
"pool_pre_ping": True,
"max_overflow": 30,
"echo": DB_ECHO,
}
engine = create_engine(DATABASE_URL, **options)

def get_engine(uri: str):
options = {
"pool_recycle": 3600,
"pool_size": 10,
"pool_timeout": 30,
"pool_pre_ping": True,
"max_overflow": 30,
"echo": DB_ECHO,
}
return create_engine(uri, **options)


def get_async_engine(uri: str):
options = {
"poolclass": AsyncAdaptedQueuePool,
"pool_recycle": 3600,
"pool_size": 10,
"pool_timeout": 30,
"pool_pre_ping": True,
"max_overflow": 30,
"echo": DB_ECHO,
}
return create_async_engine(uri, **options)


def get_batch_async_engine(uri: str):
options = {
"poolclass": AsyncAdaptedQueuePool,
"pool_pre_ping": True,
"echo": False,
}
return create_async_engine(uri, **options)


# Create Engine
engine = get_engine(DATABASE_URL)
async_engine = get_async_engine(DATABASE_URL)
batch_async_engine = get_batch_async_engine(DATABASE_URL)

# Create Session Maker
SessionLocal = sessionmaker(autocommit=False, autoflush=True, bind=engine)
AsyncSessionLocal = async_sessionmaker(
autocommit=False,
autoflush=True,
expire_on_commit=False,
bind=async_engine,
class_=AsyncSession,
)
BatchAsyncSessionLocal = async_sessionmaker(
autocommit=False,
autoflush=True,
expire_on_commit=False,
bind=batch_async_engine,
class_=AsyncSession,
)


def db_session():
Expand All @@ -44,11 +92,17 @@ def db_session():
db.close()


async def db_async_session():
db = AsyncSessionLocal()
try:
yield db
finally:
await db.close()


DBSession = Annotated[Session, Depends(db_session)]
DBAsyncSession = Annotated[AsyncSession, Depends(db_async_session)]


def get_db_schema():
if DATABASE_SCHEMA and engine.name != "mysql":
return DATABASE_SCHEMA
else:
return None
return DATABASE_SCHEMA
1 change: 1 addition & 0 deletions app/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from fastapi import status

from app.utils.contract_error_code import REVERT_CODE_MAP, error_code_msg
Expand Down
7 changes: 6 additions & 1 deletion app/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging
import sys
import urllib
Expand Down Expand Up @@ -128,7 +129,11 @@ def output_access_log(req: Request, res: Response, request_start_time: datetime)


def __auth_format(req: Request, address: str, msg: str):
return AUTH_FORMAT % (req.client.host, address, msg)
if req.client is None:
_host = ""
else:
_host = req.client.host
return AUTH_FORMAT % (_host, address, msg)


def __get_url(req: Request):
Expand Down
5 changes: 4 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from datetime import datetime

from fastapi import FastAPI, Request
Expand All @@ -35,6 +36,7 @@
common,
e2e_messaging,
file,
freeze_log,
ledger,
notification,
position,
Expand All @@ -60,7 +62,7 @@
app = FastAPI(
title="ibet Prime",
description="Security token management system for ibet network",
version="23.12.0",
version="24.3.0",
contact={"email": "dev@boostry.co.jp"},
license_info={
"name": "Apache 2.0",
Expand Down Expand Up @@ -102,6 +104,7 @@ async def root():
app.include_router(share.router)
app.include_router(token_holders.router)
app.include_router(bc_explorer.router)
app.include_router(freeze_log.router)


###############################################################
Expand Down
39 changes: 39 additions & 0 deletions app/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Copyright BOOSTRY Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
"""

from typing import Annotated, Any

from pydantic import WrapValidator
from pydantic_core.core_schema import ValidatorFunctionWrapHandler
from web3 import Web3


def ethereum_address_validator(
value: Any, handler: ValidatorFunctionWrapHandler, *args, **kwargs
):
"""Validator for ethereum address"""
if value is not None:
if not isinstance(value, str):
raise ValueError(f"value must be of string")
if not Web3.is_address(value):
raise ValueError("invalid ethereum address")
return value


EthereumAddress = Annotated[str, WrapValidator(ethereum_address_validator)]
2 changes: 2 additions & 0 deletions app/model/blockchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
SPDX-License-Identifier: Apache-2.0
"""

from .e2e_messaging import E2EMessaging
from .exchange import IbetExchangeInterface, IbetSecurityTokenEscrow
from .freeze_log import FreezeLogContract
from .personal_info import PersonalInfoContract
from .token import (
IbetSecurityTokenInterface,
Expand Down
Loading

0 comments on commit a996947

Please sign in to comment.