From 5d5242ed21f177539581d2a47a064faeaa346f04 Mon Sep 17 00:00:00 2001 From: Quentin Burg Date: Mon, 18 Dec 2023 16:26:36 +0100 Subject: [PATCH] :bug: discard operation if entrypoint is disabled --- src/crud.py | 5 +---- src/routes.py | 13 +++++++++++-- src/utils.py | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/crud.py b/src/crud.py index ebaa6b2..39869eb 100644 --- a/src/crud.py +++ b/src/crud.py @@ -94,9 +94,7 @@ def get_entrypoints( return contract.entrypoints -def get_entrypoint( - db: Session, contract_address_or_id: str, name: str -) -> Optional[models.Entrypoint]: +def get_entrypoint(db: Session, contract_address_or_id: str, name: str): """ Return a models.Entrypoint or raise EntrypointNotFound exception """ @@ -233,7 +231,6 @@ def get_credits_from_contract_address(db: Session, contract_address: str): ) if db_contract is None: raise ContractNotFound() - print(db_contract) db_credit = ( db.query(models.Credit) .filter(models.Credit.id == db_contract.credit_id) diff --git a/src/routes.py b/src/routes.py index 409a35d..af0e28c 100644 --- a/src/routes.py +++ b/src/routes.py @@ -10,6 +10,7 @@ ContractAlreadyRegistered, ContractNotFound, CreditNotFound, + EntrypointDisabled, EntrypointNotFound, UserNotFound, OperationNotFound, @@ -292,13 +293,21 @@ async def post_operation( entrypoint_name = operation["parameters"]["entrypoint"] try: - crud.get_entrypoint(db, str(contract.address), entrypoint_name) + entrypoint = crud.get_entrypoint(db, str(contract.address), entrypoint_name) + if not entrypoint.is_enabled: + raise EntrypointDisabled() except EntrypointNotFound: logging.warning(f"Entrypoint {entrypoint_name} is not found") raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail=f"Entrypoint {entrypoint_name} is not found", ) + except EntrypointDisabled: + logging.warning(f"Entrypoint {entrypoint_name} is disabled.") + raise HTTPException( + status_code=status.HTTP_403_FORBIDDEN, + detail=f"Entrypoint {entrypoint_name} is disabled.", + ) try: # Simulate the operation alone without sending it @@ -307,7 +316,7 @@ async def post_operation( logging.debug(f"Result of operation simulation : {op}") op_estimated_fees = [(int(x["fee"]), x["destination"]) for x in op.contents] estimated_fees = tezos.group_fees(op_estimated_fees) - logging.debug(f"Estimated fees for {op.hash()}: {estimated_fees}") + logging.debug(f"Estimated fees: {estimated_fees}") if not tezos.check_credits(db, estimated_fees): logging.warning(f"Not enough funds to pay estimated fees.") raise HTTPException( diff --git a/src/utils.py b/src/utils.py index 97932d6..ce846f4 100644 --- a/src/utils.py +++ b/src/utils.py @@ -11,6 +11,10 @@ class EntrypointNotFound(Exception): pass +class EntrypointDisabled(Exception): + pass + + class CreditNotFound(Exception): pass