Skip to content

Commit

Permalink
Merge pull request #15 from coder1963/bump-pydantic
Browse files Browse the repository at this point in the history
bump sqlmodel / pydantic / fastapi
  • Loading branch information
robcxyz authored Dec 1, 2024
2 parents 7822d51 + 2205445 commit 52aebca
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 43 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ ps: ## List all containers and running status
postgres-console: ## Start postgres terminal
docker compose -f docker-compose.db.yml -f docker-compose.yml exec postgres psql -U postgres

install: ## Install requirements
pip install -r requirements_api.txt -r requirements_worker.txt -r requirements_dev.txt

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'
2 changes: 1 addition & 1 deletion icon_contracts/api/v1/endpoints/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def get_contracts(
) -> List[Contract]:
"""Return list of contracts"""
query = select(Contract).offset(skip).limit(limit)
query_count = select([func.count(Contract.address)])
query_count = select(func.count(Contract.address))

if contract_type:
query = query.where(Contract.contract_type == contract_type)
Expand Down
21 changes: 11 additions & 10 deletions icon_contracts/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from pydantic import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
Expand Down Expand Up @@ -38,9 +38,9 @@ class Settings(BaseSettings):
LOG_FORMAT: str = "string"

# ICON Nodes
ICON_NODE_URL = "https://api.icon.community/api/v3"
ICON_NODE_URL: str = "https://api.icon.community/api/v3"
# ICON_NODE_URL: str = "https://berlin.net.solidwallet.io/api/v3"
BACKUP_ICON_NODE_URL = "https://ctz.solidwallet.io/api/v3"
BACKUP_ICON_NODE_URL:str = "https://ctz.solidwallet.io/api/v3"

COMMUNITY_API_ENDPOINT: str = "https://tracker.icon.community"

Expand All @@ -50,7 +50,7 @@ class Settings(BaseSettings):

# KAFKA_GROUP_ID: str = "contracts"
CONSUMER_IS_TAIL: bool = False
JOB_ID: str = None
JOB_ID: str | None = None
CONSUMER_GROUP: str = "contracts"
# Change this to "earliest" + CONSUMER_GROUP to trigger a manual backfill
CONSUMER_AUTO_OFFSET_RESET: str = "latest"
Expand All @@ -68,9 +68,9 @@ class Settings(BaseSettings):
POSTGRES_DATABASE: str = "postgres"

# Contract S3 Upload
CONTRACTS_S3_AWS_ACCESS_KEY_ID: str = None
CONTRACTS_S3_AWS_SECRET_ACCESS_KEY: str = None
CONTRACTS_S3_BUCKET: str = None
CONTRACTS_S3_AWS_ACCESS_KEY_ID: str | None = None
CONTRACTS_S3_AWS_SECRET_ACCESS_KEY: str | None = None
CONTRACTS_S3_BUCKET: str | None = None

# Endpoints
MAX_PAGE_SIZE: int = 100
Expand Down Expand Up @@ -98,9 +98,10 @@ class Settings(BaseSettings):
governance_address: str = "cx0000000000000000000000000000000000000000"
one_address: str = "cx0000000000000000000000000000000000000001"

class Config:
case_sensitive = False


model_config = SettingsConfigDict(
case_sensitive=False,
)

if os.environ.get("ENV_FILE", False):
settings = Settings(_env_file=os.environ.get("ENV_FILE"))
Expand Down
32 changes: 18 additions & 14 deletions icon_contracts/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,44 @@ class Contract(SQLModel, table=True):
address: str = Field(primary_key=True)

name: Optional[str] = Field(None, index=False)
symbol: str = Field(None, index=False)
decimals: str = Field(None, index=False)
symbol: Optional[str] = Field(None, index=False)
decimals: Optional[str] = Field(None, index=False)

contract_type: str = Field(None, index=True, description="One of python / java")
token_standard: str = Field(None, index=True, description="One of Contract, IRC2")
contract_type: Optional[str] = Field(None, index=True, description="One of python / java")
token_standard: Optional[str] = Field(None, index=True, description="One of Contract, IRC2")

email: Optional[str] = Field(None, index=False)
website: Optional[str] = Field(None, index=False)

last_updated_block: Optional[int] = Field(None, index=True)
last_updated_timestamp: Optional[int] = Field(None, sa_column=Column(BIGINT), index=True)
last_updated_timestamp: Optional[int] = Field(
None, sa_column=Column(BIGINT, index=True)
)
created_block: Optional[int] = Field(None, index=True)
created_timestamp: Optional[int] = Field(None, sa_column=Column(BIGINT), index=True)
created_timestamp: Optional[int] = Field(
None, sa_column=Column(BIGINT, index=True)
)
creation_hash: Optional[str] = Field(None, index=False)

owner_address: Optional[str] = Field(None, index=False)

current_version: Optional[str] = Field(None, index=False)

abi: List[dict] = Field(None, index=False, sa_column=Column(JSON))
abi: List[dict] = Field(None, sa_column=Column(JSON, index=False))

source_code_link: str = Field(None, index=False)
verified_source_code_link: str = Field(None, index=False)
verified: bool = Field(False, index=True)
revision_number: int = Field(
source_code_link: Optional[str] = Field(None, index=False)
verified_source_code_link: Optional[str] = Field(None, index=False)
verified: Optional[bool] = Field(False, index=True)
revision_number: Optional[int] = Field(
-1,
index=False,
description="Out of order ID for zipped up source code in s3 "
"/bucket/[address]_[revision_number].zip",
)

audit_tx_hash: str = Field(None, index=False)
code_hash: str = Field(None, index=False)
deploy_tx_hash: str = Field(None, index=False)
audit_tx_hash: Optional[str] = Field(None, index=False)
code_hash: Optional[str] = Field(None, index=False)
deploy_tx_hash: Optional[str] = Field(None, index=False)

status: Optional[str] = Field(
None, index=True, description="Field to inform audit status of 1.0 contracts."
Expand Down
3 changes: 2 additions & 1 deletion icon_contracts/workers/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# from confluent_kafka.serialization import StringSerializer
from loguru import logger
from pydantic import BaseModel
from sqlalchemy import text

from icon_contracts.config import settings

Expand All @@ -25,7 +26,7 @@ def get_current_offset(session):
output = {}
while True:
logger.info(f"Getting kafka job with job_id = {settings.JOB_ID}")
sql = f"select * from kafka_jobs WHERE job_id='{settings.JOB_ID}';"
sql = text(f"select * from kafka_jobs WHERE job_id='{settings.JOB_ID}';")
result = session.execute(sql).fetchall()
session.commit()

Expand Down
13 changes: 7 additions & 6 deletions requirements_api.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
loguru==0.5.3
prometheus_client==0.11.0
asyncpg==0.24.0
fastapi==0.68.1
sqlmodel==0.0.4
uvicorn==0.15.0
asyncpg
fastapi
sqlmodel
uvicorn
requests==2.26.0
fastapi-health==0.4.0
brotli-asgi==1.1.0
fastapi-health
brotli-asgi==1.1.0
pydantic_settings
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pytest
pytest-mock
pytest-cov

docker-compose
grpcio-tools==1.40.0
# docker-compose
grpcio-tools
10 changes: 5 additions & 5 deletions requirements_worker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ requests==2.26.0
loguru==0.5.3
prometheus_client==0.11.0

grpcio==1.40.0
grpcio

# Temporary breaking change
protobuf==3.20.1
protobuf==3.20.*
confluent_kafka
psycopg2-binary
alembic==1.7.1
asyncpg==0.24.0
sqlmodel==0.0.4
alembic
asyncpg
sqlmodel
9 changes: 5 additions & 4 deletions tests/integration/worker/test_partition_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from sqlalchemy import text

from icon_contracts.config import settings
from icon_contracts.workers.kafka import get_current_offset
Expand All @@ -10,17 +11,17 @@
def backfill_job(db):
def f(job_id):
with db as session:
sql = "DROP TABLE IF EXISTS kafka_jobs;"
sql = text("DROP TABLE IF EXISTS kafka_jobs;")
session.execute(sql)
session.commit()

sql = "CREATE TABLE IF NOT EXISTS kafka_jobs (job_id varchar, worker_group varchar, topic varchar, partition bigint, stop_offset bigint, PRIMARY KEY (job_id, worker_group, topic, partition));"
sql = text("CREATE TABLE IF NOT EXISTS kafka_jobs (job_id varchar, worker_group varchar, topic varchar, partition bigint, stop_offset bigint, PRIMARY KEY (job_id, worker_group, topic, partition));")
session.execute(sql)
session.commit()

num_msgs = 1000
for i in range(0, 12):
sql = (
sql = text(
f"INSERT INTO kafka_jobs (job_id, worker_group, topic, partition, stop_offset) VALUES "
f"('{job_id}','{settings.CONSUMER_GROUP}-{job_id}',"
f"'{settings.CONSUMER_TOPIC_BLOCKS}','{i}','{num_msgs}');"
Expand All @@ -33,7 +34,7 @@ def f(job_id):


def test_get_current_offset(db, backfill_job):
settings.JOB_ID = "test6"
settings.JOB_ID = text("test6")
backfill_job(settings.JOB_ID)

with db as session:
Expand Down

0 comments on commit 52aebca

Please sign in to comment.