Files
prime-sdk-python/prime_sdk/transaction.py
Andrew Miller e4e49218d0 add get_interchain: trace a transaction/block to validator blocks + interchain anchors
New transaction.get_interchain and block.get_interchain call the prime-node
/api/v1/{transaction,block}/{id}/interchain endpoints, returning an
InterchainTrace {block_id, validator_blocks, interchain_transactions}. Adds
VerificationBlock / InterchainTransaction / InterchainTrace dataclasses with
from_dict, exports them, and a from_dict test.
2026-06-02 14:12:59 -04:00

54 lines
2.0 KiB
Python

"""Transaction endpoints."""
from .client import CONTENT_TYPE_JSON, Client
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) -> 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."""
return self._client.get(
f"/api/v1/transaction/{transaction_id}/interchain", InterchainTrace
)
def list(self) -> ListTransactionsResponse:
return self._client.get("/api/v1/transaction/", ListTransactionsResponse)