Skip to content

Commit e895296

Browse files
committed
Do webhook validation before handling
1 parent 30e6dc8 commit e895296

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/examples/cvat/recording-oracle/src/crons/process_exchange_oracle_webhooks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import logging
22

3+
from human_protocol_sdk.constants import Status as EscrowStatus
34
from sqlalchemy.orm import Session
45

56
import src.services.webhook as oracle_db_service
7+
from src.chain.escrow import validate_escrow
68
from src.chain.kvstore import get_exchange_oracle_url
79
from src.core.config import Config
810
from src.core.types import ExchangeOracleEventTypes, OracleWebhookTypes
@@ -35,12 +37,20 @@ def handle_exchange_oracle_event(webhook: Webhook, *, db_session: Session):
3537

3638
match webhook.event_type:
3739
case ExchangeOracleEventTypes.job_finished:
40+
validate_escrow(webhook.chain_id, webhook.escrow_address)
41+
3842
validate_results(
3943
escrow_address=webhook.escrow_address,
4044
chain_id=webhook.chain_id,
4145
db_session=db_session,
4246
)
4347
case ExchangeOracleEventTypes.escrow_cleaned:
48+
validate_escrow(
49+
webhook.chain_id,
50+
webhook.escrow_address,
51+
accepted_states=[EscrowStatus.Pending, EscrowStatus.Cancelled],
52+
)
53+
4454
clean_escrow(
4555
db_session, escrow_address=webhook.escrow_address, chain_id=webhook.chain_id
4656
)

packages/examples/cvat/recording-oracle/src/handlers/validation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ def validate_results(
214214
):
215215
logger = get_function_logger(module_logger_name)
216216

217-
escrow.validate_escrow(chain_id=chain_id, escrow_address=escrow_address)
218-
219217
manifest = parse_manifest(escrow.get_escrow_manifest(chain_id, escrow_address))
220218

221219
validator = _TaskValidator(

0 commit comments

Comments
 (0)