Skip to content

Commit

Permalink
🐛 discard operation if entrypoint is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Burg committed Dec 18, 2023
1 parent bb798b0 commit 5d5242e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions src/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ContractAlreadyRegistered,
ContractNotFound,
CreditNotFound,
EntrypointDisabled,
EntrypointNotFound,
UserNotFound,
OperationNotFound,
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class EntrypointNotFound(Exception):
pass


class EntrypointDisabled(Exception):
pass


class CreditNotFound(Exception):
pass

Expand Down

0 comments on commit 5d5242e

Please sign in to comment.