Skip to content

Commit

Permalink
feat: Add missing nft_page, ledger_index and ledger_hash fields…
Browse files Browse the repository at this point in the history
… to requests (#604)

Add `ledger_hash` and `ledger_index` to `account_nfts`, `nft_buy_offers`, and `nft_sell_offers` requests.
Create `LookupByLedgerRequest` to clean up `ledger_hash` and `ledger_index` which are optional on most request objects.
Add `nft_page` to `ledger_entry` request.
  • Loading branch information
pdp2121 authored Jun 26, 2023
1 parent 8ca6050 commit 1d51463
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 97 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [[Unreleased]]
### Fixed:
- Added a sort of the account IDs in `multisign`, so that the `multisign` always works.
- Add `ledger_hash` and `ledger_index` to `account_nfts`, `nft_buy_offers`, and `nft_sell_offers` requests.
- Add `nft_page` to `ledger_entry` request.

## [1.9.0] - 2023-06-13
### Added:
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/account_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
`See account_channels <https://xrpl.org/account_channels.html>`_
"""
from dataclasses import dataclass, field
from typing import Any, Optional, Union
from typing import Any, Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountChannels(Request):
class AccountChannels(Request, LookupByLedgerRequest):
"""
This request returns information about an account's Payment Channels. This includes
only channels where the specified account is the channel's source, not the
Expand All @@ -41,5 +41,3 @@ class AccountChannels(Request):
# marker data shape is actually undefined in the spec, up to the
# implementation of an individual server
marker: Optional[Any] = None
ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
8 changes: 2 additions & 6 deletions xrpl/models/requests/account_currencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
`See account_currencies <https://xrpl.org/account_currencies.html>`_
"""
from dataclasses import dataclass, field
from typing import Optional, Union

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountCurrencies(Request):
class AccountCurrencies(Request, LookupByLedgerRequest):
"""
This request retrieves a list of currencies that an account can send or receive,
based on its trust lines.
Expand All @@ -34,8 +33,5 @@ class AccountCurrencies(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.ACCOUNT_CURRENCIES, init=False)
strict: bool = False
7 changes: 2 additions & 5 deletions xrpl/models/requests/account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
`See account_info <https://xrpl.org/account_info.html>`_
"""
from dataclasses import dataclass, field
from typing import Optional, Union

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountInfo(Request):
class AccountInfo(Request, LookupByLedgerRequest):
"""
This request retrieves information about an account, its activity, and its XRP
balance.
Expand All @@ -33,8 +32,6 @@ class AccountInfo(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.ACCOUNT_INFO, init=False)
queue: bool = False
signer_lists: bool = False
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/account_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
`See account_lines <https://xrpl.org/account_lines.html>`_
"""
from dataclasses import dataclass, field
from typing import Any, Optional, Union
from typing import Any, Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountLines(Request):
class AccountLines(Request, LookupByLedgerRequest):
"""
This request returns information about an account's trust lines, including balances
in all non-XRP currencies and assets. All information retrieved is relative to a
Expand All @@ -31,8 +31,6 @@ class AccountLines(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.ACCOUNT_LINES, init=False)
peer: Optional[str] = None
limit: Optional[int] = None
Expand Down
4 changes: 2 additions & 2 deletions xrpl/models/requests/account_nfts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from dataclasses import dataclass, field
from typing import Any, Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountNFTs(Request):
class AccountNFTs(Request, LookupByLedgerRequest):
"""
This method retrieves all of the NFTs currently owned
by the specified account.
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/account_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"""
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Optional, Union
from typing import Any, Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init

Expand All @@ -31,7 +31,7 @@ class AccountObjectType(str, Enum):

@require_kwargs_on_init
@dataclass(frozen=True)
class AccountObjects(Request):
class AccountObjects(Request, LookupByLedgerRequest):
"""
This request returns the raw ledger format for all objects owned by an account.
Expand All @@ -48,8 +48,6 @@ class AccountObjects(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.ACCOUNT_OBJECTS, init=False)
type: Optional[AccountObjectType] = None
deletion_blockers_only: bool = False
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/account_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
`See account_offers <https://xrpl.org/account_offers.html>`_
"""
from dataclasses import dataclass, field
from typing import Any, Optional, Union
from typing import Any, Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountOffers(Request):
class AccountOffers(Request, LookupByLedgerRequest):
"""
This request retrieves a list of offers made by a given account that are
outstanding as of a particular ledger version.
Expand All @@ -29,8 +29,6 @@ class AccountOffers(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.ACCOUNT_OFFERS, init=False)
limit: Optional[int] = None
# marker data shape is actually undefined in the spec, up to the
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/account_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
`See account_tx <https://xrpl.org/account_tx.html>`_
"""
from dataclasses import dataclass, field
from typing import Any, Optional, Union
from typing import Any, Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class AccountTx(Request):
class AccountTx(Request, LookupByLedgerRequest):
"""
This request retrieves from the ledger a list of transactions that involved the
specified account.
Expand All @@ -29,8 +29,6 @@ class AccountTx(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.ACCOUNT_TX, init=False)
ledger_index_min: Optional[int] = None
ledger_index_max: Optional[int] = None
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/book_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
as the order book, between two currencies.
"""
from dataclasses import dataclass, field
from typing import Optional, Union
from typing import Optional

from xrpl.models.currencies import Currency
from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class BookOffers(Request):
class BookOffers(Request, LookupByLedgerRequest):
"""
The book_offers method retrieves a list of offers, also known
as the order book, between two currencies.
Expand All @@ -34,7 +34,5 @@ class BookOffers(Request):
"""

method: RequestMethod = field(default=RequestMethod.BOOK_OFFERS, init=False)
ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
limit: Optional[int] = None
taker: Optional[str] = None
7 changes: 2 additions & 5 deletions xrpl/models/requests/deposit_authorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
authorization to deliver money to your account.
"""
from dataclasses import dataclass, field
from typing import Optional

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class DepositAuthorized(Request):
class DepositAuthorized(Request, LookupByLedgerRequest):
"""
The deposit_authorized command indicates whether one account
is authorized to send payments directly to another. See
Expand All @@ -37,5 +36,3 @@ class DepositAuthorized(Request):
"""

method: RequestMethod = field(default=RequestMethod.DEPOSIT_AUTHORIZED, init=False)
ledger_hash: Optional[str] = None
ledger_index: Optional[str] = None
6 changes: 2 additions & 4 deletions xrpl/models/requests/gateway_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from dataclasses import dataclass, field
from typing import List, Optional, Union

from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class GatewayBalances(Request):
class GatewayBalances(Request, LookupByLedgerRequest):
"""
This request calculates the total balances issued by a given account, optionally
excluding amounts held by operational addresses.
Expand All @@ -29,8 +29,6 @@ class GatewayBalances(Request):
:meta hide-value:
"""

ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
method: RequestMethod = field(default=RequestMethod.GATEWAY_BALANCES, init=False)
strict: bool = False
hotwallet: Optional[Union[str, List[str]]] = None
8 changes: 3 additions & 5 deletions xrpl/models/requests/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@
`See ledger <https://xrpl.org/ledger.html>`_
"""
from dataclasses import dataclass, field
from typing import Optional, Union
from typing import Optional

from xrpl.models.requests.ledger_entry import LedgerEntryType
from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class Ledger(Request):
class Ledger(Request, LookupByLedgerRequest):
"""
Retrieve information about the public ledger.
`See ledger <https://xrpl.org/ledger.html>`_
"""

method: RequestMethod = field(default=RequestMethod.LEDGER, init=False)
ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
full: bool = False
accounts: bool = False
transactions: bool = False
Expand Down
8 changes: 3 additions & 5 deletions xrpl/models/requests/ledger_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
`See ledger data <https://xrpl.org/ledger_data.html>`_
"""
from dataclasses import dataclass, field
from typing import Any, Optional, Union
from typing import Any, Optional

from xrpl.models.requests.ledger_entry import LedgerEntryType
from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class LedgerData(Request):
class LedgerData(Request, LookupByLedgerRequest):
"""
The ledger_data method retrieves contents of
the specified ledger. You can iterate through
Expand All @@ -25,8 +25,6 @@ class LedgerData(Request):
"""

method: RequestMethod = field(default=RequestMethod.LEDGER_DATA, init=False)
ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
binary: bool = False
limit: Optional[int] = None
# marker data shape is actually undefined in the spec, up to the
Expand Down
8 changes: 4 additions & 4 deletions xrpl/models/requests/ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Dict, List, Optional, Union

from xrpl.models.base_model import BaseModel
from xrpl.models.requests.request import Request, RequestMethod
from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init

Expand Down Expand Up @@ -174,7 +174,7 @@ class Ticket(BaseModel):

@require_kwargs_on_init
@dataclass(frozen=True)
class LedgerEntry(Request):
class LedgerEntry(Request, LookupByLedgerRequest):
"""
The ledger_entry method returns a single ledger
object from the XRP Ledger in its raw format.
Expand All @@ -195,8 +195,8 @@ class LedgerEntry(Request):
ripple_state: Optional[RippleState] = None
ticket: Optional[Union[str, Ticket]] = None
binary: bool = False
ledger_hash: Optional[str] = None
ledger_index: Optional[Union[str, int]] = None
nft_page: Optional[str] = None
"""Must be the object ID of the NFToken page, as hexadecimal"""

def _get_errors(self: LedgerEntry) -> Dict[str, str]:
errors = super()._get_errors()
Expand Down
Loading

0 comments on commit 1d51463

Please sign in to comment.