Skip to content

Commit

Permalink
define queries estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgroul committed Dec 15, 2023
1 parent cdd2f3a commit 232e581
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 11 deletions.
1 change: 0 additions & 1 deletion MODULE_NAME/__init__.py

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ TODO: Description
You can install the latest release via [`pip`](https://pypi.org/project/pip/):

```bash
pip install <PYPI_NAME>
pip install ape-subsquid
```

### via `setuptools`

You can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version:

```bash
git clone https://github.com/ApeWorX/<PYPI_NAME>.git
cd <PYPI_NAME>
git clone https://github.com/ApeWorX/ape-subsquid.git
cd ape-subsquid
python3 setup.py install
```

Expand Down
8 changes: 8 additions & 0 deletions ape_subsquid/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ape import plugins

from ape_subsquid.query import SubsquidQueryEngine


@plugins.register(plugins.QueryPlugin)
def query_engines():
yield SubsquidQueryEngine
File renamed without changes.
71 changes: 71 additions & 0 deletions ape_subsquid/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from typing import Iterator, Optional

from ape.api.query import (
AccountTransactionQuery,
BlockQuery,
BlockTransactionQuery,
ContractCreationQuery,
ContractEventQuery,
QueryAPI,
QueryType,
)
from ape.exceptions import QueryEngineError
from ape.utils import singledispatchmethod


class SubsquidQueryEngine(QueryAPI):
@singledispatchmethod
def estimate_query(self, query: QueryType) -> Optional[int]:
return None

@estimate_query.register
def estimate_block_query(self, query: BlockQuery) -> int:
router_ms = 400
query_ms = 300
return router_ms + query_ms

@estimate_query.register
def estimate_block_transaction_query(self, query: BlockTransactionQuery) -> int:
router_ms = 400
query_ms = 1500
return router_ms + query_ms

@estimate_query.register
def estimate_account_transaction_query(self, query: AccountTransactionQuery) -> int:
return 0

@estimate_query.register
def estimate_contract_creation_query(self, query: ContractCreationQuery) -> int:
return 0

@estimate_query.register
def estimate_contract_event_query(self, query: ContractEventQuery) -> int:
router_ms = 400
query_ms = 400 + (1 + query.stop_block - query.start_block) * 1.4
return router_ms + query_ms

@singledispatchmethod
def perform_query(self, query: QueryType) -> Iterator:
raise QueryEngineError(
f"{self.__class__.__name__} cannot handle {query.__class__.__name__} queries."
)

@perform_query.register
def perform_block_query(self, query: BlockQuery):
return None

@perform_query.register
def perform_block_transaction_query(self, query: BlockTransactionQuery):
return None

@perform_query.register
def perform_account_transaction_query(self, query: AccountTransactionQuery):
return None

@perform_query.register
def perform_contract_creation_query(self, query: ContractCreationQuery):
return None

@perform_query.register
def perform_contract_event_query(self, query: ContractEventQuery):
return None
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude = "build/"
plugins = ["pydantic.mypy"]

[tool.setuptools_scm]
write_to = "<MODULE_NAME>/version.py"
write_to = "ape_subsquid/version.py"

# NOTE: you have to use single-quoted strings in TOML for regular expressions.
# It's the equivalent of r-strings in Python. Multiline strings are treated as
Expand All @@ -25,7 +25,7 @@ addopts = """
--cov-report term
--cov-report html
--cov-report xml
--cov=<MODULE_NAME>
--cov=ape_subsquid
"""
python_files = "test_*.py"
testpaths = "tests"
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@


setup(
name="<PYPI_NAME>",
name="ape-subsquid",
use_scm_version=True,
setup_requires=["setuptools_scm"],
description="""<PYPI_NAME>: <SHORT_DESCRIPTION>""",
description="""ape-subsquid: <SHORT_DESCRIPTION>""",
long_description=long_description,
long_description_content_type="text/markdown",
author="ApeWorX Ltd.",
author_email="[email protected]",
url="https://github.com/ApeWorX/<REPO_NAME>",
include_package_data=True,
install_requires=[],
install_requires=["eth-ape>=0.6.27,<0.7"],
python_requires=">=3.8,<4",
extras_require=extras_require,
py_modules=["<MODULE_NAME>"],
py_modules=["ape_subsquid"],
license="Apache-2.0",
zip_safe=False,
keywords="ethereum",
packages=find_packages(exclude=["tests", "tests.*"]),
package_data={"<MODULE_NAME>": ["py.typed"]},
package_data={"ape_subsquid": ["py.typed"]},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand Down

0 comments on commit 232e581

Please sign in to comment.