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

Add blocks hash to labels #935

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Event:
event_name: str
args: Dict[str, Any]
address: str
block_hash: str
block_number: int
block_timestamp: int
transaction_hash: str
Expand Down Expand Up @@ -131,6 +132,7 @@ def _crawl_events(
event_name=raw_event["event"],
args=raw_event["args"],
address=raw_event["address"],
block_hash=raw_event["blockHash"],
block_number=raw_event["blockNumber"],
block_timestamp=raw_event["blockTimestamp"],
transaction_hash=raw_event["transactionHash"],
Expand Down Expand Up @@ -178,6 +180,7 @@ def _autoscale_crawl_events(
event_name=raw_event["event"],
args=raw_event["args"],
address=raw_event["address"],
block_hash=raw_event["blockHash"],
block_number=raw_event["blockNumber"],
block_timestamp=raw_event["blockTimestamp"],
transaction_hash=raw_event["transactionHash"],
Expand Down
54 changes: 54 additions & 0 deletions moonstreamdb/alembic/versions/91451b16c5c8_add_block_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Add block_hash

Revision ID: 91451b16c5c8
Revises: 0f8ee1ebb45f
Create Date: 2023-10-16 14:39:31.687486

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '91451b16c5c8'
down_revision = '0f8ee1ebb45f'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('ethereum_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_ethereum_labels_block_hash'), 'ethereum_labels', ['block_hash'], unique=False)
op.add_column('mumbai_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_mumbai_labels_block_hash'), 'mumbai_labels', ['block_hash'], unique=False)
op.add_column('polygon_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_polygon_labels_block_hash'), 'polygon_labels', ['block_hash'], unique=False)
op.add_column('wyrm_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_wyrm_labels_block_hash'), 'wyrm_labels', ['block_hash'], unique=False)
op.add_column('xdai_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_xdai_labels_block_hash'), 'xdai_labels', ['block_hash'], unique=False)
op.add_column('zksync_era_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_zksync_era_labels_block_hash'), 'zksync_era_labels', ['block_hash'], unique=False)
op.add_column('zksync_era_testnet_labels', sa.Column('block_hash', sa.VARCHAR(length=256), nullable=True))
op.create_index(op.f('ix_zksync_era_testnet_labels_block_hash'), 'zksync_era_testnet_labels', ['block_hash'], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_zksync_era_testnet_labels_block_hash'), table_name='zksync_era_testnet_labels')
op.drop_column('zksync_era_testnet_labels', 'block_hash')
op.drop_index(op.f('ix_zksync_era_labels_block_hash'), table_name='zksync_era_labels')
op.drop_column('zksync_era_labels', 'block_hash')
op.drop_index(op.f('ix_xdai_labels_block_hash'), table_name='xdai_labels')
op.drop_column('xdai_labels', 'block_hash')
op.drop_index(op.f('ix_wyrm_labels_block_hash'), table_name='wyrm_labels')
op.drop_column('wyrm_labels', 'block_hash')
op.drop_index(op.f('ix_polygon_labels_block_hash'), table_name='polygon_labels')
op.drop_column('polygon_labels', 'block_hash')
op.drop_index(op.f('ix_mumbai_labels_block_hash'), table_name='mumbai_labels')
op.drop_column('mumbai_labels', 'block_hash')
op.drop_index(op.f('ix_ethereum_labels_block_hash'), table_name='ethereum_labels')
op.drop_column('ethereum_labels', 'block_hash')
# ### end Alembic commands ###
7 changes: 7 additions & 0 deletions moonstreamdb/moonstreamdb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class EthereumLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down Expand Up @@ -270,6 +271,7 @@ class PolygonLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down Expand Up @@ -376,6 +378,7 @@ class MumbaiLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down Expand Up @@ -486,6 +489,7 @@ class XDaiLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down Expand Up @@ -607,6 +611,7 @@ class WyrmLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down Expand Up @@ -738,6 +743,7 @@ class ZkSyncEraLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down Expand Up @@ -869,6 +875,7 @@ class ZkSyncEraTestnetLabel(Base): # type: ignore
index=True,
)
label_data = Column(JSONB, nullable=True)
block_hash = Column(VARCHAR(256), index=True)
block_timestamp = Column(BigInteger, index=True)
log_index = Column(Integer, nullable=True)
created_at = Column(
Expand Down
Loading