Skip to content

Commit

Permalink
deps: bump pydantic to v2 & fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Aug 27, 2023
1 parent c3d5779 commit c37cad7
Show file tree
Hide file tree
Showing 65 changed files with 804 additions and 471 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=============
stellar-model
=============
.. image:: https://img.shields.io/github/workflow/status/StellarCN/stellar-model/GitHub%20Action/main?style=flat&maxAge=1800
.. image:: https://img.shields.io/github/actions/workflow/status/StellarCN/stellar-model/continuous-integration-workflow.yml?branch=main&style=flat&maxAge=1800
:alt: GitHub Action
:target: https://github.com/StellarCN/stellar-model/actions

Expand Down Expand Up @@ -40,7 +40,7 @@ Example
url = "https://horizon.stellar.org/accounts/GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = requests.get(url).json()
parsed_resp = AccountResponse.parse_obj(raw_resp)
parsed_resp = AccountResponse.model_validate(raw_resp)
print(f"Account Sequence: {parsed_resp.sequence}")
Expand All @@ -54,7 +54,7 @@ Of course you can use it with `stellar-sdk`_.
server = Server("https://horizon.stellar.org")
account_id = "GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = server.accounts().account_id(account_id).call()
parsed_resp = AccountResponse.parse_obj(raw_resp)
parsed_resp = AccountResponse.model_validate(raw_resp)
print(f"Account Sequence: {parsed_resp.sequence}")
Expand Down
597 changes: 426 additions & 171 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ classifiers = [
]

[tool.poetry.dependencies]
python = ">=3.6.1"
pydantic = "^1.8.1"
python = ">=3.7"
pydantic = "^2.3.0"

[tool.poetry.dev-dependencies]
Sphinx = "^5.2.3"
Expand Down
46 changes: 29 additions & 17 deletions stellar_model/model/horizon/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,40 @@ class Balance(BaseModel):
)
liquidity_pool_id: Optional[str] = Field(
description="This liquidity pool’s id encoded in a "
"hex string representation."
"hex string representation.",
default=None,
)
limit: Optional[Decimal] = Field(
description="The maximum amount of this asset that this account "
"is willing to accept. Specified when opening a trustline."
"is willing to accept. Specified when opening a trustline.",
default=None,
)
buying_liabilities: Optional[Decimal] = Field(
description="The sum of all buy offers owned by this account " "for this asset."
description="The sum of all buy offers owned by this account for this asset.",
default=None,
)
selling_liabilities: Optional[Decimal] = Field(
description="The sum of all sell offers owned by this account "
"for this asset."
"for this asset.",
default=None,
)
sponsor: Optional[str] = Field(
description="The account ID of the sponsor who is paying "
"the reserves for this trustline."
"the reserves for this trustline.",
default=None,
)
last_modified_ledger: Optional[int]
is_authorized: Optional[bool]
is_authorized_to_maintain_liabilities: Optional[bool]
is_clawback_enabled: Optional[bool]
last_modified_ledger: Optional[int] = None
is_authorized: Optional[bool] = None
is_authorized_to_maintain_liabilities: Optional[bool] = None
is_clawback_enabled: Optional[bool] = None
asset_type: str = Field(
description="Either **native**, **credit_alphanum4**, or **credit_alphanum12**."
)
asset_code: Optional[str] = Field(description="The code for this asset.")
asset_code: Optional[str] = Field(
description="The code for this asset.", default=None
)
asset_issuer: Optional[str] = Field(
description="The Stellar address of this asset's issuer."
description="The Stellar address of this asset's issuer.", default=None
)


Expand Down Expand Up @@ -129,24 +136,28 @@ class Account(BaseModel):
"For use when submitting this account's next transaction."
)
sequence_ledger: Optional[int] = Field(
description="The unsigned 32-bit ledger " "number of the sequence number's age."
description="The unsigned 32-bit ledger "
"number of the sequence number's age.",
default=None,
)
sequence_time: Optional[datetime] = Field(
description="The time of the sequence number's age."
description="The time of the sequence number's age.", default=None
)
subentry_count: int = Field(description="The number of subentries on this account.")
inflation_destination: Optional[str] = Field(
description="The inflation destination set for this account."
description="The inflation destination set for this account.", default=None
)
home_domain: Optional[str] = Field(
description="The domain that hosts this account's stellar.toml file."
description="The domain that hosts this account's stellar.toml file.",
default=None,
)
last_modified_ledger: int = Field(
description="The ID of the last ledger that included changes to this account."
)
last_modified_time: Optional[datetime] = Field(
description="The time of the last ledger that included "
"changes to this account."
"changes to this account.",
default=None,
)
thresholds: AccountThresholds = Field(
description="Operations have varying levels of access. "
Expand All @@ -170,7 +181,8 @@ class Account(BaseModel):
)
sponsor: Optional[str] = Field(
description="The account ID of the sponsor who is paying the "
"reserves for this account."
"reserves for this account.",
default=None,
)
paging_token: str = Field(description="A cursor value for use in pagination.")
links: Links = Field(alias="_links")
2 changes: 1 addition & 1 deletion stellar_model/model/horizon/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class AccountData(BaseModel):

value: str = Field(description="The key value for this data.")
# TODO: add description
sponsor: Optional[str]
sponsor: Optional[str] = None
6 changes: 4 additions & 2 deletions stellar_model/model/horizon/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class Asset(BaseModel):
description="The type for this asset. Either **native**, "
"**credit_alphanum4**, or **credit_alphanum12**."
)
asset_code: Optional[str] = Field(description="The code for this asset.")
asset_code: Optional[str] = Field(
description="The code for this asset.", default=None
)
asset_issuer: Optional[str] = Field(
description="The Stellar address of this asset's issuer."
description="The Stellar address of this asset's issuer.", default=None
)
22 changes: 15 additions & 7 deletions stellar_model/model/horizon/claimable_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ClaimPredicate(BaseModel):
# TODO: add type in the future.
unconditional: Optional[bool] = Field(
description="If **True** it means this clause of the condition "
"is always satisfied."
"is always satisfied.",
default=None,
)
# https://pydantic-docs.helpmanual.io/usage/postponed_annotations/
and_predicates: Optional[List["ClaimPredicate"]] = Field(
Expand All @@ -37,6 +38,7 @@ class ClaimPredicate(BaseModel):
"condition is satisfied if both "
"of the two elements in the array "
"are satisfied.",
default=None,
)
or_predicates: Optional[List["ClaimPredicate"]] = Field(
alias="or",
Expand All @@ -46,26 +48,31 @@ class ClaimPredicate(BaseModel):
"condition is satisfied if at "
"least one of the two elements "
"in the array are satisfied.",
default=None,
)
not_predicate: Optional["ClaimPredicate"] = Field(
alias="not",
description="The value is also a predicate. This "
"clause of the condition is satisfied "
"if the value is not satisfied.",
default=None,
)
abs_before: Optional[datetime] = Field(
description="The datetime representing a deadline for when the claimable "
"balance can be claimed. If the balance is claimed before the "
"date then this clause of the condition is satisfied."
"date then this clause of the condition is satisfied.",
default=None,
)
abs_before_epoch: Optional[int] = Field(
"The Unix Epoch value represented by the same custom extended "
"ISO date value in the abs_before field."
description="The Unix Epoch value represented by the same custom extended "
"ISO date value in the abs_before field.",
default=None,
)
rel_before: Optional[int] = Field(
description="A relative deadline for when the claimable balance can be "
"claimed. The value represents the number of seconds since the "
"close time of the ledger which created the claimable balance."
"close time of the ledger which created the claimable balance.",
default=None,
)


Expand Down Expand Up @@ -100,13 +107,14 @@ class ClaimableBalance(BaseModel):
)
amount: Decimal = Field(description="The amount of **asset** that can be claimed.")
sponsor: Optional[str] = Field(
description="The account id of the sponsor who is paying the reserves for this claimable balance."
description="The account id of the sponsor who is paying the reserves for this claimable balance.",
default=None,
)
last_modified_ledger: int = Field(
description="The sequence number of the last ledger in which this claimable balance was modified."
)
last_modified_time: Optional[datetime] = Field(
description="The datetime of last modification time."
description="The datetime of last modification time.", default=None
)
claimants: List[Claimant] = Field(
description="The list of entries which could claim the claimable balance."
Expand Down
64 changes: 32 additions & 32 deletions stellar_model/model/horizon/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class BaseEffect(BaseModel):
id: str
paging_token: str
account: str
account_muxed: Optional[str]
account_muxed_id: Optional[int]
account_muxed: Optional[str] = None
account_muxed_id: Optional[int] = None
type: str
type_i: int
# The maximum year in Python is 9999
Expand Down Expand Up @@ -123,8 +123,8 @@ class AccountCreditedEffect(BaseEffect):
"""

asset_type: str
asset_code: Optional[str]
asset_issuer: Optional[str]
asset_code: Optional[str] = None
asset_issuer: Optional[str] = None
amount: Decimal


Expand All @@ -137,8 +137,8 @@ class AccountDebitedEffect(BaseEffect):
"""

asset_type: str
asset_code: Optional[str]
asset_issuer: Optional[str]
asset_code: Optional[str] = None
asset_issuer: Optional[str] = None
amount: Decimal


Expand Down Expand Up @@ -175,8 +175,8 @@ class AccountFlagsUpdatedEffect(BaseEffect):
type_i: 6
"""

auth_required_flag: Optional[bool]
auth_revokable_flag: Optional[bool]
auth_required_flag: Optional[bool] = None
auth_revokable_flag: Optional[bool] = None


class AccountInflationDestinationUpdatedEffect(BaseEffect):
Expand Down Expand Up @@ -238,9 +238,9 @@ class TrustlineCreatedEffect(BaseEffect):
"""

asset_type: str
asset_code: Optional[str]
asset_issuer: Optional[str]
liquidity_pool_id: Optional[str]
asset_code: Optional[str] = None
asset_issuer: Optional[str] = None
liquidity_pool_id: Optional[str] = None
limit: Decimal


Expand All @@ -253,9 +253,9 @@ class TrustlineRemovedEffect(BaseEffect):
"""

asset_type: str
asset_code: Optional[str]
asset_issuer: Optional[str]
liquidity_pool_id: Optional[str]
asset_code: Optional[str] = None
asset_issuer: Optional[str] = None
liquidity_pool_id: Optional[str] = None
limit: Decimal


Expand All @@ -268,9 +268,9 @@ class TrustlineUpdatedEffect(BaseEffect):
"""

asset_type: str
asset_code: Optional[str]
asset_issuer: Optional[str]
liquidity_pool_id: Optional[str]
asset_code: Optional[str] = None
asset_issuer: Optional[str] = None
liquidity_pool_id: Optional[str] = None
limit: Decimal


Expand Down Expand Up @@ -327,9 +327,9 @@ class TrustlineFlagsUpdatedEffect(BaseEffect):
asset_code: str
asset_issuer: str
trustor: str
authorized_flag: Optional[bool]
authorized_to_maintain_liabilites_flag: Optional[bool]
clawback_enabled_flag: Optional[bool]
authorized_flag: Optional[bool] = None
authorized_to_maintain_liabilites_flag: Optional[bool] = None
clawback_enabled_flag: Optional[bool] = None


class OfferCreatedEffect(BaseEffect):
Expand Down Expand Up @@ -368,17 +368,17 @@ class TradeEffect(BaseEffect):
"""

seller: str
seller_muxed: Optional[str]
seller_muxed_id: Optional[int]
seller_muxed: Optional[str] = None
seller_muxed_id: Optional[int] = None
offer_id: str
sold_amount: Decimal
sold_asset_type: str
sold_asset_code: Optional[str]
sold_asset_issuer: Optional[str]
sold_asset_code: Optional[str] = None
sold_asset_issuer: Optional[str] = None
bought_amount: Decimal
bought_asset_type: str
bought_asset_code: Optional[str]
bought_asset_issuer: Optional[str]
bought_asset_code: Optional[str] = None
bought_asset_issuer: Optional[str] = None


class DataCreatedEffect(BaseEffect):
Expand Down Expand Up @@ -510,8 +510,8 @@ class TrustlineSponsorshipCreatedEffect(BaseEffect):
"""

asset_type: str
asset: Optional[str]
liquidity_pool_id: Optional[str]
asset: Optional[str] = None
liquidity_pool_id: Optional[str] = None
sponsor: str


Expand All @@ -524,8 +524,8 @@ class TrustlineSponsorshipUpdatedEffect(BaseEffect):
"""

asset_type: str
asset: Optional[str]
liquidity_pool_id: Optional[str]
asset: Optional[str] = None
liquidity_pool_id: Optional[str] = None
former_sponsor: str
new_sponsor: str

Expand All @@ -539,8 +539,8 @@ class TrustlineSponsorshipRemovedEffect(BaseEffect):
"""

asset_type: str
asset: Optional[str]
liquidity_pool_id: Optional[str]
asset: Optional[str] = None
liquidity_pool_id: Optional[str] = None
former_sponsor: str


Expand Down
3 changes: 2 additions & 1 deletion stellar_model/model/horizon/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Ledger(BaseModel):
description="A hex-encoded SHA-256 hash of this ledger's XDR-encoded form."
)
prev_hash: Optional[str] = Field(
description="The hash of the ledger immediately preceding this ledger."
description="The hash of the ledger immediately preceding this ledger.",
default=None,
)
sequence: int = Field(
description="The sequence number of this ledger, and the parameter used in Horizon "
Expand Down
2 changes: 1 addition & 1 deletion stellar_model/model/horizon/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

class Link(BaseModel):
href: str
templated: Optional[bool]
templated: Optional[bool] = None
Loading

0 comments on commit c37cad7

Please sign in to comment.