Sergei Sumarokov 2024-01-15 12:54:09 +03:00 zatwierdzone przez GitHub
commit f013798a7b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 205 dodań i 1 usunięć

Wyświetl plik

@ -46,6 +46,9 @@ from moonstreamdb.models import (
ZkSyncEraTestnetBlock,
ZkSyncEraTestnetLabel,
ZkSyncEraTestnetTransaction,
StarknetBlock,
StarknetTransaction,
StarknetLabel,
)
@ -72,6 +75,9 @@ def include_symbol(tablename, schema):
ZkSyncEraTestnetBlock.__tablename__,
ZkSyncEraTestnetLabel.__tablename__,
ZkSyncEraTestnetTransaction.__tablename__,
StarknetBlock.__tablename__,
StarknetTransaction.__tablename__,
StarknetLabel.__tablename__,
}

Wyświetl plik

@ -0,0 +1,85 @@
"""Starknet blocks, txs, labels
Revision ID: 6f8c4b9e3970
Revises: 0f8ee1ebb45f
Create Date: 2023-10-31 13:46:35.536476
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '6f8c4b9e3970'
down_revision = '0f8ee1ebb45f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('starknet_blocks',
sa.Column('block_number', sa.BigInteger(), nullable=False),
sa.Column('sequencer_address', sa.VARCHAR(length=256), nullable=True),
sa.Column('status', sa.VARCHAR(length=256), nullable=True),
sa.Column('hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=True),
sa.Column('new_root', sa.VARCHAR(length=256), nullable=True),
sa.Column('timestamp', sa.BigInteger(), nullable=False),
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_starknet_blocks'))
)
op.create_index(op.f('ix_starknet_blocks_block_number'), 'starknet_blocks', ['block_number'], unique=True)
op.create_index(op.f('ix_starknet_blocks_hash'), 'starknet_blocks', ['hash'], unique=False)
op.create_index(op.f('ix_starknet_blocks_timestamp'), 'starknet_blocks', ['timestamp'], unique=False)
op.create_table('starknet_labels',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('label', sa.VARCHAR(length=256), nullable=False),
sa.Column('block_number', sa.BigInteger(), nullable=True),
sa.Column('address', sa.VARCHAR(length=256), nullable=True),
sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=True),
sa.Column('label_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('block_timestamp', sa.BigInteger(), 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_starknet_labels')),
sa.UniqueConstraint('id', name=op.f('uq_starknet_labels_id'))
)
op.create_index(op.f('ix_starknet_labels_address'), 'starknet_labels', ['address'], unique=False)
op.create_index(op.f('ix_starknet_labels_block_number'), 'starknet_labels', ['block_number'], unique=False)
op.create_index(op.f('ix_starknet_labels_block_timestamp'), 'starknet_labels', ['block_timestamp'], unique=False)
op.create_index(op.f('ix_starknet_labels_label'), 'starknet_labels', ['label'], unique=False)
op.create_index(op.f('ix_starknet_labels_transaction_hash'), 'starknet_labels', ['transaction_hash'], unique=False)
op.create_table('starknet_transactions',
sa.Column('hash', sa.VARCHAR(length=256), nullable=False),
sa.Column('calldata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('address', sa.VARCHAR(length=256), nullable=False),
sa.Column('entry_point_selector', sa.VARCHAR(length=256), nullable=True),
sa.Column('max_fee', sa.Numeric(precision=78, scale=0), nullable=True),
sa.Column('nonce', sa.VARCHAR(length=256), nullable=True),
sa.Column('signature', sa.ARRAY(sa.Text()), nullable=True),
sa.Column('type', sa.VARCHAR(length=256), nullable=True),
sa.Column('version', sa.VARCHAR(length=256), nullable=True),
sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False),
sa.PrimaryKeyConstraint('hash', name=op.f('pk_starknet_transactions'))
)
op.create_index(op.f('ix_starknet_transactions_address'), 'starknet_transactions', ['address'], unique=False)
op.create_index(op.f('ix_starknet_transactions_hash'), 'starknet_transactions', ['hash'], unique=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_starknet_transactions_hash'), table_name='starknet_transactions')
op.drop_index(op.f('ix_starknet_transactions_address'), table_name='starknet_transactions')
op.drop_table('starknet_transactions')
op.drop_index(op.f('ix_starknet_labels_transaction_hash'), table_name='starknet_labels')
op.drop_index(op.f('ix_starknet_labels_label'), table_name='starknet_labels')
op.drop_index(op.f('ix_starknet_labels_block_timestamp'), table_name='starknet_labels')
op.drop_index(op.f('ix_starknet_labels_block_number'), table_name='starknet_labels')
op.drop_index(op.f('ix_starknet_labels_address'), table_name='starknet_labels')
op.drop_table('starknet_labels')
op.drop_index(op.f('ix_starknet_blocks_timestamp'), table_name='starknet_blocks')
op.drop_index(op.f('ix_starknet_blocks_hash'), table_name='starknet_blocks')
op.drop_index(op.f('ix_starknet_blocks_block_number'), table_name='starknet_blocks')
op.drop_table('starknet_blocks')
# ### end Alembic commands ###

Wyświetl plik

@ -23,6 +23,9 @@ from .models import (
ZkSyncEraBlock,
ZkSyncEraLabel,
ZkSyncEraTransaction,
StarknetBlock,
StarknetTransaction,
StarknetLabel,
)
@ -34,6 +37,7 @@ class AvailableBlockchainType(Enum):
WYRM = "wyrm"
ZKSYNC_ERA_TESTNET = "zksync_era_testnet"
ZKSYNC_ERA = "zksync_era"
STARKNET = "starknet"
def get_block_model(
@ -47,6 +51,7 @@ def get_block_model(
WyrmBlock,
ZkSyncEraTestnetBlock,
ZkSyncEraBlock,
StarknetBlock,
]
]:
"""
@ -62,6 +67,7 @@ def get_block_model(
WyrmBlock,
ZkSyncEraTestnetBlock,
ZkSyncEraBlock,
StarknetBlock,
]
]
if blockchain_type == AvailableBlockchainType.ETHEREUM:
@ -78,6 +84,8 @@ def get_block_model(
block_model = ZkSyncEraTestnetBlock
elif blockchain_type == AvailableBlockchainType.ZKSYNC_ERA:
block_model = ZkSyncEraBlock
elif blockchain_type == AvailableBlockchainType.STARKNET:
block_model = StarknetBlock
else:
raise Exception("Unsupported blockchain type provided")
@ -95,6 +103,7 @@ def get_label_model(
WyrmLabel,
ZkSyncEraTestnetLabel,
ZkSyncEraLabel,
StarknetLabel,
]
]:
"""
@ -110,6 +119,7 @@ def get_label_model(
WyrmLabel,
ZkSyncEraTestnetLabel,
ZkSyncEraLabel,
StarknetLabel,
]
]
if blockchain_type == AvailableBlockchainType.ETHEREUM:
@ -126,6 +136,8 @@ def get_label_model(
label_model = ZkSyncEraTestnetLabel
elif blockchain_type == AvailableBlockchainType.ZKSYNC_ERA:
label_model = ZkSyncEraLabel
elif blockchain_type == AvailableBlockchainType.STARKNET:
label_model = StarknetLabel
else:
raise Exception("Unsupported blockchain type provided")
@ -143,6 +155,7 @@ def get_transaction_model(
WyrmTransaction,
ZkSyncEraTestnetTransaction,
ZkSyncEraTransaction,
StarknetTransaction,
]
]:
"""
@ -158,6 +171,7 @@ def get_transaction_model(
WyrmTransaction,
ZkSyncEraTestnetTransaction,
ZkSyncEraTransaction,
StarknetTransaction,
]
]
if blockchain_type == AvailableBlockchainType.ETHEREUM:
@ -174,6 +188,8 @@ def get_transaction_model(
transaction_model = ZkSyncEraTestnetTransaction
elif blockchain_type == AvailableBlockchainType.ZKSYNC_ERA:
transaction_model = ZkSyncEraTransaction
elif blockchain_type == AvailableBlockchainType.STARKNET:
transaction_model = StarknetTransaction
else:
raise Exception("Unsupported blockchain type provided")

Wyświetl plik

@ -1,6 +1,7 @@
import uuid
from sqlalchemy import (
ARRAY,
VARCHAR,
BigInteger,
Column,
@ -923,3 +924,89 @@ class OpenSeaCrawlingState(Base): # type: ignore
)
total_count = Column(Integer, nullable=False)
class StarknetBlock(Base): # type: ignore
__tablename__ = "starknet_blocks"
block_number = Column(
BigInteger, primary_key=True, unique=True, nullable=False, index=True
)
sequencer_address = Column(VARCHAR(256))
status = Column(VARCHAR(256))
hash = Column(VARCHAR(256), index=True, nullable=False)
parent_hash = Column(VARCHAR(256))
new_root = Column(VARCHAR(256))
timestamp = Column(BigInteger, index=True, nullable=False)
indexed_at = Column(
DateTime(timezone=True), server_default=utcnow(), nullable=False
)
class StarknetTransaction(Base): # type: ignore
__tablename__ = "starknet_transactions"
hash = Column(
VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True
)
calldata = Column(JSONB, nullable=True)
address = Column(VARCHAR(256), index=True, nullable=False)
entry_point_selector = Column(VARCHAR(256))
max_fee = Column(Numeric(precision=78, scale=0), nullable=True)
nonce = Column(VARCHAR(256))
signature = Column(ARRAY(Text))
type = Column(VARCHAR(256))
version = Column(VARCHAR(256))
indexed_at = Column(
DateTime(timezone=True), server_default=utcnow(), nullable=False
)
class StarknetLabel(Base): # type: ignore
__tablename__ = "starknet_labels"
__table_args__ = (
Index(
"ix_polygon_labels_address_block_number",
"address",
"block_number",
unique=False,
),
Index(
"ix_polygon_labels_address_block_timestamp",
"address",
"block_timestamp",
unique=False,
),
)
id = Column(
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
unique=True,
nullable=False,
)
label = Column(VARCHAR(256), nullable=False, index=True)
block_number = Column(
BigInteger,
nullable=True,
index=True,
)
address = Column(
VARCHAR(256),
nullable=True,
index=True,
)
transaction_hash = Column(
VARCHAR(256),
nullable=True,
index=True,
)
label_data = Column(JSONB, nullable=True)
block_timestamp = Column(BigInteger, index=True)
created_at = Column(
DateTime(timezone=True), server_default=utcnow(), nullable=False
)

Wyświetl plik

@ -24,6 +24,9 @@ from .models import (
ZkSyncEraBlock,
ZkSyncEraLabel,
ZkSyncEraTransaction,
StarknetBlock,
StarknetTransaction,
StarknetLabel,
)
@ -35,6 +38,7 @@ class Network(Enum):
wyrm = "wyrm"
zksync_era_testnet = "zksync_era_testnet"
zksync_era = "zksync_era"
starknet = "starknet"
tx_raw_types = Union[
@ -45,6 +49,7 @@ tx_raw_types = Union[
XDaiTransaction,
ZkSyncEraTestnetTransaction,
ZkSyncEraTransaction,
StarknetTransaction,
]
MODELS: Dict[Network, Dict[str, Base]] = {
@ -83,4 +88,9 @@ MODELS: Dict[Network, Dict[str, Base]] = {
"labels": ZkSyncEraLabel,
"transactions": ZkSyncEraTransaction,
},
Network.starknet: {
"blocks": StarknetBlock,
"labels": StarknetLabel,
"transactions": StarknetTransaction,
},
}

Wyświetl plik

@ -2,4 +2,4 @@
Moonstream database version.
"""
MOONSTREAMDB_VERSION = "0.3.5"
MOONSTREAMDB_VERSION = "0.3.6"