Files
prime-sdk-python/prime_sdk/transaction.py
Andrew Miller d425b58cfe
All checks were successful
Publish to PyPI Registry / publish (release) Successful in 23s
get_interchain: per_chain + chains options (default first anchor per chain); bump 0.5.0
transaction.get_interchain / block.get_interchain take per_chain= and chains=
kwargs mapping to prime-node's ?perChain=&chains= params. Default (no kwargs)
returns one anchor per chain. Shared interchain_query() helper, exported; pytest.
2026-06-05 10:56:33 -04:00

69 lines
2.6 KiB
Python

"""Transaction endpoints."""
from typing import List, Optional
from .client import CONTENT_TYPE_JSON, Client
from .interchain import interchain_query
from .models import (
InterchainTrace,
ListTransactionsResponse,
Transaction,
TransactionBulkRequest,
TransactionBulkResponse,
TransactionCreateRequest,
TransactionCreateResponse,
)
class TransactionClient:
def __init__(self, client: Client):
self._client = client
def create(self, req: TransactionCreateRequest) -> TransactionCreateResponse:
"""Submit a new transaction and return immediately with the assigned ID.
This does NOT wait for the transaction to be included in a block. Block
processing happens asynchronously on a ~5-second cycle. If you need the
block ID (e.g. for interchain verification), poll ``get`` until
``header.block_id`` is populated.
"""
return self._client.post(
"/api/v1/transaction", CONTENT_TYPE_JSON, req, TransactionCreateResponse
)
def create_bulk(self, req: TransactionBulkRequest) -> TransactionBulkResponse:
"""Submit multiple transactions and return immediately with their IDs.
Like ``create``, this does not wait for block inclusion.
"""
return self._client.post(
"/api/v1/transaction/bulk", CONTENT_TYPE_JSON, req, TransactionBulkResponse
)
def get(self, transaction_id: str) -> Transaction:
return self._client.get(f"/api/v1/transaction/{transaction_id}", Transaction)
def get_interchain(
self,
transaction_id: str,
per_chain: Optional[int] = None,
chains: Optional[List[str]] = None,
) -> InterchainTrace:
"""Trace a transaction to the validator (verification) blocks that
validated its prime block and the public-chain interchain anchors those
validator blocks were bundled into. If the transaction is still pending
(not yet in a block) the trace's lists are empty.
By default returns the first anchor per public chain (anchor proofs are
chained, so the earliest per chain is the meaningful one). ``per_chain``
caps anchors per chain (1 = first per chain; 0 = all); ``chains``
restricts to specific chain ids."""
return self._client.get(
f"/api/v1/transaction/{transaction_id}/interchain"
f"{interchain_query(per_chain, chains)}",
InterchainTrace,
)
def list(self) -> ListTransactionsResponse:
return self._client.get("/api/v1/transaction/", ListTransactionsResponse)