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 `get_account_transactions_with_marker` to allow pagination through all transaction history [#462]

### Fixed:
- Typing for factory classmethods on models
Expand Down
575 changes: 80 additions & 495 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ flake8-isort = "^4.0.0"
flake8-annotations = "2.7.0"
flake8-absolute-import = "^1.0"
darglint = "^1.5.8"
Sphinx = "^3.5.1"
sphinx-rtd-theme = "^0.5.1"
aiounittest = "^1.4.0"
coverage = "^6.4.1"
Jinja2 = "^2.11.3"
MarkupSafe = "2.0.1"
Sphinx = "^5.1.1"

[tool.isort]
# Make sure that isort's settings line up with black
Expand Down
4 changes: 4 additions & 0 deletions xrpl/account/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
)
from xrpl.account.transaction_history import (
get_account_payment_transactions,
get_account_payment_transactions_with_marker,
get_account_transactions,
get_account_transactions_with_marker,
get_latest_transaction,
)

Expand All @@ -18,7 +20,9 @@
"get_account_root",
"get_account_info",
"get_account_payment_transactions",
"get_account_payment_transactions_with_marker",
"get_account_transactions",
"get_account_transactions_with_marker",
"does_account_exist",
"get_latest_transaction",
]
75 changes: 70 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, Tuple

from xrpl.asyncio.account import transaction_history
from xrpl.clients.sync_client import SyncClient
Expand All @@ -24,36 +24,101 @@ 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_with_marker(
address: str, client: SyncClient, marker: Optional[Any] = None
) -> Tuple[List[Dict[str, Any]], 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 most recent set of transactions for this address from the marker, along
with a new marker if there are more results to fetch from the server. Passing
the marker back in will fetch the next set of results. If there are no more
results, the marker will be None.

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


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_with_marker(
address: str, client: SyncClient, marker: Optional[Any] = None
) -> Tuple[List[Dict[str, Any]], 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, along with a marker if there
are more results to fetch from the server. Passing the marker back in will
fetch the next set of results. If there are no more results, the marker will
be None.
"""
return asyncio.run(
transaction_history.get_account_payment_transactions_with_marker(
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)
)
4 changes: 4 additions & 0 deletions xrpl/asyncio/account/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
)
from xrpl.asyncio.account.transaction_history import (
get_account_payment_transactions,
get_account_payment_transactions_with_marker,
get_account_transactions,
get_account_transactions_with_marker,
get_latest_transaction,
)

Expand All @@ -18,7 +20,9 @@
"get_account_root",
"get_account_info",
"get_account_payment_transactions",
"get_account_payment_transactions_with_marker",
"get_account_transactions",
"get_account_transactions_with_marker",
"does_account_exist",
"get_latest_transaction",
]
87 changes: 77 additions & 10 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, Tuple, cast

from xrpl.asyncio.clients import Client, XRPLRequestFailureException
from xrpl.core.addresscodec import is_valid_xaddress, xaddress_to_classic_address
Expand Down Expand Up @@ -32,43 +32,110 @@ async def get_latest_transaction(account: str, client: Client) -> Response:
return response


async def get_account_transactions(
address: str, client: Client
) -> List[Dict[str, Any]]:
async def get_account_transactions_with_marker(
address: str, client: Client, marker: Optional[Any] = None
) -> Tuple[List[Dict[str, Any]], 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.
The most recent set of transactions for this address from the marker, along
with a new marker if there are more results to fetch from the server. Passing
the marker back in will fetch the next set of results. If there are no more
results, the marker will be None.

Raises:
XRPLRequestFailureException: if the transaction fails.
"""
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"])
return (
cast(List[Dict[str, Any]], response.result["transactions"]),
response.result.get("marker"),
)


async def get_account_transactions(
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.

Raises:
XRPLRequestFailureException: if the transaction fails.
"""
(transactions, _) = await get_account_payment_transactions_with_marker(
address, client, marker
)
return transactions


async def get_account_payment_transactions_with_marker(
address: str, client: Client, marker: Optional[Any] = None
) -> Tuple[List[Dict[str, Any]], 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 most recent set of payment transactions for this address from the marker,
along with a new marker if there are more results to fetch from the server.
Passing the marker back in will fetch the next set of results. If there are
no more results, the marker will be None.
"""
(all_transactions, marker) = await get_account_transactions_with_marker(
address, client, marker
)
return (
[tx for tx in all_transactions if tx["tx"]["TransactionType"] == "Payment"],
marker,
)


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)
return [tx for tx in all_transactions if tx["tx"]["TransactionType"] == "Payment"]
(transactions, _) = await get_account_payment_transactions_with_marker(
address, client, marker
)
return transactions