From a046d33804ff3c10a267bd9ef7b8b54eb399e2eb Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Wed, 28 Jul 2021 20:58:56 -0700 Subject: [PATCH] Added EthereumSmartContract model to database --- .../b6842e6c720d_ethereum_smart_contracts.py | 52 +++++++++++++++++++ db/moonstreamdb/models.py | 12 +++-- db/mypy.ini | 10 ++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 db/alembic/versions/b6842e6c720d_ethereum_smart_contracts.py create mode 100644 db/mypy.ini diff --git a/db/alembic/versions/b6842e6c720d_ethereum_smart_contracts.py b/db/alembic/versions/b6842e6c720d_ethereum_smart_contracts.py new file mode 100644 index 00000000..d3d2cf0a --- /dev/null +++ b/db/alembic/versions/b6842e6c720d_ethereum_smart_contracts.py @@ -0,0 +1,52 @@ +"""ethereum_smart_contracts + +Revision ID: b6842e6c720d +Revises: 1e33c3d07306 +Create Date: 2021-07-28 20:57:07.739567 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "b6842e6c720d" +down_revision = "1e33c3d07306" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "ethereum_smart_contracts", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("transaction_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("address", sa.VARCHAR(length=256), nullable=False), + sa.ForeignKeyConstraint( + ["transaction_hash"], + ["ethereum_transactions.hash"], + name=op.f( + "fk_ethereum_smart_contracts_transaction_hash_ethereum_transactions" + ), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_ethereum_smart_contracts")), + ) + op.create_index( + op.f("ix_ethereum_smart_contracts_address"), + "ethereum_smart_contracts", + ["address"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + op.f("ix_ethereum_smart_contracts_address"), + table_name="ethereum_smart_contracts", + ) + op.drop_table("ethereum_smart_contracts") + # ### end Alembic commands ### diff --git a/db/moonstreamdb/models.py b/db/moonstreamdb/models.py index bd2c8873..6521c337 100644 --- a/db/moonstreamdb/models.py +++ b/db/moonstreamdb/models.py @@ -1,3 +1,4 @@ +import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import ( BigInteger, @@ -102,6 +103,12 @@ class EthereumTransaction(Base): # type: ignore DateTime(timezone=True), server_default=utcnow(), nullable=False ) +class EthereumSmartContract(Base): # type: ignore + __tablename__ = "ethereum_smart_contracts" + + id = Column(Integer, primary_key=True) + transaction_hash = Column(VARCHAR(256), ForeignKey("ethereum_transactions.hash", ondelete="CASCADE"), nullable=False) + address = Column(VARCHAR(256), nullable=False, index=True) class EthereumPendingTransaction(Base): # type: ignore __tablename__ = "ethereum_pending_transactions" @@ -130,8 +137,7 @@ class EthereumPendingTransaction(Base): # type: ignore DateTime(timezone=True), server_default=utcnow(), nullable=False ) - -class ESDFunctionSignature(Base): +class ESDFunctionSignature(Base): # type: ignore """ Function signature from Ethereum Signature Database. """ @@ -146,7 +152,7 @@ class ESDFunctionSignature(Base): ) -class ESDEventSignature(Base): +class ESDEventSignature(Base): # type: ignore """ Function signature from Ethereum Signature Database. """ diff --git a/db/mypy.ini b/db/mypy.ini new file mode 100644 index 00000000..47838c47 --- /dev/null +++ b/db/mypy.ini @@ -0,0 +1,10 @@ +[mypy] + +[mypy-sqlalchemy.*] +ignore_missing_imports = True + +[mypy-moonstreamdb.*] +ignore_missing_imports = True + +[mypy-pyevmasm.*] +ignore_missing_imports = True