generated from ApeWorX/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for all networks from archive
- Loading branch information
Showing
4 changed files
with
163 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from ape.exceptions import ApeException | ||
|
||
|
||
class ApeSubsquidError(ApeException): | ||
""" | ||
A base exception in the ape-subsquid plugin. | ||
""" | ||
|
||
|
||
class NotReadyToServeError(ApeSubsquidError): | ||
""" | ||
Raised when archive isn't ready to serve a specific block | ||
or a network isn't supported. | ||
""" | ||
|
||
|
||
class DataIsNotAvailable(ApeSubsquidError): | ||
""" | ||
Raised when a specific worker has no requested data. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from hexbytes import HexBytes | ||
|
||
from ape_subsquid.archive import BlockHeader, Log, Transaction | ||
|
||
|
||
def hex_to_int(value: str): | ||
return int(value, 16) | ||
|
||
|
||
def map_header(value: BlockHeader, transactions: list[Transaction]) -> dict: | ||
return { | ||
"number": value["number"], | ||
"hash": HexBytes(value["hash"]), | ||
"parentHash": HexBytes(value["parentHash"]), | ||
"baseFeePerGas": value["baseFeePerGas"] and hex_to_int(value["baseFeePerGas"]), | ||
"difficulty": hex_to_int(value["difficulty"]), | ||
"totalDifficulty": hex_to_int(value["totalDifficulty"]), | ||
"extraData": HexBytes(value["extraData"]), | ||
"gasLimit": hex_to_int(value["gasLimit"]), | ||
"gasUsed": hex_to_int(value["gasUsed"]), | ||
"logsBloom": HexBytes(value["logsBloom"]), | ||
"miner": value["miner"], | ||
"mixHash": HexBytes(value["mixHash"]), | ||
"nonce": HexBytes(value["nonce"]), | ||
"receiptsRoot": HexBytes(value["receiptsRoot"]), | ||
"sha3Uncles": HexBytes(value["sha3Uncles"]), | ||
"size": value["size"], | ||
"stateRoot": HexBytes(value["stateRoot"]), | ||
"timestamp": int(value["timestamp"]), | ||
"transactionsRoot": HexBytes(value["transactionsRoot"]), | ||
"transactions": transactions, | ||
} | ||
|
||
|
||
def map_receipt( | ||
value: Transaction, | ||
block_number: int, | ||
block_hash: HexBytes, | ||
logs: list[dict], | ||
) -> dict: | ||
return { | ||
"blockNumber": block_number, | ||
"blockHash": block_hash, | ||
"from": value["from"], | ||
"to": value["to"], | ||
"hash": HexBytes(value["hash"]), | ||
"status": value["status"], | ||
"chainId": value["chainId"], | ||
"contractAddress": value["contractAddress"], | ||
"cumulativeGasUsed": hex_to_int(value["cumulativeGasUsed"]), | ||
"effectiveGasPrice": hex_to_int(value["effectiveGasPrice"]), | ||
"gas": hex_to_int(value["gas"]), | ||
"gasPrice": hex_to_int(value["gasPrice"]), | ||
"gasUsed": hex_to_int(value["gasUsed"]), | ||
"input": HexBytes(value["input"]), | ||
"maxFeePerGas": value["maxFeePerGas"] and hex_to_int(value["maxFeePerGas"]), | ||
"maxPriorityFeePerGas": value["maxPriorityFeePerGas"] | ||
and hex_to_int(value["maxPriorityFeePerGas"]), | ||
"nonce": value["nonce"], | ||
"v": hex_to_int(value["v"]), | ||
"r": HexBytes(value["r"]), | ||
"s": HexBytes(value["s"]), | ||
"transactionIndex": value["transactionIndex"], | ||
"type": value["type"], | ||
"value": hex_to_int(value["value"]), | ||
"yParity": value["yParity"], | ||
"transactionHash": HexBytes(value["hash"]), | ||
"logs": logs, | ||
} | ||
|
||
|
||
def map_log(value: Log, block_number: int, block_hash: HexBytes) -> dict: | ||
return { | ||
"blockNumber": block_number, | ||
"blockHash": block_hash, | ||
"address": value["address"], | ||
"transactionIndex": value["transactionIndex"], | ||
"transactionHash": HexBytes(value["transactionHash"]), | ||
"logIndex": value["logIndex"], | ||
"data": HexBytes(value["data"]), | ||
"topics": [HexBytes(topic) for topic in value["topics"]], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters