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

feat: add support for Horizon v22.0.0. #62

Merged
merged 5 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on:
push:
pull_request:
release:
types: [created]
types: [ created ]

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ ubuntu-latest ]
python-version:
[
"3.8",
Expand All @@ -38,3 +38,21 @@ jobs:

- name: Test with unittest
run: python -m unittest

deploy:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
permissions:
id-token: write
steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Build Packages
run: poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: pre-commit/[email protected].0
python-version: '3.13'
- uses: pre-commit/[email protected].1
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Change Log

This document records all notable changes to `stellar-model <https://github.com/StellarCN/stellar-model/>`_.

0.6.0
----------------------------
* feat: add support for Horizon v22.0.0. (`#62 <https://github.com/StellarCN/stellar-model/pull/62/>`_)

0.5.4
----------------------------
* feat: add support for Horizon v2.27.0. (`#59 <https://github.com/StellarCN/stellar-model/pull/59/>`_)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please check the list `here <https://github.com/StellarCN/stellar-model/issues/2

.. code-block:: text

pip install stellar-model==0.5.4
pip install stellar-model==0.6.0

Example
=======
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "stellar-model"
version = "0.5.4"
version = "0.6.0"
description = "Parse the raw Stellar data into Python models."
authors = ["overcat <[email protected]>"]
readme = "README.rst"
Expand Down
2 changes: 1 addition & 1 deletion stellar_model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.4"
__version__ = "0.6.0"
__url__ = "https://github.com/StellarCN/stellar-model"
__issues__ = f"{__url__}/issues"

Expand Down
4 changes: 0 additions & 4 deletions stellar_model/model/horizon/asset_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ class AssetStat(BaseModel):
asset_issuer: str = Field(description="The Stellar address of this asset's issuer.")
paging_token: str = Field(description="A cursor value for use in pagination.")
contract_id: Optional[str] = Field(description="The contract ID of this asset.")
num_accounts: int = Field(
description="The numnber of accounts that have issued a trustline to this asset. If the **auth_required** flag for this asset's issuer is set to **true**, this number only includes the accounts who have both set up a trustline to the asset and have been authorized to hold the asset."
)
num_claimable_balances: int = Field(
description="The current number of claimable_balances for this asset."
)
num_liquidity_pools: int = Field(
description="The current number of liquidity_pools for this asset."
)
num_contracts: int
amount: Decimal = Field(description="The number of units issued for this asset.")
accounts: AssetStatAccounts = Field(
description="The number of accounts grouped by each trustline flag state."
)
Expand Down
13 changes: 13 additions & 0 deletions stellar_model/model/horizon/async_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Literal, Optional

from pydantic import BaseModel, Field


class AsyncTransaction(BaseModel):
"""
Represents an asynchronous transaction response.
"""

error_result_xdr: Optional[str] = Field(default=None)
tx_status: Literal["ERROR", "PENDING", "DUPLICATE", "TRY_AGAIN_LATER"]
hash: str
2 changes: 1 addition & 1 deletion stellar_model/model/horizon/claimable_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ class ClaimableBalance(BaseModel):
links: Links = Field(alias="_links")


ClaimPredicate.update_forward_refs()
ClaimPredicate.model_rebuild()
10 changes: 0 additions & 10 deletions stellar_model/model/horizon/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ class Transaction(BaseModel):
signatures: List[str] = Field(
description="An array of signatures used to sign this transaction."
)
valid_after: Optional[datetime] = Field(
description="The datetime after which a transaction is valid. This field is deprecated in lieu "
"of `preconditions.time_bounds.min_time` and will be removed in Horizon v3.",
default=None,
)
valid_before: Optional[datetime] = Field(
description="The datetime before which a transaction is valid. This field is deprecated in lieu "
"of `preconditions.time_bounds.max_time` and will be removed in Horizon v3.",
default=None,
)
preconditions: Optional[TransactionPreconditions] = Field(
description="A set of transaction preconditions affecting its validity.",
default=None,
Expand Down
14 changes: 14 additions & 0 deletions stellar_model/response/async_transaction_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from stellar_model.model.horizon.async_transaction import AsyncTransaction

__all__ = ["AsyncTransactionResponse"]


class AsyncTransactionResponse(AsyncTransaction):
"""Represents async transaction response.

Can be used for the following endpoint(s):

- POST /transactions_async

See `Submit a Transaction Asynchronously <https://developers.stellar.org/docs/data/horizon/api-reference/submit-async-transaction>`_ on Stellar API Reference.
"""
2 changes: 0 additions & 2 deletions tests/model/horizon/test_asset_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ def test_valid(self):
parsed_data.paging_token,
"ZX2_GDBSQA2GDRBRZVWOMRLZ6V4ZN2UESRQAEIHGKCZDR3YO4QIMC3CLHPR3_credit_alphanum4",
)
self.assertEqual(parsed_data.num_accounts, 1)
self.assertEqual(parsed_data.num_claimable_balances, 0)
self.assertEqual(parsed_data.num_liquidity_pools, 0)
self.assertEqual(parsed_data.amount, Decimal("1001"))
self.assertEqual(parsed_data.accounts.authorized, 1)
self.assertEqual(parsed_data.accounts.authorized_to_maintain_liabilities, 0)
self.assertEqual(parsed_data.accounts.unauthorized, 0)
Expand Down
30 changes: 30 additions & 0 deletions tests/model/horizon/test_async_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest

from stellar_model.model.horizon.async_transaction import AsyncTransaction
from tests.model.horizon import load_horizon_file


class TestAsyncTransaction(unittest.TestCase):
def test_pending(self):
raw_data = load_horizon_file("async_transaction_pending.json")
parsed_data = AsyncTransaction.model_validate(raw_data)
self.assertEqual(parsed_data.error_result_xdr, None)
self.assertEqual(parsed_data.tx_status, "PENDING")
self.assertEqual(
parsed_data.hash,
"7dfaa088db9a220568bb520649a52fe66de8ae4d18d7bf06c8c1544e85a29f60",
)

def test_error(self):
raw_data = load_horizon_file("async_transaction_error.json")
parsed_data = AsyncTransaction.model_validate(raw_data)
self.assertEqual(parsed_data.error_result_xdr, "AAAAAAAAAGT////9AAAAAA==")
self.assertEqual(parsed_data.tx_status, "ERROR")
self.assertEqual(
parsed_data.hash,
"267a9d1b5faac774c6f74ee059b28d63cb2f6880c0f75be90415cd392327af88",
)


if __name__ == "__main__":
unittest.main()
16 changes: 0 additions & 16 deletions tests/model/horizon/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ def test_transaction_valid(self):
parsed_data.signatures[0],
"zktIGIVFAq0VhE+k1pvBW68iFlJVENpqN/QrNhqomaBpcCUVpM5jJhzXVi7FQzUXOXVVPhQRsjbYG87/wfNSBA==",
)
self.assertEqual(
parsed_data.valid_after,
datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
)
self.assertEqual(
parsed_data.valid_before,
datetime.datetime(2022, 5, 6, 5, 29, 45, tzinfo=datetime.timezone.utc),
)
self.assertEqual(
parsed_data.preconditions.timebounds.min_time,
datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
Expand Down Expand Up @@ -150,14 +142,6 @@ def test_transaction_fee_bump_valid(self):
parsed_data.signatures[0],
"KbfbHT6jbk7gCOyyKZ+cyGQPnNoTAHy3lZgGqbrPkNWE8ekJSnicNScamUQYzngXkyd2ekTdmQxTaPkEHleTBQ==",
)
self.assertEqual(
parsed_data.valid_after,
datetime.datetime(2021, 4, 24, 1, 52, 57, tzinfo=datetime.timezone.utc),
)
self.assertEqual(
parsed_data.valid_before,
datetime.datetime(2021, 4, 24, 1, 57, 52, tzinfo=datetime.timezone.utc),
)
self.assertEqual(
parsed_data.fee_bump_transaction.hash,
"ac8cf91a1c0559091ba26573c0966191ae81466d5df4931af302f135d99c0d72",
Expand Down
2 changes: 0 additions & 2 deletions tests/resources/model/horizon/asset_stat.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
"asset_issuer": "GDBSQA2GDRBRZVWOMRLZ6V4ZN2UESRQAEIHGKCZDR3YO4QIMC3CLHPR3",
"paging_token": "ZX2_GDBSQA2GDRBRZVWOMRLZ6V4ZN2UESRQAEIHGKCZDR3YO4QIMC3CLHPR3_credit_alphanum4",
"contract_id": "CCCPUUUK5HZCTPW6RM2EY5IXGDEOML672CJ7VDCCSLSQLT2Z5R755QHD",
"num_accounts": 1,
"num_claimable_balances": 0,
"num_liquidity_pools": 0,
"num_contracts": 2,
"amount": "1001.0000000",
"accounts": {
"authorized": 1,
"authorized_to_maintain_liabilities": 0,
Expand Down
5 changes: 5 additions & 0 deletions tests/resources/model/horizon/async_transaction_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"error_result_xdr": "AAAAAAAAAGT////9AAAAAA==",
"tx_status": "ERROR",
"hash": "267a9d1b5faac774c6f74ee059b28d63cb2f6880c0f75be90415cd392327af88"
}
4 changes: 4 additions & 0 deletions tests/resources/model/horizon/async_transaction_pending.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tx_status": "PENDING",
"hash": "7dfaa088db9a220568bb520649a52fe66de8ae4d18d7bf06c8c1544e85a29f60"
}
2 changes: 0 additions & 2 deletions tests/resources/model/horizon/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
"signatures": [
"zktIGIVFAq0VhE+k1pvBW68iFlJVENpqN/QrNhqomaBpcCUVpM5jJhzXVi7FQzUXOXVVPhQRsjbYG87/wfNSBA=="
],
"valid_after": "1970-01-01T00:00:00Z",
"valid_before": "2022-05-06T05:29:45Z",
"preconditions": {
"timebounds": {
"min_time": "1970-01-01T00:00:00Z",
Expand Down
2 changes: 0 additions & 2 deletions tests/resources/model/horizon/transaction_fee_bump.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
"signatures": [
"KbfbHT6jbk7gCOyyKZ+cyGQPnNoTAHy3lZgGqbrPkNWE8ekJSnicNScamUQYzngXkyd2ekTdmQxTaPkEHleTBQ=="
],
"valid_after": "2021-04-24T01:52:57Z",
"valid_before": "2021-04-24T01:57:52Z",
"fee_bump_transaction": {
"hash": "ac8cf91a1c0559091ba26573c0966191ae81466d5df4931af302f135d99c0d72",
"signatures": [
Expand Down
Loading
Loading