Add requested changes.

Refactor contract check.
refactor-support-interface
Andrey 2023-07-24 15:55:54 +03:00
rodzic e76a779400
commit 0e1a54fda7
2 zmienionych plików z 11 dodań i 9 usunięć

Wyświetl plik

@ -94,7 +94,7 @@ class EntityCollectionNotFoundException(Exception):
"""
class AddressNotAreSmartContractException(Exception):
class AddressNotSmartContractException(Exception):
"""
Raised when address not are smart contract
"""
@ -801,10 +801,12 @@ def get_list_of_support_interfaces(
Returns list of interfaces supported by given address
"""
if not check_if_smartcontract(
_, _, is_contract = check_if_smart_contract(
blockchain_type=blockchain_type, address=address, user_token=user_token
)[2]:
raise AddressNotAreSmartContractException(f"Address not are smart contract")
)
if not is_contract:
raise AddressNotSmartContractException(f"Address not are smart contract")
web3_client = connect(blockchain_type, user_token=user_token)
@ -894,7 +896,7 @@ def get_list_of_support_interfaces(
return result
def check_if_smartcontract(
def check_if_smart_contract(
blockchain_type: AvailableBlockchainType,
address: str,
user_token: uuid.UUID,

Wyświetl plik

@ -14,12 +14,12 @@ from moonstreamdb.blockchain import AvailableBlockchainType
from web3 import Web3
from ..actions import (
AddressNotAreSmartContractException,
AddressNotSmartContractException,
validate_abi_json,
apply_moonworm_tasks,
get_entity_subscription_collection_id,
EntityCollectionNotFoundException,
check_if_smartcontract,
check_if_smart_contract,
get_list_of_support_interfaces,
)
from ..admin import subscription_types
@ -636,7 +636,7 @@ async def address_info(request: Request, address: str):
with ThreadPoolExecutor(max_workers=5) as executor:
futures.append(
executor.submit(
check_if_smartcontract,
check_if_smart_contract,
address=address,
blockchain_type=blockchain_type,
user_token=user_token,
@ -705,7 +705,7 @@ def get_contract_interfaces(
address=address,
user_token=user_token,
)
except AddressNotAreSmartContractException as e:
except AddressNotSmartContractException as e:
raise MoonstreamHTTPException(
status_code=409,
detail=str(e),