Skip to content

Commit

Permalink
Dots in typename should indicate nested packages
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsereda committed Feb 4, 2024
1 parent a0a9d69 commit f3866af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/dipdup/codegen/evm_subsquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def jsonschema_from_abi(abi: dict[str, Any]) -> dict[str, Any]:
def convert_abi(package: DipDupPackage, events: set[str], functions: set[str]) -> None:
for abi_path in package.abi.glob('**/abi.json'):
abi = orjson.loads(abi_path.read_bytes())
abi_dirname = abi_path.relative_to(package.abi).parent
event_extras: defaultdict[str, EventAbiExtra] = defaultdict(EventAbiExtra) # type: ignore[arg-type]

for abi_item in abi:
Expand All @@ -66,7 +67,7 @@ def convert_abi(package: DipDupPackage, events: set[str], functions: set[str]) -
if name not in functions:
continue
schema = jsonschema_from_abi(abi_item)
schema_path = package.schemas / abi_path.parent.stem / 'evm_functions' / f'{abi_item["name"]}.json'
schema_path = package.schemas / abi_dirname / 'evm_functions' / f'{abi_item["name"]}.json'
elif abi_item['type'] == 'event':
name = abi_item['name']
if name in event_extras:
Expand All @@ -81,15 +82,15 @@ def convert_abi(package: DipDupPackage, events: set[str], functions: set[str]) -
continue

schema = jsonschema_from_abi(abi_item)
schema_path = package.schemas / abi_path.parent.stem / 'evm_events' / f'{abi_item["name"]}.json'
schema_path = package.schemas / abi_dirname / 'evm_events' / f'{abi_item["name"]}.json'
else:
continue

touch(schema_path)
schema_path.write_bytes(json_dumps(schema))

if event_extras:
event_extras_path = package.abi / abi_path.parent.stem / 'events.json'
event_extras_path = package.abi / abi_dirname / 'events.json'
touch(event_extras_path)
event_extras_path.write_bytes(json_dumps(event_extras))

Expand Down Expand Up @@ -139,7 +140,7 @@ async def _fetch_abi(self, index_config: SubsquidEventsIndexConfig) -> None:
datasource_configs = self._config.abi_datasources

for handler_config in index_config.handlers:
abi_path = self._package.abi / handler_config.contract.module_name / 'abi.json'
abi_path = self._package.abi / handler_config.contract.module_path / 'abi.json'
if abi_path.exists():
continue

Expand Down
6 changes: 5 additions & 1 deletion src/dipdup/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
from dipdup.utils import pascal_to_snake
from dipdup.yaml import DipDupYAMLConfig

from pathlib import Path
if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path

from dipdup.subscriptions import Subscription

Expand Down Expand Up @@ -242,6 +242,10 @@ class ContractConfig(ABC, NameMixin):
def module_name(self) -> str:
return self.typename or self.name

@property
def module_path(self) -> Path:
return Path(*self.module_name.split('.'))


class DatasourceConfig(ABC, NameMixin):
kind: str
Expand Down

0 comments on commit f3866af

Please sign in to comment.