fix: add validation to require 'to' field for TRANSFER transactions
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 2s
Integration Tests / test-service-integration (push) Successful in 59s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 3s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 9s
Security Scanning / security-scan (push) Successful in 17s

This commit is contained in:
aitbc
2026-04-28 13:18:11 +02:00
parent 285209006f
commit 0359a7c83f

View File

@@ -205,7 +205,7 @@ def _serialize_receipt(receipt: Receipt) -> Dict[str, Any]:
class TransactionRequest(BaseModel):
type: str = Field(description="Transaction type, e.g. TRANSFER, RECEIPT_CLAIM, GPU_MARKETPLACE, EXCHANGE, MESSAGE")
sender: str = Field(alias="from") # Accept both "sender" and "from"
to: str = Field(description="Recipient address")
to: Optional[str] = Field(default=None, description="Recipient address (required for TRANSFER)")
nonce: int
fee: int = Field(ge=0)
payload: Dict[str, Any]
@@ -222,6 +222,12 @@ class TransactionRequest(BaseModel):
self.type = normalized
return self
@model_validator(mode="after")
def validate_transfer_fields(self) -> "TransactionRequest": # type: ignore[override]
if self.type == "TRANSFER" and not self.to:
raise ValueError("transaction.to is required for TRANSFER transactions")
return self
class ReceiptSubmissionRequest(BaseModel):
sender: str