From 547caa893f1686ce40411f5748e53b46c878f7b7 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Fri, 23 Jul 2021 00:09:01 +0200 Subject: [PATCH] Add validator to PaymentOperation --- stellar_model/model/horizon/operations.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/stellar_model/model/horizon/operations.py b/stellar_model/model/horizon/operations.py index fe4f855..1c3dd28 100644 --- a/stellar_model/model/horizon/operations.py +++ b/stellar_model/model/horizon/operations.py @@ -6,6 +6,7 @@ from pydantic import BaseModel from pydantic import Field +from pydantic import validator from stellar_model.model.horizon.asset import Asset from stellar_model.model.horizon.claimable_balance import Claimant @@ -156,6 +157,22 @@ class PaymentOperation(BaseOperation): to_muxed_id: Optional[int] amount: Decimal = Field(description="Amount sent.") + @validator("asset_code") + def asset_code_none_check(cls, v, values, **kwargs): + if values["asset_type"] == "native" and v is not None: + raise ValueError("If the asset_type is native, the asset_code should be None") + elif values["asset_type"] != "native" and v is None: + raise ValueError("If the asset_type is not native, the asset_code should not be None") + return v + + @validator("asset_issuer") + def asset_issuer_none_check(cls, v, values, **kwargs): + if values["asset_type"] == "native" and v is not None: + raise ValueError("If the asset_type is native, the asset_issuer should be None") + elif values["asset_type"] != "native" and v is None: + raise ValueError("If the asset_type is not native, the asset_issuer should not be None") + return v + class PathPaymentStrictReceiveOperation(BaseOperation): """