kopia lustrzana https://github.com/bugout-dev/moonstream
commit
03eecd2e93
|
|
@ -59,13 +59,8 @@ def web3_client_from_cli_or_env(args: argparse.Namespace) -> Web3:
|
|||
return connect(web3_connection_string)
|
||||
|
||||
|
||||
def get_latest_block_from_db(db_session: Session):
|
||||
return (
|
||||
db_session.query(EthereumBlock)
|
||||
.order_by(EthereumBlock.timestamp.desc())
|
||||
.limit(1)
|
||||
.one()
|
||||
)
|
||||
def get_latest_block_from_node(web3_client: Web3):
|
||||
return web3_client.eth.block_number
|
||||
|
||||
|
||||
def get_latest_summary_block() -> Optional[int]:
|
||||
|
|
@ -94,32 +89,11 @@ def get_latest_summary_block() -> Optional[int]:
|
|||
return None
|
||||
|
||||
|
||||
# TODO(yhtiyar):
|
||||
# Labeling status should be stored in new tabel, and
|
||||
# latest label should be got from there
|
||||
def get_latest_nft_labeled_block(db_session: Session) -> Optional[int]:
|
||||
|
||||
query = (
|
||||
db_session.query(
|
||||
EthereumLabel.label,
|
||||
EthereumTransaction.hash,
|
||||
EthereumBlock.block_number,
|
||||
)
|
||||
.join(
|
||||
EthereumTransaction,
|
||||
EthereumLabel.transaction_hash == EthereumTransaction.hash,
|
||||
)
|
||||
.join(
|
||||
EthereumBlock,
|
||||
EthereumTransaction.block_number == EthereumBlock.block_number,
|
||||
)
|
||||
.filter(EthereumLabel.label.in_([MINT_LABEL, TRANSFER_LABEL]))
|
||||
.order_by(EthereumBlock.block_number.desc())
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
start_block = query.one_or_none()
|
||||
if start_block is not None:
|
||||
return start_block.block_number
|
||||
else:
|
||||
return None
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def sync_labels(db_session: Session, web3_client: Web3, start: Optional[int]) -> int:
|
||||
|
|
@ -141,15 +115,14 @@ def sync_labels(db_session: Session, web3_client: Web3, start: Optional[int]) ->
|
|||
.one()
|
||||
).block_number
|
||||
logger.info(f"Syncing labels, start block: {start}")
|
||||
latest_block = get_latest_block_from_db(db_session)
|
||||
end = latest_block.block_number
|
||||
end = get_latest_block_from_node(web3_client)
|
||||
if start > end:
|
||||
logger.warn(f"Start block {start} is greater than latest_block {end} in db")
|
||||
logger.warn("Maybe ethcrawler is not syncing or nft sync is up to date")
|
||||
return start - 1
|
||||
logger.info(f"Labeling blocks {start}-{end}")
|
||||
add_labels(web3_client, db_session, start, end)
|
||||
return latest_block.block_number
|
||||
return end
|
||||
|
||||
|
||||
def sync_summaries(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
"""Drop foreign key constraint on tx hash on ethereum_labels table
|
||||
|
||||
Revision ID: d6ed4b1b43d5
|
||||
Revises: 72f1ad512b2e
|
||||
Create Date: 2021-09-23 21:02:46.577682
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "d6ed4b1b43d5"
|
||||
down_revision = "72f1ad512b2e"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(
|
||||
"fk_ethereum_labels_transaction_hash_ethereum_transactions",
|
||||
"ethereum_labels",
|
||||
type_="foreignkey",
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_foreign_key(
|
||||
"fk_ethereum_labels_transaction_hash_ethereum_transactions",
|
||||
"ethereum_labels",
|
||||
"ethereum_transactions",
|
||||
["transaction_hash"],
|
||||
["hash"],
|
||||
ondelete="CASCADE",
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -152,7 +152,6 @@ class EthereumLabel(Base): # type: ignore
|
|||
)
|
||||
transaction_hash = Column(
|
||||
VARCHAR(256),
|
||||
ForeignKey("ethereum_transactions.hash", ondelete="CASCADE"),
|
||||
nullable=True,
|
||||
index=True,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
Moonstream database version.
|
||||
"""
|
||||
|
||||
MOONSTREAMDB_VERSION = "0.1.0"
|
||||
MOONSTREAMDB_VERSION = "0.1.1"
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue