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

Add validator to PaymentOperation #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions stellar_model/model/horizon/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down