kopia lustrzana https://github.com/bugout-dev/moonstream
Polygon models for blocks, txx, labels
rodzic
fd2eb08d78
commit
2371b7f597
|
@ -29,8 +29,12 @@ from moonstreamdb.models import (
|
||||||
EthereumBlock,
|
EthereumBlock,
|
||||||
EthereumTransaction,
|
EthereumTransaction,
|
||||||
EthereumLabel,
|
EthereumLabel,
|
||||||
ESDEventSignature,
|
PolygonBlock,
|
||||||
|
PolygonTransaction,
|
||||||
|
PolygonLabel,
|
||||||
ESDFunctionSignature,
|
ESDFunctionSignature,
|
||||||
|
ESDEventSignature,
|
||||||
|
OpenSeaCrawlingState,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +43,12 @@ def include_symbol(tablename, schema):
|
||||||
EthereumBlock.__tablename__,
|
EthereumBlock.__tablename__,
|
||||||
EthereumTransaction.__tablename__,
|
EthereumTransaction.__tablename__,
|
||||||
EthereumLabel.__tablename__,
|
EthereumLabel.__tablename__,
|
||||||
ESDEventSignature.__tablename__,
|
PolygonBlock.__tablename__,
|
||||||
|
PolygonTransaction.__tablename__,
|
||||||
|
PolygonLabel.__tablename__,
|
||||||
ESDFunctionSignature.__tablename__,
|
ESDFunctionSignature.__tablename__,
|
||||||
|
ESDEventSignature.__tablename__,
|
||||||
|
OpenSeaCrawlingState.__tablename__,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
"""Polygon models
|
||||||
|
|
||||||
|
Revision ID: f991fc7493c8
|
||||||
|
Revises: 3d55105b0603
|
||||||
|
Create Date: 2021-11-08 10:44:05.882650
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'f991fc7493c8'
|
||||||
|
down_revision = '3d55105b0603'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('polygon_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.PrimaryKeyConstraint('block_number', name=op.f('pk_polygon_blocks'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_blocks_block_number'), 'polygon_blocks', ['block_number'], unique=True)
|
||||||
|
op.create_index(op.f('ix_polygon_blocks_hash'), 'polygon_blocks', ['hash'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_blocks_timestamp'), 'polygon_blocks', ['timestamp'], unique=False)
|
||||||
|
op.create_table('polygon_labels',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), 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_polygon_labels')),
|
||||||
|
sa.UniqueConstraint('id', name=op.f('uq_polygon_labels_id'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_labels_address'), 'polygon_labels', ['address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_labels_block_number'), 'polygon_labels', ['block_number'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_labels_block_timestamp'), 'polygon_labels', ['block_timestamp'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_labels_label'), 'polygon_labels', ['label'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_labels_transaction_hash'), 'polygon_labels', ['transaction_hash'], unique=False)
|
||||||
|
op.create_table('polygon_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.ForeignKeyConstraint(['block_number'], ['polygon_blocks.block_number'], name=op.f('fk_polygon_transactions_block_number_polygon_blocks'), ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('hash', name=op.f('pk_polygon_transactions'))
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_block_number'), 'polygon_transactions', ['block_number'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_from_address'), 'polygon_transactions', ['from_address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_gas'), 'polygon_transactions', ['gas'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_gas_price'), 'polygon_transactions', ['gas_price'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_hash'), 'polygon_transactions', ['hash'], unique=True)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_to_address'), 'polygon_transactions', ['to_address'], unique=False)
|
||||||
|
op.create_index(op.f('ix_polygon_transactions_value'), 'polygon_transactions', ['value'], unique=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_value'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_to_address'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_hash'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_gas_price'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_gas'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_from_address'), table_name='polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_transactions_block_number'), table_name='polygon_transactions')
|
||||||
|
op.drop_table('polygon_transactions')
|
||||||
|
op.drop_index(op.f('ix_polygon_labels_transaction_hash'), table_name='polygon_labels')
|
||||||
|
op.drop_index(op.f('ix_polygon_labels_label'), table_name='polygon_labels')
|
||||||
|
op.drop_index(op.f('ix_polygon_labels_block_timestamp'), table_name='polygon_labels')
|
||||||
|
op.drop_index(op.f('ix_polygon_labels_block_number'), table_name='polygon_labels')
|
||||||
|
op.drop_index(op.f('ix_polygon_labels_address'), table_name='polygon_labels')
|
||||||
|
op.drop_table('polygon_labels')
|
||||||
|
op.drop_index(op.f('ix_polygon_blocks_timestamp'), table_name='polygon_blocks')
|
||||||
|
op.drop_index(op.f('ix_polygon_blocks_hash'), table_name='polygon_blocks')
|
||||||
|
op.drop_index(op.f('ix_polygon_blocks_block_number'), table_name='polygon_blocks')
|
||||||
|
op.drop_table('polygon_blocks')
|
||||||
|
# ### end Alembic commands ###
|
|
@ -155,9 +155,115 @@ class EthereumLabel(Base): # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonBlock(Base): # type: ignore
|
||||||
|
__tablename__ = "polygon_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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonTransaction(Base): # type: ignore
|
||||||
|
__tablename__ = "polygon_transactions"
|
||||||
|
|
||||||
|
hash = Column(
|
||||||
|
VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True
|
||||||
|
)
|
||||||
|
block_number = Column(
|
||||||
|
BigInteger,
|
||||||
|
ForeignKey("polygon_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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PolygonLabel(Base): # type: ignore
|
||||||
|
"""
|
||||||
|
Example of label_data:
|
||||||
|
{
|
||||||
|
"label": "ERC20",
|
||||||
|
"label_data": {
|
||||||
|
"name": "Uniswap",
|
||||||
|
"symbol": "UNI"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Exchange"
|
||||||
|
"label_data": {...}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
__tablename__ = "polygon_labels"
|
||||||
|
|
||||||
|
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
|
class ESDFunctionSignature(Base): # type: ignore
|
||||||
"""
|
"""
|
||||||
Function signature from Ethereum Signature Database.
|
Function signature from blockchain (Ethereum/Polygon) Signature Database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__tablename__ = "esd_function_signatures"
|
__tablename__ = "esd_function_signatures"
|
||||||
|
@ -172,7 +278,7 @@ class ESDFunctionSignature(Base): # type: ignore
|
||||||
|
|
||||||
class ESDEventSignature(Base): # type: ignore
|
class ESDEventSignature(Base): # type: ignore
|
||||||
"""
|
"""
|
||||||
Function signature from Ethereum Signature Database.
|
Function signature from blockchain (Ethereum/Polygon) Signature Database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__tablename__ = "esd_event_signatures"
|
__tablename__ = "esd_event_signatures"
|
||||||
|
|
Ładowanie…
Reference in New Issue