Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make face_value_currency required & Manage token contract versions #561

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/model/blockchain/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@
from app.model.db import TokenAttrUpdate, TokenCache
from app.utils.contract_utils import ContractUtils
from app.utils.web3_utils import Web3Wrapper
from config import CHAIN_ID, TOKEN_CACHE, TOKEN_CACHE_TTL, TX_GAS_LIMIT, ZERO_ADDRESS
from config import (
CHAIN_ID,
DEFAULT_CURRENCY,
TOKEN_CACHE,
TOKEN_CACHE_TTL,
TX_GAS_LIMIT,
ZERO_ADDRESS,
)

LOG = log.get_logger()

Expand Down Expand Up @@ -500,7 +507,7 @@ def get(self):
# Set IbetStraightBondToken attribute
self.face_value = ContractUtils.call_function(contract, "faceValue", (), 0)
self.face_value_currency = ContractUtils.call_function(
contract, "faceValueCurrency", (), ""
contract, "faceValueCurrency", (), DEFAULT_CURRENCY
)
self.interest_rate = float(
Decimal(str(ContractUtils.call_function(contract, "interestRate", (), 0)))
Expand Down
2 changes: 1 addition & 1 deletion app/model/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from .node import Node
from .notification import Notification, NotificationType
from .scheduled_events import ScheduledEvents, ScheduledEventType
from .token import Token, TokenAttrUpdate, TokenCache, TokenType
from .token import Token, TokenAttrUpdate, TokenCache, TokenType, TokenVersion
from .token_holders import TokenHolder, TokenHolderBatchStatus, TokenHoldersList
from .token_update_operation_log import (
TokenUpdateOperationCategory,
Expand Down
23 changes: 15 additions & 8 deletions app/model/db/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,41 @@
SPDX-License-Identifier: Apache-2.0
"""
from datetime import datetime
from enum import Enum
from enum import Enum, StrEnum

from sqlalchemy import JSON, DateTime, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base


class TokenType(str, Enum):
IBET_STRAIGHT_BOND = "IbetStraightBond"
IBET_SHARE = "IbetShare"


class TokenVersion(StrEnum):
V_22_12 = "22_12"
V_23_12 = "23_12"


class Token(Base):
"""Issued Token"""

__tablename__ = "token"

id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
# token type
type: Mapped[str] = mapped_column(String(40), nullable=False)
type: Mapped[TokenType] = mapped_column(String(40), nullable=False)
# transaction hash
tx_hash: Mapped[str] = mapped_column(String(66), nullable=False)
# issuer address
issuer_address: Mapped[str] = mapped_column(String(42), nullable=True)
# token address
token_address: Mapped[str] = mapped_column(String(42), nullable=True)
# ABI
# contract version
version: Mapped[TokenVersion] = mapped_column(String(5), nullable=False)
# contract ABI
abi: Mapped[dict] = mapped_column(JSON, nullable=False)
# token processing status (pending:0, succeeded:1, failed:2)
token_status: Mapped[int | None] = mapped_column(Integer, default=1)
Expand All @@ -58,11 +70,6 @@ class TokenAttrUpdate(Base):
updated_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False)


class TokenType(str, Enum):
IBET_STRAIGHT_BOND = "IbetStraightBond"
IBET_SHARE = "IbetShare"


class TokenCache(Base):
"""Token Cache"""

Expand Down
1 change: 0 additions & 1 deletion app/model/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,3 @@
UpdateTransferApprovalOperationType,
UpdateTransferApprovalRequest,
)
from .types import ResultSet
27 changes: 27 additions & 0 deletions app/model/schema/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
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 .base import (
EMPTY_str,
IbetShareContractVersion,
IbetStraightBondContractVersion,
MMDD_constr,
ResultSet,
SortOrder,
YYYYMMDD_constr,
)
31 changes: 25 additions & 6 deletions app/model/schema/types.py → app/model/schema/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,25 @@

SPDX-License-Identifier: Apache-2.0
"""
from enum import IntEnum
from enum import IntEnum, StrEnum
from typing import Literal, Optional

from pydantic import BaseModel, Field, StringConstraints
from typing_extensions import Annotated


############################
# COMMON
############################
class IbetStraightBondContractVersion(StrEnum):
V_22_12 = "22_12"
V_23_12 = "23_12"


class IbetShareContractVersion(StrEnum):
V_22_12 = "22_12"
Comment on lines +29 to +35
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It defines the possible versions of each token.



MMDD_constr = Annotated[
str, StringConstraints(pattern="^(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$")
]
Expand All @@ -34,15 +47,21 @@
EMPTY_str = Literal[""]


############################
# REQUEST
############################
class SortOrder(IntEnum):
ASC = 0
DESC = 1


############################
# RESPONSE
############################
class ResultSet(BaseModel):
"""result set for pagination"""

count: Optional[int] = Field(...)
offset: Optional[int] = Field(...)
limit: Optional[int] = Field(...)
total: Optional[int] = Field(...)


class SortOrder(IntEnum):
ASC = 0
DESC = 1
2 changes: 1 addition & 1 deletion app/model/schema/batch_issue_redeem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from pydantic import BaseModel, ConfigDict, Field

from app.model.db import TokenType
from app.model.schema.base import ResultSet

from .personal_info import PersonalInfo
from .types import ResultSet

############################
# RESPONSE
Expand Down
2 changes: 1 addition & 1 deletion app/model/schema/bc_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pydantic.dataclasses import dataclass
from web3 import Web3

from .types import ResultSet, SortOrder
from app.model.schema.base import ResultSet, SortOrder

############################
# COMMON
Expand Down
3 changes: 1 addition & 2 deletions app/model/schema/e2e_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

from pydantic import BaseModel, Field, field_validator

from app.model.schema.base import ResultSet
from app.utils.check_utils import check_value_is_encrypted
from config import E2EE_REQUEST_ENABLED

from .types import ResultSet


############################
# REQUEST
Expand Down
5 changes: 2 additions & 3 deletions app/model/schema/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
"""
import base64
from datetime import datetime
from typing import Any, Dict, List, Optional
from typing import List, Optional

from pydantic import BaseModel, Field, field_validator

from app.model.schema.base import ResultSet
from config import MAX_UPLOAD_FILE_SIZE

from .types import ResultSet

############################
# REQUEST
############################
Expand Down
2 changes: 1 addition & 1 deletion app/model/schema/issue_redeem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from pydantic import BaseModel

from .types import ResultSet
from app.model.schema.base import ResultSet

############################
# REQUEST
Expand Down
3 changes: 1 addition & 2 deletions app/model/schema/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from pydantic import BaseModel, Field, field_validator

from app.model.db import LedgerDetailsDataType, TokenType

from .types import ResultSet
from app.model.schema.base import ResultSet

############################
# REQUEST
Expand Down
4 changes: 1 addition & 3 deletions app/model/schema/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

SPDX-License-Identifier: Apache-2.0
"""

from typing import List, Literal, Optional, Union

from pydantic import BaseModel, Field, RootModel
from typing_extensions import Annotated

from app.model.db import BatchIssueRedeemProcessingCategory, NotificationType, TokenType

from .types import ResultSet
from app.model.schema.base import ResultSet


class IssueErrorMetaInfo(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion app/model/schema/personal_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from web3 import Web3

from app.model.db import BatchRegisterPersonalInfoUploadStatus
from app.model.schema.types import ResultSet
from app.model.schema.base import ResultSet


class PersonalInfo(BaseModel):
Expand Down
3 changes: 1 addition & 2 deletions app/model/schema/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from web3 import Web3

from app.model.db import TokenType

from .types import ResultSet, SortOrder
from app.model.schema.base import ResultSet, SortOrder

############################
# COMMON
Expand Down
15 changes: 13 additions & 2 deletions app/model/schema/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@
from pydantic.dataclasses import dataclass
from web3 import Web3

from app.model.schema.base import (
EMPTY_str,
IbetShareContractVersion,
IbetStraightBondContractVersion,
MMDD_constr,
ResultSet,
SortOrder,
YYYYMMDD_constr,
)

from . import LockEventCategory
from .position import LockEvent
from .types import EMPTY_str, MMDD_constr, ResultSet, SortOrder, YYYYMMDD_constr


############################
Expand All @@ -40,7 +49,7 @@ class IbetStraightBondCreate(BaseModel):
name: str = Field(max_length=100)
total_supply: int = Field(..., ge=0, le=1_000_000_000_000)
face_value: int = Field(..., ge=0, le=5_000_000_000)
face_value_currency: Optional[str] = Field(default=None, min_length=3, max_length=3)
face_value_currency: str = Field(..., min_length=3, max_length=3)
purpose: str = Field(max_length=2000)
symbol: Optional[str] = Field(default=None, max_length=100)
redemption_date: Optional[YYYYMMDD_constr] = None
Expand Down Expand Up @@ -539,6 +548,7 @@ class IbetStraightBondResponse(BaseModel):
token_status: int
transfer_approval_required: bool
memo: str
contract_version: IbetStraightBondContractVersion


class IbetShareResponse(BaseModel):
Expand Down Expand Up @@ -567,6 +577,7 @@ class IbetShareResponse(BaseModel):
token_status: int
is_canceled: bool
memo: str
contract_version: IbetShareContractVersion


class TokenOperationLogResponse(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion app/model/schema/token_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from pydantic import BaseModel, ConfigDict, Field, NonNegativeInt, field_validator

from app.model.db import TokenHolderBatchStatus
from app.model.schema.base import ResultSet, SortOrder
from app.model.schema.personal_info import PersonalInfoIndex
from app.model.schema.types import ResultSet, SortOrder


############################
Expand Down
3 changes: 2 additions & 1 deletion app/model/schema/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
from pydantic import BaseModel, Field, NonNegativeInt
from pydantic.dataclasses import dataclass

from app.model.schema.base import ResultSet

from .personal_info import PersonalInfo
from .types import ResultSet

############################
# COMMON
Expand Down
Loading
Loading