Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add_contract method #90

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions src/dipdup/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
from tortoise import Tortoise
from tortoise.transactions import in_transaction

from dipdup.config import (
ContractConfig,
DipDupConfig,
OperationHandlerOriginationPatternConfig,
OperationIndexConfig,
PostgresDatabaseConfig,
StaticTemplateConfig,
)
from dipdup.config import ContractConfig, DipDupConfig, PostgresDatabaseConfig, StaticTemplateConfig
from dipdup.datasources import DatasourceT
from dipdup.exceptions import ContractAlreadyExistsError, IndexAlreadyExistsError
from dipdup.utils import FormattedLogger
Expand Down Expand Up @@ -93,23 +86,8 @@ def __init__(
self.datasource = datasource

def add_contract(self, name: str, address: str, typename: Optional[str] = None) -> None:
for contract_name, contract_config in self.config.contracts.items():
if name == contract_name or address == contract_config.address:
# NOTE: Origination pattern with `similar_to` field is a special case, safe to add duplicate
is_similar_to = False
for index_config in self.config.indexes.values():
if not isinstance(index_config, OperationIndexConfig):
continue
for handler_config in index_config.handlers:
for pattern_config in handler_config.pattern:
if not isinstance(pattern_config, OperationHandlerOriginationPatternConfig):
continue
if pattern_config.similar_to_contract_config.address == address:
is_similar_to = True

if not is_similar_to:
raise ContractAlreadyExistsError(self, name, address)

if name in self.config.contracts:
raise ContractAlreadyExistsError(self, name, address)
self.config.contracts[name] = ContractConfig(
address=address,
typename=typename,
Expand Down