Merge branch 'main' into add-contracts-table

pull/1130/head
Andrey 2024-11-04 14:31:40 +02:00
commit a7194c985c
12 zmienionych plików z 460 dodań i 40 usunięć

Wyświetl plik

@ -1181,10 +1181,10 @@ def create_resource_for_user(
return resource
def chekc_user_resource_access(
def check_user_resource_access(
customer_id: uuid.UUID,
user_token: uuid.UUID,
) -> bool:
) -> Optional[BugoutResource]:
"""
Check if user has access to customer_id
"""
@ -1198,10 +1198,10 @@ def chekc_user_resource_access(
except BugoutResponseException as e:
if e.status_code == 404:
return False
return None
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
except Exception as e:
logger.error(f"Error get customer: {str(e)}")
raise MoonstreamHTTPException(status_code=500, internal_error=e)
return str(response.id) == customer_id
return response

Wyświetl plik

@ -315,6 +315,33 @@ def create_v3_task_handler(args: argparse.Namespace) -> None:
)
def delete_v3_task_handler(args: argparse.Namespace) -> None:
tasks = moonworm_tasks.get_v3_tasks(
user_id=args.user_id,
customer_id=args.customer_id,
blockchain=args.blockchain,
address=args.address,
)
tasks_dict_output: Dict[str, int] = {}
for task in tasks:
if task.chain not in tasks_dict_output:
tasks_dict_output[task.chain] = 0
tasks_dict_output[task.chain] += 1
print("Found:")
for k, v in tasks_dict_output.items():
print(f"- {k} - {v} tasks")
response = input(f"Delete {len(tasks)} tasks? (yes/y): ").strip().lower()
if response != "yes" and response != "y":
logger.warning("Canceled")
return
moonworm_tasks.delete_v3_tasks(tasks=tasks)
def main() -> None:
cli_description = f"""Moonstream Admin CLI
@ -598,8 +625,8 @@ This CLI is configured to work with the following API URLs:
parser_moonworm_tasks_migrate.set_defaults(func=moonworm_tasks_v3_migrate)
parser_moonworm_tasks_v3_create = subcommands_moonworm_tasks.add_parser(
"create_v3_tasks",
description="Create v3 tasks from v2 tasks",
"create-v3-tasks",
description="Create new v3 tasks",
)
parser_moonworm_tasks_v3_create.add_argument(
@ -639,6 +666,37 @@ This CLI is configured to work with the following API URLs:
parser_moonworm_tasks_v3_create.set_defaults(func=create_v3_task_handler)
parser_moonworm_tasks_v3_delete = subcommands_moonworm_tasks.add_parser(
"delete-v3-tasks",
description="Delete v3 tasks",
)
parser_moonworm_tasks_v3_delete.add_argument(
"--user-id",
type=uuid_type,
help="The user ID of which we wish to delete the task",
)
parser_moonworm_tasks_v3_delete.add_argument(
"--customer-id",
type=uuid_type,
help="The customer ID of which we wish to delete the task",
)
parser_moonworm_tasks_v3_delete.add_argument(
"--blockchain",
type=str,
help="Blockchain name",
)
parser_moonworm_tasks_v3_delete.add_argument(
"--address",
type=str,
help="Contract address",
)
parser_moonworm_tasks_v3_delete.set_defaults(func=delete_v3_task_handler)
queries_parser = subcommands.add_parser(
"queries", description="Manage Moonstream queries"
)

Wyświetl plik

@ -174,6 +174,70 @@ def create_v3_task(
return None
def get_v3_tasks(
customer_id: Optional[str] = None,
user_id: Optional[str] = None,
address: Optional[str] = None,
blockchain: Optional[str] = None,
) -> List[AbiJobs]:
"""
Get moonworm v3 tasks.
"""
if (
customer_id is None
and user_id is None
and address is None
and blockchain is None
):
raise Exception(
"At least one of customer_id, or user_id, or address, or blockchain should be set"
)
db_engine = MoonstreamDBIndexesEngine()
with db_engine.yield_db_session_ctx() as db_session_v3:
query = db_session_v3.query(AbiJobs)
if customer_id is not None:
query = query.filter(AbiJobs.customer_id == customer_id)
if user_id is not None:
query = query.filter(AbiJobs.user_id == user_id)
if address is not None:
query = query.filter(AbiJobs.address == bytes.fromhex(address[2:]))
if blockchain is not None:
query = query.filter(AbiJobs.chain == blockchain)
try:
tasks = query.all()
except Exception as e:
logger.error(f"Error selecting tasks, err: {str(e)}")
raise e
return tasks
def delete_v3_tasks(tasks: List[AbiJobs]) -> None:
tasks_len = len(tasks)
if tasks_len == 0:
raise Exception("No tasks to delete")
db_engine = MoonstreamDBIndexesEngine()
with db_engine.yield_db_session_ctx() as db_session_v3:
try:
for task in tasks:
db_session_v3.delete(task)
pass
db_session_v3.commit()
except Exception as e:
logger.error(f"Error delete tasks: {str(e)}")
db_session_v3.rollback()
raise e
logger.info(f"Deleted {tasks_len} tasks")
def migrate_v3_tasks(
user_id: UUID, customer_id: UUID, blockchain: Optional[str] = None
):

Wyświetl plik

@ -20,7 +20,7 @@ from ..actions import (
EntityJournalNotFoundException,
apply_moonworm_tasks,
check_if_smart_contract,
chekc_user_resource_access,
check_user_resource_access,
get_entity_subscription_journal_id,
get_list_of_support_interfaces,
get_moonworm_tasks,
@ -104,17 +104,19 @@ async def add_subscription_handler(
if customer_id is not None:
results = chekc_user_resource_access(
results = check_user_resource_access(
customer_id=customer_id,
user_token=token,
)
if not results:
if results is None:
raise MoonstreamHTTPException(
status_code=403,
detail="User has no access to this customer",
status_code=404,
detail="Not found customer",
)
customer_instance_name = results.resource_data["name"]
active_subscription_types_response = subscription_types.list_subscription_types(
active_only=True
)
@ -156,12 +158,12 @@ async def add_subscription_handler(
if description:
content["description"] = description
excluded_keys = MOONSTREAM_ENTITIES_RESERVED_TAGS
allowed_required_fields: List[Any] = []
if tags:
allowed_required_fields = [
item
for item in tags
if not any(key in item for key in MOONSTREAM_ENTITIES_RESERVED_TAGS)
item for item in tags if not any(key in item for key in excluded_keys)
]
required_fields: List[Dict[str, Union[str, bool, int, List[Any]]]] = [
@ -172,6 +174,18 @@ async def add_subscription_handler(
{"user_id": f"{user.id}"},
]
if customer_id is not None and customer_instance_name is not None:
required_fields.extend(
[
{
"customer_id": f"{customer_id}",
},
{
"instance_name": f"{customer_instance_name}",
},
]
)
if allowed_required_fields:
required_fields.extend(allowed_required_fields)
@ -214,11 +228,15 @@ async def add_subscription_handler(
entity_secondary_fields = (
entity.secondary_fields if entity.secondary_fields is not None else {}
)
# We remove the instance_name for return that tag to the frontend
excluded_keys = excluded_keys - {"instance_name"}
normalized_entity_tags = [
f"{key}:{value}"
for tag in entity_required_fields
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in excluded_keys
]
if entity_secondary_fields.get("abi") and customer_id is not None:
@ -310,7 +328,7 @@ async def delete_subscription_handler(
f"{key}:{value}"
for tag in tags_raw
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in (MOONSTREAM_ENTITIES_RESERVED_TAGS - {"instance_name"})
]
if deleted_entity.secondary_fields is not None:
@ -383,6 +401,9 @@ async def get_subscriptions_handler(
List[BugoutSearchResultAsEntity], subscriptions_list.results
)
# We remove the instance_name for return that tag to the frontend
excluded_keys = MOONSTREAM_ENTITIES_RESERVED_TAGS - {"instance_name"}
for subscription in user_subscriptions_results:
tags = subscription.required_fields
@ -402,7 +423,7 @@ async def get_subscriptions_handler(
f"{key}:{value}"
for tag in tags
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in excluded_keys
]
subscriptions.append(
@ -460,17 +481,19 @@ async def update_subscriptions_handler(
if customer_id is not None:
results = chekc_user_resource_access(
results = check_user_resource_access(
customer_id=customer_id,
user_token=token,
)
if not results:
if results is None:
raise MoonstreamHTTPException(
status_code=403,
detail="User has no access to this customer",
status_code=404,
detail="Not found customer",
)
excluded_keys = MOONSTREAM_ENTITIES_RESERVED_TAGS
try:
journal_id = get_entity_subscription_journal_id(
resource_type=BUGOUT_RESOURCE_TYPE_ENTITY_SUBSCRIPTION,
@ -490,7 +513,7 @@ async def update_subscriptions_handler(
update_required_fields = [
field
for field in subscription_entity.required_fields
if any(key in field for key in MOONSTREAM_ENTITIES_RESERVED_TAGS)
if any(key in field for key in excluded_keys)
]
update_secondary_fields = (
@ -556,9 +579,7 @@ async def update_subscriptions_handler(
if tags:
allowed_required_fields = [
item
for item in tags
if not any(key in item for key in MOONSTREAM_ENTITIES_RESERVED_TAGS)
item for item in tags if not any(key in item for key in excluded_keys)
]
if allowed_required_fields:
@ -619,12 +640,14 @@ async def update_subscriptions_handler(
if subscription.secondary_fields is not None
else {}
)
# We remove the instance_name for return that tag to the frontend
excluded_keys = excluded_keys - {"instance_name"}
normalized_entity_tags = [
f"{key}:{value}"
for tag in subscription_required_fields
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in excluded_keys
]
return data.SubscriptionResourceData(

Wyświetl plik

@ -301,15 +301,19 @@ if MOONSTREAM_S3_QUERIES_BUCKET_PREFIX == "":
)
# Entities reserved tags
MOONSTREAM_ENTITIES_RESERVED_TAGS = [
"type",
"subscription_type_id",
"color",
"label",
"user_id",
"address",
"blockchain",
]
MOONSTREAM_ENTITIES_RESERVED_TAGS = set(
[
"type",
"subscription_type_id",
"color",
"label",
"user_id",
"address",
"blockchain",
"customer_id",
"instance_name",
]
)
## Moonstream resources types

Wyświetl plik

@ -25,6 +25,7 @@ target_metadata = MoonstreamBase.metadata
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
from moonstreamdbv3.models import (
MOONSTREAM_DB_V3_SCHEMA_NAME,
AmoyLabel,
ArbitrumNovaLabel,
ArbitrumOneLabel,
@ -37,6 +38,7 @@ from moonstreamdbv3.models import (
BlastLabel,
BlastSepoliaLabel,
EthereumLabel,
Game7Label,
Game7OrbitArbitrumSepoliaLabel,
Game7TestnetLabel,
ImxZkevmLabel,
@ -71,6 +73,7 @@ def include_symbol(tablename, schema):
ArbitrumNovaLabel.__tablename__,
ArbitrumOneLabel.__tablename__,
ArbitrumSepoliaLabel.__tablename__,
Game7Label.__tablename__,
Game7OrbitArbitrumSepoliaLabel.__tablename__,
Game7TestnetLabel.__tablename__,
XaiLabel.__tablename__,
@ -110,6 +113,7 @@ def run_migrations_offline() -> None:
literal_binds=True,
dialect_opts={"paramstyle": "named"},
version_table="alembic_version",
version_table_schema=MOONSTREAM_DB_V3_SCHEMA_NAME,
include_schemas=True,
include_symbol=include_symbol,
)
@ -136,6 +140,7 @@ def run_migrations_online() -> None:
connection=connection,
target_metadata=target_metadata,
version_table="alembic_version",
version_table_schema=MOONSTREAM_DB_V3_SCHEMA_NAME,
include_schemas=True,
include_symbol=include_symbol,
)

Wyświetl plik

@ -0,0 +1,75 @@
"""Add Game7 mainnet labels
Revision ID: d816689b786a
Revises: 1d53afc1eff4
Create Date: 2024-10-14 15:58:21.374247
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = 'd816689b786a'
down_revision: Union[str, None] = '1d53afc1eff4'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('game7_labels',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('label', sa.VARCHAR(length=256), nullable=False),
sa.Column('transaction_hash', sa.VARCHAR(length=128), nullable=False),
sa.Column('log_index', sa.Integer(), nullable=True),
sa.Column('block_number', sa.BigInteger(), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('block_timestamp', sa.BigInteger(), nullable=False),
sa.Column('caller_address', sa.LargeBinary(), nullable=True),
sa.Column('origin_address', sa.LargeBinary(), nullable=True),
sa.Column('address', sa.LargeBinary(), nullable=False),
sa.Column('label_name', sa.Text(), nullable=True),
sa.Column('label_type', sa.VARCHAR(length=64), nullable=True),
sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_game7_labels')),
sa.UniqueConstraint('id', name=op.f('uq_game7_labels_id'))
)
op.create_index('ix_game7_labels_addr_block_num', 'game7_labels', ['address', 'block_number'], unique=False)
op.create_index('ix_game7_labels_addr_block_ts', 'game7_labels', ['address', 'block_timestamp'], unique=False)
op.create_index(op.f('ix_game7_labels_address'), 'game7_labels', ['address'], unique=False)
op.create_index(op.f('ix_game7_labels_block_number'), 'game7_labels', ['block_number'], unique=False)
op.create_index(op.f('ix_game7_labels_caller_address'), 'game7_labels', ['caller_address'], unique=False)
op.create_index(op.f('ix_game7_labels_label'), 'game7_labels', ['label'], unique=False)
op.create_index(op.f('ix_game7_labels_label_name'), 'game7_labels', ['label_name'], unique=False)
op.create_index(op.f('ix_game7_labels_label_type'), 'game7_labels', ['label_type'], unique=False)
op.create_index(op.f('ix_game7_labels_origin_address'), 'game7_labels', ['origin_address'], unique=False)
op.create_index(op.f('ix_game7_labels_transaction_hash'), 'game7_labels', ['transaction_hash'], unique=False)
op.create_index('uk_game7_labels_tx_hash_log_idx_evt', 'game7_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'"))
op.create_index('uk_game7_labels_tx_hash_log_idx_evt_raw', 'game7_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'"))
op.create_index('uk_game7_labels_tx_hash_tx_call', 'game7_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'"))
op.create_index('uk_game7_labels_tx_hash_tx_call_raw', 'game7_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('uk_game7_labels_tx_hash_tx_call_raw', table_name='game7_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"))
op.drop_index('uk_game7_labels_tx_hash_tx_call', table_name='game7_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'"))
op.drop_index('uk_game7_labels_tx_hash_log_idx_evt_raw', table_name='game7_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'"))
op.drop_index('uk_game7_labels_tx_hash_log_idx_evt', table_name='game7_labels', postgresql_where=sa.text("label='seer' and label_type='event'"))
op.drop_index(op.f('ix_game7_labels_transaction_hash'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_origin_address'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_label_type'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_label_name'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_label'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_caller_address'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_block_number'), table_name='game7_labels')
op.drop_index(op.f('ix_game7_labels_address'), table_name='game7_labels')
op.drop_index('ix_game7_labels_addr_block_ts', table_name='game7_labels')
op.drop_index('ix_game7_labels_addr_block_num', table_name='game7_labels')
op.drop_table('game7_labels')
# ### end Alembic commands ###

Wyświetl plik

@ -44,10 +44,12 @@ from moonstreamdbv3.models_indexes import (
EthereumLogIndex,
EthereumReorgs,
EthereumTransactionIndex,
Game7BlockIndex,
Game7OrbitArbitrumSepoliaBlockIndex,
Game7OrbitArbitrumSepoliaLogIndex,
Game7OrbitArbitrumSepoliaReorgs,
Game7OrbitArbitrumSepoliaTransactionIndex,
Game7Reorgs,
Game7TestnetBlockIndex,
Game7TestnetLogIndex,
Game7TestnetReorgs,
@ -113,6 +115,8 @@ def include_symbol(tablename, schema):
Game7OrbitArbitrumSepoliaTransactionIndex.__tablename__,
Game7OrbitArbitrumSepoliaLogIndex.__tablename__,
Game7OrbitArbitrumSepoliaReorgs.__tablename__,
Game7BlockIndex.__tablename__,
Game7Reorgs.__tablename__,
Game7TestnetBlockIndex.__tablename__,
Game7TestnetTransactionIndex.__tablename__,
Game7TestnetLogIndex.__tablename__,

Wyświetl plik

@ -1,8 +1,8 @@
"""Add contracts tables
Revision ID: e1ca63e94f03
Revises: 6807bdf6f417
Create Date: 2024-11-04 13:34:09.484335
Revision ID: 82ff1541f4b4
Revises: c1bc596631f9
Create Date: 2024-11-04 14:29:45.303216
"""
@ -13,8 +13,8 @@ import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = "e1ca63e94f03"
down_revision: Union[str, None] = "6807bdf6f417"
revision: str = "82ff1541f4b4"
down_revision: Union[str, None] = "c1bc596631f9"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
@ -325,6 +325,59 @@ def upgrade() -> None:
["transaction_hash"],
unique=False,
)
op.create_table(
"game7_contracts",
sa.Column("address", sa.LargeBinary(length=20), nullable=False),
sa.Column("deployed_bytecode", sa.Text(), nullable=False),
sa.Column("deployed_bytecode_hash", sa.VARCHAR(length=32), nullable=False),
sa.Column("bytecode_storage_id", sa.UUID(), nullable=True),
sa.Column("abi", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column("deployed_at_block_number", sa.BigInteger(), nullable=False),
sa.Column("deployed_at_block_hash", sa.VARCHAR(length=256), nullable=False),
sa.Column("deployed_at_block_timestamp", sa.BigInteger(), nullable=False),
sa.Column("transaction_hash", sa.VARCHAR(length=256), nullable=False),
sa.Column("transaction_index", sa.BigInteger(), nullable=False),
sa.Column("name", sa.VARCHAR(length=256), nullable=True),
sa.Column("statistics", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column(
"supported_standards",
postgresql.JSONB(astext_type=sa.Text()),
nullable=True,
),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("TIMEZONE('utc', statement_timestamp())"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.text("TIMEZONE('utc', statement_timestamp())"),
nullable=False,
),
sa.ForeignKeyConstraint(
["bytecode_storage_id"],
["bytecode_storage.id"],
name=op.f("fk_game7_contracts_bytecode_storage_id_bytecode_storage"),
),
sa.PrimaryKeyConstraint("address", name=op.f("pk_game7_contracts")),
)
op.create_index(
op.f("ix_game7_contracts_deployed_bytecode_hash"),
"game7_contracts",
["deployed_bytecode_hash"],
unique=False,
)
op.create_index(
op.f("ix_game7_contracts_name"), "game7_contracts", ["name"], unique=False
)
op.create_index(
op.f("ix_game7_contracts_transaction_hash"),
"game7_contracts",
["transaction_hash"],
unique=False,
)
op.create_table(
"game7_orbit_arbitrum_sepolia_contracts",
sa.Column("address", sa.LargeBinary(length=20), nullable=False),
@ -993,6 +1046,14 @@ def downgrade() -> None:
table_name="game7_orbit_arbitrum_sepolia_contracts",
)
op.drop_table("game7_orbit_arbitrum_sepolia_contracts")
op.drop_index(
op.f("ix_game7_contracts_transaction_hash"), table_name="game7_contracts"
)
op.drop_index(op.f("ix_game7_contracts_name"), table_name="game7_contracts")
op.drop_index(
op.f("ix_game7_contracts_deployed_bytecode_hash"), table_name="game7_contracts"
)
op.drop_table("game7_contracts")
op.drop_index(
op.f("ix_ethereum_contracts_transaction_hash"), table_name="ethereum_contracts"
)

Wyświetl plik

@ -0,0 +1,57 @@
"""Add Game7 mainnet indexes
Revision ID: c1bc596631f9
Revises: 6807bdf6f417
Create Date: 2024-10-14 16:10:27.757094
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'c1bc596631f9'
down_revision: Union[str, None] = '6807bdf6f417'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('game7_blocks',
sa.Column('l1_block_number', sa.BigInteger(), nullable=False),
sa.Column('block_number', sa.BigInteger(), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('block_timestamp', sa.BigInteger(), nullable=False),
sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('row_id', sa.BigInteger(), nullable=False),
sa.Column('path', sa.Text(), nullable=False),
sa.Column('transactions_indexed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('logs_indexed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.PrimaryKeyConstraint('block_number', name=op.f('pk_game7_blocks'))
)
op.create_index(op.f('ix_game7_blocks_block_number'), 'game7_blocks', ['block_number'], unique=False)
op.create_index(op.f('ix_game7_blocks_block_timestamp'), 'game7_blocks', ['block_timestamp'], unique=False)
op.create_table('game7_reorgs',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('block_number', sa.BigInteger(), nullable=False),
sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_game7_reorgs'))
)
op.create_index(op.f('ix_game7_reorgs_block_hash'), 'game7_reorgs', ['block_hash'], unique=False)
op.create_index(op.f('ix_game7_reorgs_block_number'), 'game7_reorgs', ['block_number'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_game7_reorgs_block_number'), table_name='game7_reorgs')
op.drop_index(op.f('ix_game7_reorgs_block_hash'), table_name='game7_reorgs')
op.drop_table('game7_reorgs')
op.drop_index(op.f('ix_game7_blocks_block_timestamp'), table_name='game7_blocks')
op.drop_index(op.f('ix_game7_blocks_block_number'), table_name='game7_blocks')
op.drop_table('game7_blocks')
# ### end Alembic commands ###

Wyświetl plik

@ -15,6 +15,7 @@ Example of label_data column record:
}
"""
import os
import uuid
from sqlalchemy import (
@ -56,6 +57,10 @@ Following:
3. https://stackoverflow.com/a/33532154/13659585
"""
MOONSTREAM_DB_V3_SCHEMA_NAME = os.environ.get(
"MOONSTREAM_DB_V3_SCHEMA_NAME", "blockchain"
)
class utcnow(expression.FunctionElement):
type = DateTime # type: ignore
@ -1289,6 +1294,51 @@ class ImxZkevmSepoliaLabel(EvmBasedLabel): # type: ignore
)
class Game7Label(EvmBasedLabel): # type: ignore
__tablename__ = "game7_labels"
__table_args__ = (
Index(
"ix_game7_labels_addr_block_num",
"address",
"block_number",
unique=False,
),
Index(
"ix_game7_labels_addr_block_ts",
"address",
"block_timestamp",
unique=False,
),
Index(
"uk_game7_labels_tx_hash_tx_call",
"transaction_hash",
unique=True,
postgresql_where=text("label='seer' and label_type='tx_call'"),
),
Index(
"uk_game7_labels_tx_hash_log_idx_evt",
"transaction_hash",
"log_index",
unique=True,
postgresql_where=text("label='seer' and label_type='event'"),
),
Index(
"uk_game7_labels_tx_hash_tx_call_raw",
"transaction_hash",
unique=True,
postgresql_where=text("label='seer-raw' and label_type='tx_call'"),
),
Index(
"uk_game7_labels_tx_hash_log_idx_evt_raw",
"transaction_hash",
"log_index",
unique=True,
postgresql_where=text("label='seer-raw' and label_type='event'"),
),
)
class Game7TestnetLabel(EvmBasedLabel): # type: ignore
__tablename__ = "game7_testnet_labels"

Wyświetl plik

@ -806,6 +806,24 @@ class ImxZkevmSepoliaContracts(evmBasedContracts):
### Game7 Testnet
# Game7
class Game7BlockIndex(EvmBasedBlocks):
__tablename__ = "game7_blocks"
l1_block_number = Column(BigInteger, nullable=False)
class Game7Reorgs(EvmBasedReorgs):
__tablename__ = "game7_reorgs"
class Game7Contracts(evmBasedContracts):
__tablename__ = "game7_contracts"
# Game7 Testnet
class Game7TestnetBlockIndex(EvmBasedBlocks):
@ -860,6 +878,7 @@ class Game7TestnetContracts(evmBasedContracts):
__tablename__ = "game7_testnet_contracts"
# B3
class B3BlockIndex(EvmBasedBlocks):
__tablename__ = "b3_blocks"