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

🐛 discard operation if entrypoint is disabled #31

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
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
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
Loading