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 docs to get_account_transactions and fix Sphinx dependency issues #427

Merged
merged 13 commits into from
Sep 14, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Function to parse the final account balances from a transaction's metadata
- Function to parse order book changes from a transaction's metadata
- Support for Ed25519 seeds that don't use the `sEd` prefix
- Add the optional `marker` field to `get_account_transactions` to paginate through results [#462]

### Fixed:
- Typing for factory classmethods on models
Expand Down
20 changes: 15 additions & 5 deletions xrpl/account/transaction_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""High-level methods to obtain information about account transaction history."""
import asyncio
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

from xrpl.asyncio.account import transaction_history
from xrpl.clients.sync_client import SyncClient
Expand All @@ -24,36 +24,46 @@ def get_latest_transaction(account: str, client: SyncClient) -> Response:
return asyncio.run(transaction_history.get_latest_transaction(account, client))


def get_account_transactions(address: str, client: SyncClient) -> List[Dict[str, Any]]:
def get_account_transactions(
address: str, client: SyncClient, marker: Optional[Any] = None
) -> List[Dict[str, Any]]:
"""
Query the ledger for a list of transactions that involved a given account.

Args:
address: the account to query.
client: the network client used to make network calls.
marker: fetches the next set of data from the server. The type of
marker is intentionally undefined in the spec and is chosen
by each server.

Returns:
The transaction history for the address.

Raises:
XRPLRequestFailureException: if the transaction fails.
"""
return asyncio.run(transaction_history.get_account_transactions(address, client))
return asyncio.run(
transaction_history.get_account_transactions(address, client, marker)
)


def get_account_payment_transactions(
address: str, client: SyncClient
address: str, client: SyncClient, marker: Optional[Any] = None
) -> List[Dict[str, Any]]:
"""
Query the ledger for a list of payment transactions that involved a given account.

Args:
address: the account to query.
client: the network client used to make network calls.
marker: fetches the next set of data from the server. The type of
marker is intentionally undefined in the spec and is chosen
by each server.

Returns:
The payment transaction history for the address.
"""
return asyncio.run(
transaction_history.get_account_payment_transactions(address, client)
transaction_history.get_account_payment_transactions(address, client, marker)
)
16 changes: 11 additions & 5 deletions xrpl/asyncio/account/transaction_history.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""High-level methods to obtain information about account transaction history."""
from typing import Any, Dict, List, cast
from typing import Any, Dict, List, Optional, cast

from xrpl.asyncio.clients import Client, XRPLRequestFailureException
from xrpl.core.addresscodec import is_valid_xaddress, xaddress_to_classic_address
Expand Down Expand Up @@ -33,14 +33,17 @@ async def get_latest_transaction(account: str, client: Client) -> Response:


async def get_account_transactions(
address: str, client: Client
address: str, client: Client, marker: Optional[Any] = None
) -> List[Dict[str, Any]]:
"""
Query the ledger for a list of transactions that involved a given account.

Args:
address: the account to query.
client: the network client used to make network calls.
marker: fetches the next set of data from the server. The type of
marker is intentionally undefined in the spec and is chosen
by each server.

Returns:
The transaction history for the address.
Expand All @@ -50,25 +53,28 @@ async def get_account_transactions(
"""
if is_valid_xaddress(address):
address, _, _ = xaddress_to_classic_address(address)
request = AccountTx(account=address)
request = AccountTx(account=address, marker=marker)
response = await client.request_impl(request)
if not response.is_successful():
raise XRPLRequestFailureException(response.result)
return cast(List[Dict[str, Any]], response.result["transactions"])


async def get_account_payment_transactions(
address: str, client: Client
address: str, client: Client, marker: Optional[Any] = None
) -> List[Dict[str, Any]]:
"""
Query the ledger for a list of payment transactions that involved a given account.

Args:
address: the account to query.
client: the network client used to make network calls.
marker: fetches the next set of data from the server. The type of
marker is intentionally undefined in the spec and is chosen
by each server.

Returns:
The payment transaction history for the address.
"""
all_transactions = await get_account_transactions(address, client)
all_transactions = await get_account_transactions(address, client, marker)
return [tx for tx in all_transactions if tx["tx"]["TransactionType"] == "Payment"]