From e72ed407ea1a5491afbc753b86c825f342a8f56d Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Mon, 12 Jul 2021 15:43:44 +0300 Subject: [PATCH 1/3] Fix `add_contract` method --- src/dipdup/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dipdup/context.py b/src/dipdup/context.py index 73dfe862c..9060007a8 100644 --- a/src/dipdup/context.py +++ b/src/dipdup/context.py @@ -102,7 +102,7 @@ def add_contract(self, name: str, address: str, typename: Optional[str] = None) continue for handler_config in index_config.handlers: for pattern_config in handler_config.pattern: - if not isinstance(pattern_config, OperationHandlerOriginationPatternConfig): + if not isinstance(pattern_config, OperationHandlerOriginationPatternConfig) or not pattern_config.similar_to: continue if pattern_config.similar_to_contract_config.address == address: is_similar_to = True From 27ca7187d06d48ae4109783ef94d4dedf9669297 Mon Sep 17 00:00:00 2001 From: Michael Zaikin Date: Mon, 12 Jul 2021 17:13:44 +0300 Subject: [PATCH 2/3] Simple contract existence check --- src/dipdup/context.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/dipdup/context.py b/src/dipdup/context.py index 9060007a8..7add53b5a 100644 --- a/src/dipdup/context.py +++ b/src/dipdup/context.py @@ -93,23 +93,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) or not pattern_config.similar_to: - 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, From e336c07e4ffa8c325e83706013affa8da379aca5 Mon Sep 17 00:00:00 2001 From: Michael Zaikin Date: Mon, 12 Jul 2021 17:17:31 +0300 Subject: [PATCH 3/3] Remove unused imports --- src/dipdup/context.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/dipdup/context.py b/src/dipdup/context.py index 7add53b5a..81d15a720 100644 --- a/src/dipdup/context.py +++ b/src/dipdup/context.py @@ -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