Remove all EthereumAddresses usage from cli and some imports.

pull/313/head
Andrey Dolgolev 2021-10-20 17:16:46 +03:00
rodzic ef12313e22
commit 90cd175721
7 zmienionych plików z 12 dodań i 124 usunięć

Wyświetl plik

@ -8,7 +8,6 @@ import boto3 # type: ignore
from bugout.data import BugoutSearchResults
from bugout.journal import SearchOrder
from moonstreamdb.models import (
EthereumAddress,
EthereumLabel,
)
from sqlalchemy import text
@ -39,12 +38,6 @@ class StatusAPIException(Exception):
def get_contract_source_info(
db_session: Session, contract_address: str
) -> Optional[data.EthereumSmartContractSourceInfo]:
query = db_session.query(EthereumAddress.id).filter(
EthereumAddress.address == contract_address
)
id = query.one_or_none()
if id is None:
return None
labels = (
db_session.query(EthereumLabel)
.filter(EthereumLabel.address == contract_address)

Wyświetl plik

@ -8,7 +8,6 @@ from bugout.data import BugoutResource
from moonstreamdb.models import (
EthereumBlock,
EthereumTransaction,
EthereumAddress,
EthereumLabel,
)
from sqlalchemy import or_, and_, text

Wyświetl plik

@ -72,15 +72,15 @@ async def txinfo_ethereum_blockchain_handler(
response.errors.append("Could not decode ABI from the given input")
# transaction is contract deployment:
if txinfo_request.tx.to_address is None:
response.is_smart_contract_deployment = True
smart_contract = (
db_session.query(EthereumAddress)
.filter(EthereumAddress.transaction_hash == txinfo_request.tx.hash)
.one_or_none()
)
if smart_contract is not None:
response.is_smart_contract_deployment = True
# if txinfo_request.tx.to_address is None:
# response.is_smart_contract_deployment = True
# smart_contract = (
# db_session.query(EthereumAddress)
# .filter(EthereumAddress.transaction_hash == txinfo_request.tx.hash)
# .one_or_none()
# )
# if smart_contract is not None:
# response.is_smart_contract_deployment = True
else:
source_info = actions.get_contract_source_info(
db_session, txinfo_request.tx.to_address

Wyświetl plik

@ -17,7 +17,6 @@ from .ethereum import (
crawl_blocks_executor,
check_missing_blocks,
get_latest_blocks,
process_contract_deployments,
DateRange,
trending,
)
@ -191,12 +190,6 @@ def ethcrawler_blocks_missing_handler(args: argparse.Namespace) -> None:
)
def ethcrawler_contracts_update_handler(args: argparse.Namespace) -> None:
results = process_contract_deployments()
with args.outfile:
json.dump(results, args.outfile)
def ethcrawler_trending_handler(args: argparse.Namespace) -> None:
date_range = DateRange(
start_time=args.start,
@ -323,31 +316,6 @@ def main() -> None:
func=ethcrawler_blocks_missing_handler
)
parser_ethcrawler_contracts = subcommands.add_parser(
"contracts", description="Ethereum smart contract related crawlers"
)
parser_ethcrawler_contracts.set_defaults(
func=lambda _: parser_ethcrawler_contracts.print_help()
)
subcommands_ethcrawler_contracts = parser_ethcrawler_contracts.add_subparsers(
description="Ethereum contracts commands"
)
parser_ethcrawler_contracts_update = subcommands_ethcrawler_contracts.add_parser(
"update",
description="Update smart contract registry to include newly deployed smart contracts",
)
parser_ethcrawler_contracts_update.add_argument(
"-o",
"--outfile",
type=argparse.FileType("w"),
default=sys.stdout,
help="(Optional) File to write new (transaction_hash, contract_address) pairs to",
)
parser_ethcrawler_contracts_update.set_defaults(
func=ethcrawler_contracts_update_handler
)
parser_ethcrawler_trending = subcommands.add_parser(
"trending", description="Trending addresses on the Ethereum blockchain"
)

Wyświetl plik

@ -17,7 +17,6 @@ from .settings import MOONSTREAM_IPC_PATH, MOONSTREAM_CRAWL_WORKERS
from moonstreamdb.db import yield_db_session, yield_db_session_ctx
from moonstreamdb.models import (
EthereumBlock,
EthereumAddress,
EthereumTransaction,
)
@ -286,61 +285,6 @@ def crawl_blocks_executor(
raise EthereumBlockCrawlError(message)
def process_contract_deployments() -> List[Tuple[str, str]]:
"""
Checks for new smart contracts that have been deployed to the blockchain but not registered in
the smart contract registry.
If it finds any such smart contracts, it retrieves their addresses from the transaction receipts
and registers them in the smart contract registry.
Returns a list of pairs of the form [..., ("<transaction_hash>", "<contract_address>"), ...].
"""
web3_client = connect()
results: List[Tuple[str, str]] = []
with yield_db_session_ctx() as db_session:
current_offset = 0
limit = 10
transactions_remaining = True
existing_contract_transaction_hashes = db_session.query(
EthereumAddress.transaction_hash
)
while transactions_remaining:
contract_deployments = (
db_session.query(EthereumTransaction)
.order_by(desc(EthereumTransaction.block_number))
.filter(
EthereumTransaction.hash.notin_(
existing_contract_transaction_hashes
)
)
.filter(EthereumTransaction.to_address == None)
.limit(limit)
.offset(current_offset)
.all()
)
if contract_deployments:
for deployment in contract_deployments:
receipt = web3_client.eth.get_transaction_receipt(deployment.hash)
contract_address = receipt.get("contractAddress")
if contract_address is not None:
results.append((deployment.hash, contract_address))
db_session.add(
EthereumAddress(
transaction_hash=deployment.hash,
address=contract_address,
)
)
db_session.commit()
else:
transactions_remaining = False
current_offset += limit
return results
def trending(
date_range: DateRange, db_session: Optional[Session] = None
) -> Dict[str, Any]:

Wyświetl plik

@ -2,7 +2,7 @@ import argparse
import json
from .db import yield_db_session_ctx
from .models import EthereumAddress, EthereumLabel
from .models import EthereumLabel
def labels_add_handler(args: argparse.Namespace) -> None:
@ -41,9 +41,9 @@ def labels_list_handler(args: argparse.Namespace) -> None:
Return list of all labels.
"""
with yield_db_session_ctx() as db_session:
query = db_session.query(EthereumLabel).all()
query = db_session.query(EthereumLabel)
if str(args.address) is not None:
query = query.filter(EthereumAddress.address == str(args.address))
query = query.filter(EthereumLabel.address == str(args.address))
labels = query.all()
print(

Wyświetl plik

@ -103,22 +103,6 @@ class EthereumTransaction(Base): # type: ignore
)
class EthereumAddress(Base): # type: ignore
__tablename__ = "ethereum_addresses"
id = Column(Integer, primary_key=True, autoincrement=True)
transaction_hash = Column(
VARCHAR(256),
ForeignKey("ethereum_transactions.hash", ondelete="CASCADE"),
nullable=True,
index=True,
)
address = Column(VARCHAR(256), nullable=False, unique=True, index=True)
created_at = Column(
DateTime(timezone=True), server_default=utcnow(), nullable=False
)
class EthereumLabel(Base): # type: ignore
"""
Example of label_data: