Update db module.

pull/1057/head
Andrey 2024-04-16 00:04:05 +03:00
rodzic 41787fafaa
commit 911f7e7ebe
5 zmienionych plików z 149 dodań i 1 usunięć

Wyświetl plik

@ -32,6 +32,9 @@ from .models import (
PolygonBlock,
PolygonLabel,
PolygonTransaction,
ProofOfPlayApexBlock,
ProofOfPlayApexLabel,
ProofOfPlayApexTransaction,
WyrmBlock,
WyrmLabel,
WyrmTransaction,
@ -74,6 +77,7 @@ class AvailableBlockchainType(Enum):
AVALANCHE_FUJI = "avalanche_fuji"
BLAST = "blast"
BLAST_SEPOLIA = "blast_sepolia"
PROOF_OF_PLAY_APEX = "proof_of_play_apex"
def get_block_model(
@ -97,6 +101,7 @@ def get_block_model(
AvalancheFujiBlock,
BlastBlock,
BlastSepoliaBlock,
ProofOfPlayApexBlock,
]
]:
"""
@ -121,6 +126,7 @@ def get_block_model(
AvalancheFujiBlock,
BlastBlock,
BlastSepoliaBlock,
ProofOfPlayApexBlock,
]
]
if blockchain_type == AvailableBlockchainType.ETHEREUM:
@ -157,6 +163,8 @@ def get_block_model(
block_model = BlastBlock
elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA:
block_model = BlastSepoliaBlock
elif blockchain_type == AvailableBlockchainType.PROOF_OF_PLAY_APEX:
block_model = ProofOfPlayApexBlock
else:
raise Exception("Unsupported blockchain type provided")
@ -184,6 +192,7 @@ def get_label_model(
AvalancheFujiLabel,
BlastLabel,
BlastSepoliaLabel,
ProofOfPlayApexLabel,
]
]:
"""
@ -208,6 +217,7 @@ def get_label_model(
AvalancheFujiLabel,
BlastLabel,
BlastSepoliaLabel,
ProofOfPlayApexLabel,
]
]
if blockchain_type == AvailableBlockchainType.ETHEREUM:
@ -244,6 +254,8 @@ def get_label_model(
label_model = BlastLabel
elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA:
label_model = BlastSepoliaLabel
elif blockchain_type == AvailableBlockchainType.PROOF_OF_PLAY_APEX:
label_model = ProofOfPlayApexLabel
else:
raise Exception("Unsupported blockchain type provided")
@ -271,6 +283,7 @@ def get_transaction_model(
AvalancheFujiTransaction,
BlastTransaction,
BlastSepoliaTransaction,
ProofOfPlayApexTransaction,
]
]:
"""
@ -295,6 +308,7 @@ def get_transaction_model(
AvalancheFujiTransaction,
BlastTransaction,
BlastSepoliaTransaction,
ProofOfPlayApexTransaction,
]
]
if blockchain_type == AvailableBlockchainType.ETHEREUM:
@ -331,6 +345,8 @@ def get_transaction_model(
transaction_model = BlastTransaction
elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA:
transaction_model = BlastSepoliaTransaction
elif blockchain_type == AvailableBlockchainType.PROOF_OF_PLAY_APEX:
transaction_model = ProofOfPlayApexTransaction
else:
raise Exception("Unsupported blockchain type provided")

Wyświetl plik

@ -1936,6 +1936,120 @@ class BlastSepoliaLabel(Base): # type: ignore
)
class ProofOfPlayApexBlock(Base): # type: ignore
__tablename__ = "proof_of_play_apex_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
)
sha3_uncles = Column(VARCHAR(256), nullable=True)
l1_block_number = Column(BigInteger, nullable=True)
send_count = Column(BigInteger, nullable=True)
send_root = Column(VARCHAR(256), nullable=True)
mix_hash = Column(VARCHAR(256), nullable=True)
class ProofOfPlayApexTransaction(Base): # type: ignore
__tablename__ = "proof_of_play_apex_transactions"
hash = Column(
VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True
)
block_number = Column(
BigInteger,
ForeignKey("proof_of_play_apex_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
)
y_parity = Column(BigInteger, nullable=True)
class ProofOfPlayApexLabel(Base): # type: ignore
__tablename__ = "proof_of_play_apex_labels"
__table_args__ = (
Index(
"ix_proof_of_play_apex_labels_address_block_number",
"address",
"block_number",
unique=False,
),
Index(
"ix_proof_of_play_apex_labels_address_block_timestamp",
"address",
"block_timestamp",
unique=False,
),
)
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
"""
Function signature from blockchain (Ethereum/Polygon) Signature Database.

Wyświetl plik

@ -34,6 +34,9 @@ from .models import (
PolygonBlock,
PolygonLabel,
PolygonTransaction,
ProofOfPlayApexBlock,
ProofOfPlayApexLabel,
ProofOfPlayApexTransaction,
WyrmBlock,
WyrmLabel,
WyrmTransaction,
@ -76,6 +79,7 @@ class Network(Enum):
avalanche_fuji = "avalanche_fuji"
blast = "blast"
blast_sepolia = "blast_sepolia"
proof_of_play_apex = "proof_of_play_apex"
tx_raw_types = Union[
@ -96,6 +100,7 @@ tx_raw_types = Union[
AvalancheFujiTransaction,
BlastTransaction,
BlastSepoliaTransaction,
ProofOfPlayApexTransaction,
]
MODELS: Dict[Network, Dict[str, Base]] = {
@ -184,6 +189,11 @@ MODELS: Dict[Network, Dict[str, Base]] = {
"labels": BlastSepoliaLabel,
"transactions": BlastSepoliaTransaction,
},
Network.proof_of_play_apex: {
"blocks": ProofOfPlayApexBlock,
"labels": ProofOfPlayApexLabel,
"transactions": ProofOfPlayApexTransaction,
},
}
@ -224,5 +234,7 @@ def blockchain_type_to_network_type(
return Network.blast
elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA:
return Network.blast_sepolia
elif blockchain_type == AvailableBlockchainType.PROOF_OF_PLAY_APEX:
return Network.proof_of_play_apex
else:
raise ValueError(f"Unknown blockchain type: {blockchain_type}")

Wyświetl plik

@ -21,6 +21,7 @@ class SubscriptionTypes(Enum):
AVALANCHE_FUJI_BLOCKCHAIN = "avalanche_fuji_smartcontract"
BLAST_BLOCKCHAIN = "blast_smartcontract"
BLAST_SEPOLIA_BLOCKCHAIN = "blast_sepolia_smartcontract"
PROOF_OF_PLAY_APEX_BLOCKCHAIN = "proof_of_play_apex_smartcontract"
def blockchain_type_to_subscription_type(
@ -60,6 +61,8 @@ def blockchain_type_to_subscription_type(
return SubscriptionTypes.BLAST_BLOCKCHAIN
elif blockchain_type == AvailableBlockchainType.BLAST_SEPOLIA:
return SubscriptionTypes.BLAST_SEPOLIA_BLOCKCHAIN
elif blockchain_type == AvailableBlockchainType.PROOF_OF_PLAY_APEX:
return SubscriptionTypes.PROOF_OF_PLAY_APEX_BLOCKCHAIN
else:
raise ValueError(f"Unknown blockchain type: {blockchain_type}")
@ -82,6 +85,7 @@ subscription_id_by_blockchain = {
"avalanche_fuji": "avalanche_fuji_smartcontract",
"blast": "blast_smartcontract",
"blast_sepolia": "blast_sepolia_smartcontract",
"proof_of_play_apex": "proof_of_play_apex_smartcontract",
}
blockchain_by_subscription_id = {
@ -102,6 +106,7 @@ blockchain_by_subscription_id = {
"avalanche_fuji_blockchain": "avalanche_fuji",
"blast_blockchain": "blast",
"blast_sepolia_blockchain": "blast_sepolia",
"proof_of_play_apex_blockchain": "proof_of_play_apex",
"ethereum_smartcontract": "ethereum",
"polygon_smartcontract": "polygon",
"mumbai_smartcontract": "mumbai",
@ -119,4 +124,5 @@ blockchain_by_subscription_id = {
"avalanche_fuji_smartcontract": "avalanche_fuji",
"blast_smartcontract": "blast",
"blast_sepolia_smartcontract": "blast_sepolia",
"proof_of_play_apex_smartcontract": "proof_of_play_apex",
}

Wyświetl plik

@ -2,4 +2,4 @@
Moonstream database version.
"""
MOONSTREAMDB_VERSION = "0.4.1"
MOONSTREAMDB_VERSION = "0.4.2"