kopia lustrzana https://github.com/bugout-dev/moonstream
Working migration smart_contr -> address
rodzic
ce1d114e14
commit
55ac27689c
|
@ -14,7 +14,7 @@ from fastapi import (
|
|||
)
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from moonstreamdb.db import yield_db_session
|
||||
from moonstreamdb.models import EthereumSmartContract
|
||||
from moonstreamdb.models import EthereumAddress
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..abi_decoder import decode_abi
|
||||
|
@ -79,8 +79,8 @@ async def txinfo_ethereum_blockchain_handler(
|
|||
response.errors.append("Could not decode ABI from the given input")
|
||||
|
||||
smart_contract = (
|
||||
db_session.query(EthereumSmartContract)
|
||||
.filter(EthereumSmartContract.transaction_hash == txinfo_request.tx.hash)
|
||||
db_session.query(EthereumAddress)
|
||||
.filter(EthereumAddress.transaction_hash == txinfo_request.tx.hash)
|
||||
.one_or_none()
|
||||
)
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from .settings import MOONSTREAM_IPC_PATH, MOONSTREAM_CRAWL_WORKERS
|
|||
from moonstreamdb.db import yield_db_session_ctx
|
||||
from moonstreamdb.models import (
|
||||
EthereumBlock,
|
||||
EthereumSmartContract,
|
||||
EthereumAddress,
|
||||
EthereumTransaction,
|
||||
)
|
||||
|
||||
|
@ -227,7 +227,7 @@ def process_contract_deployments() -> List[Tuple[str, str]]:
|
|||
limit = 10
|
||||
transactions_remaining = True
|
||||
existing_contract_transaction_hashes = db_session.query(
|
||||
EthereumSmartContract.transaction_hash
|
||||
EthereumAddress.transaction_hash
|
||||
)
|
||||
|
||||
while transactions_remaining:
|
||||
|
@ -251,7 +251,7 @@ def process_contract_deployments() -> List[Tuple[str, str]]:
|
|||
if contract_address is not None:
|
||||
results.append((deployment.hash, contract_address))
|
||||
db_session.add(
|
||||
EthereumSmartContract(
|
||||
EthereumAddress(
|
||||
transaction_hash=deployment.hash,
|
||||
address=contract_address,
|
||||
)
|
||||
|
|
|
@ -17,22 +17,31 @@ fileConfig(config.config_file_name)
|
|||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
from moonstreamdb.models import Base as ExplorationBase
|
||||
from moonstreamdb.models import Base as MoonstreamBase
|
||||
|
||||
target_metadata = ExplorationBase.metadata
|
||||
target_metadata = MoonstreamBase.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
from moonstreamdb.models import EthereumBlock, EthereumTransaction, EthereumPendingTransaction, EthereumSmartContract, ESDEventSignature, ESDFunctionSignature
|
||||
from moonstreamdb.models import (
|
||||
EthereumBlock,
|
||||
EthereumTransaction,
|
||||
EthereumPendingTransaction,
|
||||
EthereumAddress,
|
||||
EthereumLabel,
|
||||
ESDEventSignature,
|
||||
ESDFunctionSignature,
|
||||
)
|
||||
|
||||
|
||||
def include_symbol(tablename, schema):
|
||||
return tablename in {
|
||||
EthereumBlock.__tablename__,
|
||||
EthereumTransaction.__tablename__,
|
||||
EthereumSmartContract.__tablename__,
|
||||
EthereumAddress.__tablename__,
|
||||
EthereumLabel.__tablename__,
|
||||
EthereumPendingTransaction.__tablename__,
|
||||
ESDEventSignature.__tablename__,
|
||||
ESDFunctionSignature.__tablename__,
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
"""Labels for addresses
|
||||
|
||||
Revision ID: 4d69885b673a
|
||||
Revises: 571f33ad7587
|
||||
Create Date: 2021-08-09 12:18:54.670225
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4d69885b673a'
|
||||
down_revision = '571f33ad7587'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index('ix_ethereum_smart_contracts_address', table_name='ethereum_smart_contracts')
|
||||
op.drop_index('ix_ethereum_smart_contracts_transaction_hash', table_name='ethereum_smart_contracts')
|
||||
|
||||
op.execute("ALTER TABLE ethereum_smart_contracts RENAME TO ethereum_addresses;")
|
||||
op.alter_column("ethereum_addresses", "transaction_hash", nullable=True)
|
||||
op.add_column('ethereum_addresses', sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False))
|
||||
|
||||
op.create_index(op.f('ix_ethereum_addresses_address'), 'ethereum_addresses', ['address'], unique=False)
|
||||
op.create_index(op.f('ix_ethereum_addresses_transaction_hash'), 'ethereum_addresses', ['transaction_hash'], unique=False)
|
||||
|
||||
op.create_table('ethereum_labels',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('label', sa.VARCHAR(length=256), nullable=False),
|
||||
sa.Column('address', sa.Integer(), nullable=False),
|
||||
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.ForeignKeyConstraint(['address'], ['ethereum_addresses.id'], name=op.f('fk_ethereum_labels_address_ethereum_addresses'), ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_ethereum_labels')),
|
||||
sa.UniqueConstraint('id', name=op.f('uq_ethereum_labels_id'))
|
||||
)
|
||||
op.create_index(op.f('ix_ethereum_labels_address'), 'ethereum_labels', ['address'], unique=False)
|
||||
op.create_index(op.f('ix_ethereum_labels_label'), 'ethereum_labels', ['label'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_ethereum_addresses_transaction_hash'), table_name='ethereum_addresses')
|
||||
op.drop_index(op.f('ix_ethereum_addresses_address'), table_name='ethereum_addresses')
|
||||
|
||||
op.execute("ALTER TABLE ethereum_addresses RENAME TO ethereum_smart_contracts;")
|
||||
op.alter_column("ethereum_smart_contracts", "transaction_hash", nullable=False)
|
||||
op.drop_column('ethereum_smart_contracts', 'created_at')
|
||||
|
||||
op.create_index('ix_ethereum_smart_contracts_transaction_hash', 'ethereum_smart_contracts', ['transaction_hash'], unique=False)
|
||||
op.create_index('ix_ethereum_smart_contracts_address', 'ethereum_smart_contracts', ['address'], unique=False)
|
||||
|
||||
op.drop_index(op.f('ix_ethereum_labels_label'), table_name='ethereum_labels')
|
||||
op.drop_index(op.f('ix_ethereum_labels_address'), table_name='ethereum_labels')
|
||||
op.drop_table('ethereum_labels')
|
||||
# ### end Alembic commands ###
|
|
@ -105,13 +105,7 @@ class EthereumTransaction(Base): # type: ignore
|
|||
class EthereumAddress(Base): # type: ignore
|
||||
__tablename__ = "ethereum_addresses"
|
||||
|
||||
id = Column(
|
||||
UUID(as_uuid=True),
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
unique=True,
|
||||
nullable=False,
|
||||
)
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
transaction_hash = Column(
|
||||
VARCHAR(256),
|
||||
ForeignKey("ethereum_transactions.hash", ondelete="CASCADE"),
|
||||
|
@ -126,18 +120,18 @@ class EthereumAddress(Base): # type: ignore
|
|||
|
||||
class EthereumLabel(Base): # type: ignore
|
||||
"""
|
||||
{
|
||||
label: ERC20,
|
||||
metadata: {
|
||||
name: 123,
|
||||
symbol: qwe
|
||||
Example of label_data:
|
||||
{
|
||||
"label": "ERC20",
|
||||
"metadata": {
|
||||
"name": "Uniswap",
|
||||
"symbol": "UNI"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Exchange"
|
||||
"metadata": {...}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
label: Exchange
|
||||
metadata: {}
|
||||
}
|
||||
"""
|
||||
|
||||
__tablename__ = "ethereum_labels"
|
||||
|
@ -156,7 +150,7 @@ class EthereumLabel(Base): # type: ignore
|
|||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
metadata = Column(JSONB, nullable=True)
|
||||
label_data = Column(JSONB, nullable=True)
|
||||
created_at = Column(
|
||||
DateTime(timezone=True), server_default=utcnow(), nullable=False
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue