BlockchainType -> AvailableBlockchainType

pull/617/head
Yhtyyar Sahatov 2022-05-26 15:13:30 +03:00
rodzic 6d69976ee7
commit 73edce2952
2 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -5,8 +5,9 @@ import logging
import os import os
import sqlite3 import sqlite3
from shutil import copyfile from shutil import copyfile
from typing import Optional from typing import Optional, Union
from mooncrawl.data import AvailableBlockchainType
from moonstreamdb.db import yield_db_session_ctx from moonstreamdb.db import yield_db_session_ctx
from moonstreamdb.models import EthereumLabel, PolygonLabel from moonstreamdb.models import EthereumLabel, PolygonLabel
@ -53,6 +54,17 @@ def handle_initdb(args: argparse.Namespace) -> None:
setup_database(conn) setup_database(conn)
def _get_label_model(
blockchain: AvailableBlockchainType,
) -> Union[EthereumLabel, PolygonLabel]:
if blockchain == AvailableBlockchainType.ETHEREUM:
return EthereumLabel
elif blockchain == AvailableBlockchainType.POLYGON:
return PolygonLabel
else:
raise ValueError(f"Unknown blockchain: {blockchain}")
def handle_materialize(args: argparse.Namespace) -> None: def handle_materialize(args: argparse.Namespace) -> None:
if args.start is None or args.end is None: if args.start is None or args.end is None:
@ -65,9 +77,8 @@ def handle_materialize(args: argparse.Namespace) -> None:
logger.info(f"Materializing NFT events to datastore: {args.datastore}") logger.info(f"Materializing NFT events to datastore: {args.datastore}")
logger.info(f"Block bounds: {bounds}") logger.info(f"Block bounds: {bounds}")
label_model = ( blockchain_type = AvailableBlockchainType(args.blockchain)
EthereumLabel if args.blockchain == Blockchain.ETHEREUM else PolygonLabel label_model = _get_label_model(blockchain_type)
)
with yield_db_session_ctx() as db_session, contextlib.closing( with yield_db_session_ctx() as db_session, contextlib.closing(
sqlite3.connect(args.datastore) sqlite3.connect(args.datastore)
@ -162,8 +173,8 @@ def main() -> None:
parser_materialize.add_argument( parser_materialize.add_argument(
"--blockchain", "--blockchain",
type=Blockchain, type=AvailableBlockchainType,
choices=[Blockchain.ETHEREUM, Blockchain.POLYGON], choices=[AvailableBlockchainType.ETHEREUM, AvailableBlockchainType.POLYGON],
help="Blockchain to use", help="Blockchain to use",
) )

Wyświetl plik

@ -32,6 +32,7 @@ setup(
zip_safe=False, zip_safe=False,
install_requires=[ install_requires=[
"moonstreamdb", "moonstreamdb",
"mooncrawl",
"humbug", "humbug",
"numpy", "numpy",
"pandas", "pandas",