diff --git a/moonstreamdb/alembic/env.py b/moonstreamdb/alembic/env.py index 2852bee7..6dbe9aa8 100644 --- a/moonstreamdb/alembic/env.py +++ b/moonstreamdb/alembic/env.py @@ -70,6 +70,12 @@ from moonstreamdb.models import ( ZkSyncEraTestnetLabel, ZkSyncEraTestnetTransaction, ZkSyncEraTransaction, + BlastBlock, + BlastLabel, + BlastTransaction, + BlastSepoliaBlock, + BlastSepoliaLabel, + BlastSepoliaTransaction, ) @@ -120,6 +126,12 @@ def include_symbol(tablename, schema): AvalancheFujiTransaction.__tablename__, AvalancheLabel.__tablename__, AvalancheTransaction.__tablename__, + BlastBlock.__tablename__, + BlastLabel.__tablename__, + BlastTransaction.__tablename__, + BlastSepoliaBlock.__tablename__, + BlastSepoliaLabel.__tablename__, + BlastSepoliaTransaction.__tablename__, } diff --git a/moonstreamdb/alembic/versions/181c5800cb1b_blast_blockchain.py b/moonstreamdb/alembic/versions/181c5800cb1b_blast_blockchain.py new file mode 100644 index 00000000..3e87b9a9 --- /dev/null +++ b/moonstreamdb/alembic/versions/181c5800cb1b_blast_blockchain.py @@ -0,0 +1,214 @@ +"""Blast blockchain + +Revision ID: 181c5800cb1b +Revises: 295ce155c811 +Create Date: 2024-04-10 09:49:54.778860 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '181c5800cb1b' +down_revision = '295ce155c811' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('blast_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('difficulty', sa.BigInteger(), nullable=True), + sa.Column('extra_data', sa.VARCHAR(length=128), nullable=True), + sa.Column('gas_limit', sa.BigInteger(), nullable=True), + sa.Column('gas_used', sa.BigInteger(), nullable=True), + sa.Column('base_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('logs_bloom', sa.VARCHAR(length=1024), nullable=True), + sa.Column('miner', sa.VARCHAR(length=256), nullable=True), + sa.Column('nonce', sa.VARCHAR(length=256), nullable=True), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('receipt_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('uncles', sa.VARCHAR(length=256), nullable=True), + sa.Column('size', sa.Integer(), nullable=True), + sa.Column('state_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('timestamp', sa.BigInteger(), nullable=True), + sa.Column('total_difficulty', sa.VARCHAR(length=256), nullable=True), + sa.Column('transactions_root', 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.Column('sha3_uncles', sa.VARCHAR(length=256), nullable=True), + sa.Column('withdrawals_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('mix_hash', sa.VARCHAR(length=256), nullable=True), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_blast_blocks')) + ) + op.create_index(op.f('ix_blast_blocks_block_number'), 'blast_blocks', ['block_number'], unique=True) + op.create_index(op.f('ix_blast_blocks_hash'), 'blast_blocks', ['hash'], unique=False) + op.create_index(op.f('ix_blast_blocks_timestamp'), 'blast_blocks', ['timestamp'], unique=False) + op.create_table('blast_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('log_index', sa.Integer(), 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_blast_labels')), + sa.UniqueConstraint('id', name=op.f('uq_blast_labels_id')) + ) + op.create_index(op.f('ix_blast_labels_address'), 'blast_labels', ['address'], unique=False) + op.create_index('ix_blast_labels_address_block_number', 'blast_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_blast_labels_address_block_timestamp', 'blast_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_blast_labels_block_number'), 'blast_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_blast_labels_block_timestamp'), 'blast_labels', ['block_timestamp'], unique=False) + op.create_index(op.f('ix_blast_labels_label'), 'blast_labels', ['label'], unique=False) + op.create_index(op.f('ix_blast_labels_transaction_hash'), 'blast_labels', ['transaction_hash'], unique=False) + op.create_table('blast_sepolia_blocks', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('difficulty', sa.BigInteger(), nullable=True), + sa.Column('extra_data', sa.VARCHAR(length=128), nullable=True), + sa.Column('gas_limit', sa.BigInteger(), nullable=True), + sa.Column('gas_used', sa.BigInteger(), nullable=True), + sa.Column('base_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('logs_bloom', sa.VARCHAR(length=1024), nullable=True), + sa.Column('miner', sa.VARCHAR(length=256), nullable=True), + sa.Column('nonce', sa.VARCHAR(length=256), nullable=True), + sa.Column('parent_hash', sa.VARCHAR(length=256), nullable=True), + sa.Column('receipt_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('uncles', sa.VARCHAR(length=256), nullable=True), + sa.Column('size', sa.Integer(), nullable=True), + sa.Column('state_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('timestamp', sa.BigInteger(), nullable=True), + sa.Column('total_difficulty', sa.VARCHAR(length=256), nullable=True), + sa.Column('transactions_root', 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.Column('sha3_uncles', sa.VARCHAR(length=256), nullable=True), + sa.Column('withdrawals_root', sa.VARCHAR(length=256), nullable=True), + sa.Column('mix_hash', sa.VARCHAR(length=256), nullable=True), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_blast_sepolia_blocks')) + ) + op.create_index(op.f('ix_blast_sepolia_blocks_block_number'), 'blast_sepolia_blocks', ['block_number'], unique=True) + op.create_index(op.f('ix_blast_sepolia_blocks_hash'), 'blast_sepolia_blocks', ['hash'], unique=False) + op.create_index(op.f('ix_blast_sepolia_blocks_timestamp'), 'blast_sepolia_blocks', ['timestamp'], unique=False) + op.create_table('blast_sepolia_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('log_index', sa.Integer(), 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_blast_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_blast_sepolia_labels_id')) + ) + op.create_index(op.f('ix_blast_sepolia_labels_address'), 'blast_sepolia_labels', ['address'], unique=False) + op.create_index('ix_blast_sepolia_labels_address_block_number', 'blast_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_blast_sepolia_labels_address_block_timestamp', 'blast_sepolia_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_block_number'), 'blast_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_block_timestamp'), 'blast_sepolia_labels', ['block_timestamp'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_label'), 'blast_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_blast_sepolia_labels_transaction_hash'), 'blast_sepolia_labels', ['transaction_hash'], unique=False) + op.create_table('blast_sepolia_transactions', + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('from_address', sa.VARCHAR(length=256), nullable=True), + sa.Column('to_address', sa.VARCHAR(length=256), nullable=True), + sa.Column('gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('gas_price', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('max_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('max_priority_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('input', sa.Text(), nullable=True), + sa.Column('nonce', sa.VARCHAR(length=256), nullable=True), + sa.Column('transaction_index', sa.BigInteger(), nullable=True), + sa.Column('transaction_type', sa.Integer(), nullable=True), + sa.Column('value', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.Column('y_parity', sa.BigInteger(), nullable=True), + sa.ForeignKeyConstraint(['block_number'], ['blast_sepolia_blocks.block_number'], name=op.f('fk_blast_sepolia_transactions_block_number_blast_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_blast_sepolia_transactions')) + ) + op.create_index(op.f('ix_blast_sepolia_transactions_block_number'), 'blast_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_blast_sepolia_transactions_from_address'), 'blast_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_blast_sepolia_transactions_gas'), 'blast_sepolia_transactions', ['gas'], unique=False) + op.create_index(op.f('ix_blast_sepolia_transactions_gas_price'), 'blast_sepolia_transactions', ['gas_price'], unique=False) + op.create_index(op.f('ix_blast_sepolia_transactions_hash'), 'blast_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_blast_sepolia_transactions_to_address'), 'blast_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_blast_sepolia_transactions_value'), 'blast_sepolia_transactions', ['value'], unique=False) + op.create_table('blast_transactions', + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('from_address', sa.VARCHAR(length=256), nullable=True), + sa.Column('to_address', sa.VARCHAR(length=256), nullable=True), + sa.Column('gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('gas_price', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('max_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('max_priority_fee_per_gas', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('input', sa.Text(), nullable=True), + sa.Column('nonce', sa.VARCHAR(length=256), nullable=True), + sa.Column('transaction_index', sa.BigInteger(), nullable=True), + sa.Column('transaction_type', sa.Integer(), nullable=True), + sa.Column('value', sa.Numeric(precision=78, scale=0), nullable=True), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.Column('y_parity', sa.BigInteger(), nullable=True), + sa.ForeignKeyConstraint(['block_number'], ['blast_blocks.block_number'], name=op.f('fk_blast_transactions_block_number_blast_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_blast_transactions')) + ) + op.create_index(op.f('ix_blast_transactions_block_number'), 'blast_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_blast_transactions_from_address'), 'blast_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_blast_transactions_gas'), 'blast_transactions', ['gas'], unique=False) + op.create_index(op.f('ix_blast_transactions_gas_price'), 'blast_transactions', ['gas_price'], unique=False) + op.create_index(op.f('ix_blast_transactions_hash'), 'blast_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_blast_transactions_to_address'), 'blast_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_blast_transactions_value'), 'blast_transactions', ['value'], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_blast_transactions_value'), table_name='blast_transactions') + op.drop_index(op.f('ix_blast_transactions_to_address'), table_name='blast_transactions') + op.drop_index(op.f('ix_blast_transactions_hash'), table_name='blast_transactions') + op.drop_index(op.f('ix_blast_transactions_gas_price'), table_name='blast_transactions') + op.drop_index(op.f('ix_blast_transactions_gas'), table_name='blast_transactions') + op.drop_index(op.f('ix_blast_transactions_from_address'), table_name='blast_transactions') + op.drop_index(op.f('ix_blast_transactions_block_number'), table_name='blast_transactions') + op.drop_table('blast_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_value'), table_name='blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_to_address'), table_name='blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_hash'), table_name='blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_gas_price'), table_name='blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_gas'), table_name='blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_from_address'), table_name='blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_transactions_block_number'), table_name='blast_sepolia_transactions') + op.drop_table('blast_sepolia_transactions') + op.drop_index(op.f('ix_blast_sepolia_labels_transaction_hash'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_label'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_block_timestamp'), table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_block_number'), table_name='blast_sepolia_labels') + op.drop_index('ix_blast_sepolia_labels_address_block_timestamp', table_name='blast_sepolia_labels') + op.drop_index('ix_blast_sepolia_labels_address_block_number', table_name='blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_labels_address'), table_name='blast_sepolia_labels') + op.drop_table('blast_sepolia_labels') + op.drop_index(op.f('ix_blast_sepolia_blocks_timestamp'), table_name='blast_sepolia_blocks') + op.drop_index(op.f('ix_blast_sepolia_blocks_hash'), table_name='blast_sepolia_blocks') + op.drop_index(op.f('ix_blast_sepolia_blocks_block_number'), table_name='blast_sepolia_blocks') + op.drop_table('blast_sepolia_blocks') + op.drop_index(op.f('ix_blast_labels_transaction_hash'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_label'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_block_timestamp'), table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_block_number'), table_name='blast_labels') + op.drop_index('ix_blast_labels_address_block_timestamp', table_name='blast_labels') + op.drop_index('ix_blast_labels_address_block_number', table_name='blast_labels') + op.drop_index(op.f('ix_blast_labels_address'), table_name='blast_labels') + op.drop_table('blast_labels') + op.drop_index(op.f('ix_blast_blocks_timestamp'), table_name='blast_blocks') + op.drop_index(op.f('ix_blast_blocks_hash'), table_name='blast_blocks') + op.drop_index(op.f('ix_blast_blocks_block_number'), table_name='blast_blocks') + op.drop_table('blast_blocks') + # ### end Alembic commands ### diff --git a/moonstreamdb/moonstreamdb/blockchain.py b/moonstreamdb/moonstreamdb/blockchain.py index d515e023..8b317961 100644 --- a/moonstreamdb/moonstreamdb/blockchain.py +++ b/moonstreamdb/moonstreamdb/blockchain.py @@ -14,6 +14,12 @@ from .models import ( AvalancheFujiTransaction, AvalancheLabel, AvalancheTransaction, + BlastBlock, + BlastLabel, + BlastSepoliaBlock, + BlastSepoliaLabel, + BlastSepoliaTransaction, + BlastTransaction, EthereumBlock, EthereumLabel, EthereumTransaction, @@ -62,6 +68,8 @@ class AvailableBlockchainType(Enum): XAI_SEPOLIA = "xai_sepolia" AVALANCHE = "avalanche" AVALANCHE_FUJI = "avalanche_fuji" + BLAST = "blast" + BLAST_SEPOLIA = "blast_sepolia" def get_block_model( @@ -82,6 +90,8 @@ def get_block_model( XaiSepoliaBlock, AvalancheBlock, AvalancheFujiBlock, + BlastBlock, + BlastSepoliaBlock, ] ]: """ @@ -104,6 +114,8 @@ def get_block_model( XaiSepoliaBlock, AvalancheBlock, AvalancheFujiBlock, + BlastBlock, + BlastSepoliaBlock, ] ] if blockchain_type == AvailableBlockchainType.ETHEREUM: @@ -134,6 +146,10 @@ def get_block_model( block_model = AvalancheBlock elif blockchain_type == AvailableBlockchainType.AVALANCHE_FUJI: block_model = AvalancheFujiBlock + elif blockchain_type == AvailableBlockchainType.BLAST: + block_model = BlastBlock + elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA: + block_model = BlastSepoliaBlock else: raise Exception("Unsupported blockchain type provided") @@ -158,6 +174,8 @@ def get_label_model( XaiSepoliaLabel, AvalancheLabel, AvalancheFujiLabel, + BlastLabel, + BlastSepoliaLabel, ] ]: """ @@ -180,6 +198,8 @@ def get_label_model( XaiSepoliaLabel, AvalancheLabel, AvalancheFujiLabel, + BlastLabel, + BlastSepoliaLabel, ] ] if blockchain_type == AvailableBlockchainType.ETHEREUM: @@ -210,6 +230,10 @@ def get_label_model( label_model = AvalancheLabel elif blockchain_type == AvailableBlockchainType.AVALANCHE_FUJI: label_model = AvalancheFujiLabel + elif blockchain_type == AvailableBlockchainType.BLAST: + label_model = BlastLabel + elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA: + label_model = BlastSepoliaLabel else: raise Exception("Unsupported blockchain type provided") @@ -234,6 +258,8 @@ def get_transaction_model( XaiSepoliaTransaction, AvalancheTransaction, AvalancheFujiTransaction, + BlastTransaction, + BlastSepoliaTransaction, ] ]: """ @@ -256,6 +282,8 @@ def get_transaction_model( XaiSepoliaTransaction, AvalancheTransaction, AvalancheFujiTransaction, + BlastTransaction, + BlastSepoliaTransaction, ] ] if blockchain_type == AvailableBlockchainType.ETHEREUM: @@ -286,6 +314,10 @@ def get_transaction_model( transaction_model = AvalancheTransaction elif blockchain_type == AvailableBlockchainType.AVALANCHE_FUJI: transaction_model = AvalancheFujiTransaction + elif blockchain_type == AvailableBlockchainType.BLAST: + transaction_model = BlastTransaction + elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA: + transaction_model = BlastSepoliaTransaction else: raise Exception("Unsupported blockchain type provided") diff --git a/moonstreamdb/moonstreamdb/models.py b/moonstreamdb/moonstreamdb/models.py index 4d31a325..c5c3b8d9 100644 --- a/moonstreamdb/moonstreamdb/models.py +++ b/moonstreamdb/moonstreamdb/models.py @@ -1603,6 +1603,232 @@ class AvalancheFujiLabel(Base): # type: ignore ) +class BlastBlock(Base): # type: ignore + __tablename__ = "blast_blocks" + + block_number = Column( + BigInteger, primary_key=True, unique=True, nullable=False, index=True + ) + difficulty = Column(BigInteger) + extra_data = Column(VARCHAR(128)) + gas_limit = Column(BigInteger) + gas_used = Column(BigInteger) + base_fee_per_gas = Column(Numeric(precision=78, scale=0), nullable=True) + hash = Column(VARCHAR(256), index=True) + logs_bloom = Column(VARCHAR(1024)) + miner = Column(VARCHAR(256)) + nonce = Column(VARCHAR(256)) + parent_hash = Column(VARCHAR(256)) + receipt_root = Column(VARCHAR(256)) + uncles = Column(VARCHAR(256)) + size = Column(Integer) + state_root = Column(VARCHAR(256)) + timestamp = Column(BigInteger, index=True) + total_difficulty = Column(VARCHAR(256)) + transactions_root = Column(VARCHAR(256)) + + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + sha3_uncles = Column(VARCHAR(256), nullable=True) + withdrawals_root = Column(VARCHAR(256), nullable=True) + mix_hash = Column(VARCHAR(256), nullable=True) + + +class BlastTransaction(Base): # type: ignore + __tablename__ = "blast_transactions" + + hash = Column( + VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True + ) + block_number = Column( + BigInteger, + ForeignKey("blast_blocks.block_number", ondelete="CASCADE"), + nullable=False, + index=True, + ) + from_address = Column(VARCHAR(256), index=True) + to_address = Column(VARCHAR(256), index=True) + gas = Column(Numeric(precision=78, scale=0), index=True) + gas_price = Column(Numeric(precision=78, scale=0), index=True) + max_fee_per_gas = Column(Numeric(precision=78, scale=0), nullable=True) + max_priority_fee_per_gas = Column(Numeric(precision=78, scale=0), nullable=True) + input = Column(Text) + nonce = Column(VARCHAR(256)) + transaction_index = Column(BigInteger) + transaction_type = Column(Integer, nullable=True) + value = Column(Numeric(precision=78, scale=0), index=True) + + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + y_parity = Column(BigInteger, nullable=True) + + +class BlastLabel(Base): # type: ignore + __tablename__ = "blast_labels" + + __table_args__ = ( + Index( + "ix_blast_labels_address_block_number", + "address", + "block_number", + unique=False, + ), + Index( + "ix_blast_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) + log_index = Column(Integer, nullable=True) + created_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + +class BlastSepoliaBlock(Base): # type: ignore + __tablename__ = "blast_sepolia_blocks" + + block_number = Column( + BigInteger, primary_key=True, unique=True, nullable=False, index=True + ) + difficulty = Column(BigInteger) + extra_data = Column(VARCHAR(128)) + gas_limit = Column(BigInteger) + gas_used = Column(BigInteger) + base_fee_per_gas = Column(Numeric(precision=78, scale=0), nullable=True) + hash = Column(VARCHAR(256), index=True) + logs_bloom = Column(VARCHAR(1024)) + miner = Column(VARCHAR(256)) + nonce = Column(VARCHAR(256)) + parent_hash = Column(VARCHAR(256)) + receipt_root = Column(VARCHAR(256)) + uncles = Column(VARCHAR(256)) + size = Column(Integer) + state_root = Column(VARCHAR(256)) + timestamp = Column(BigInteger, index=True) + total_difficulty = Column(VARCHAR(256)) + transactions_root = Column(VARCHAR(256)) + + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + sha3_uncles = Column(VARCHAR(256), nullable=True) + withdrawals_root = Column(VARCHAR(256), nullable=True) + mix_hash = Column(VARCHAR(256), nullable=True) + + +class BlastSepoliaTransaction(Base): # type: ignore + __tablename__ = "blast_sepolia_transactions" + + hash = Column( + VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True + ) + block_number = Column( + BigInteger, + ForeignKey("blast_sepolia_blocks.block_number", ondelete="CASCADE"), + nullable=False, + index=True, + ) + from_address = Column(VARCHAR(256), index=True) + to_address = Column(VARCHAR(256), index=True) + gas = Column(Numeric(precision=78, scale=0), index=True) + gas_price = Column(Numeric(precision=78, scale=0), index=True) + max_fee_per_gas = Column(Numeric(precision=78, scale=0), nullable=True) + max_priority_fee_per_gas = Column(Numeric(precision=78, scale=0), nullable=True) + input = Column(Text) + nonce = Column(VARCHAR(256)) + transaction_index = Column(BigInteger) + transaction_type = Column(Integer, nullable=True) + value = Column(Numeric(precision=78, scale=0), index=True) + + indexed_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + y_parity = Column(BigInteger, nullable=True) + + +class BlastSepoliaLabel(Base): # type: ignore + __tablename__ = "blast_sepolia_labels" + + __table_args__ = ( + Index( + "ix_blast_sepolia_labels_address_block_number", + "address", + "block_number", + unique=False, + ), + Index( + "ix_blast_sepolia_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) + log_index = Column(Integer, nullable=True) + created_at = Column( + DateTime(timezone=True), server_default=utcnow(), nullable=False + ) + + class ESDFunctionSignature(Base): # type: ignore """ Function signature from blockchain (Ethereum/Polygon) Signature Database. diff --git a/moonstreamdb/moonstreamdb/networks.py b/moonstreamdb/moonstreamdb/networks.py index b1c0fb8c..a70e9a78 100644 --- a/moonstreamdb/moonstreamdb/networks.py +++ b/moonstreamdb/moonstreamdb/networks.py @@ -15,6 +15,12 @@ from .models import ( AvalancheLabel, AvalancheTransaction, Base, + BlastBlock, + BlastLabel, + BlastSepoliaBlock, + BlastSepoliaLabel, + BlastSepoliaTransaction, + BlastTransaction, EthereumBlock, EthereumLabel, EthereumTransaction, @@ -63,6 +69,8 @@ class Network(Enum): xai_sepolia = "xai_sepolia" avalanche = "avalanche" avalanche_fuji = "avalanche_fuji" + blast = "blast" + blast_sepolia = "blast_sepolia" tx_raw_types = Union[ @@ -80,6 +88,8 @@ tx_raw_types = Union[ XaiSepoliaTransaction, AvalancheTransaction, AvalancheFujiTransaction, + BlastTransaction, + BlastSepoliaTransaction, ] MODELS: Dict[Network, Dict[str, Base]] = { @@ -153,4 +163,14 @@ MODELS: Dict[Network, Dict[str, Base]] = { "labels": AvalancheFujiLabel, "transactions": AvalancheFujiTransaction, }, + Network.blast: { + "blocks": BlastBlock, + "labels": BlastLabel, + "transactions": BlastTransaction, + }, + Network.blast_sepolia: { + "blocks": BlastSepoliaBlock, + "labels": BlastSepoliaLabel, + "transactions": BlastSepoliaTransaction, + }, } diff --git a/moonstreamdb/moonstreamdb/version.py b/moonstreamdb/moonstreamdb/version.py index 377aaf31..f3fc1065 100644 --- a/moonstreamdb/moonstreamdb/version.py +++ b/moonstreamdb/moonstreamdb/version.py @@ -2,4 +2,4 @@ Moonstream database version. """ -MOONSTREAMDB_VERSION = "0.3.11" +MOONSTREAMDB_VERSION = "0.3.12"