auradefi 0.1.1
PyPI GitHub

LedgerPort

auradefi.ledger.port · source

Structural contract for ledger persistence backends.

Tenant-scoped throughout (rule #6). Sync events are ordered by ascending last-modified sequence, SPEC §6.4: last-modified order, NOT transaction date, and clients page until has_more is False before persisting the cursor.

upsert

upsert(self, tenant_id: str, txns: Sequence[LedgerTransaction]) -> list[SyncEvent]

Insert or update transactions inside one tenant's ledger.

Tenant-scoped (rule #6). Returns the resulting events ordered by ascending last-modified seq (SPEC §6.4). A re-delivered transaction whose payload is unchanged (payload_equal) emits no event, UNLESS the stored row is removed, in which case the transaction is re-added: stored with removed=False, a bumped seq, and an ADDED event (SPEC §6.4 re-add semantics; alternative backends must copy this).

Parameters

tenant_idrequired, str

none

txnsrequired, Sequence[LedgerTransaction]

none

sync

sync(self, tenant_id: str, cursor: str | None = None, limit: int = 100) -> SyncPage

Page of changes for one tenant since cursor (SPEC §6.4).

Tenant-scoped (rule #6). Events are ordered by ascending last-modified seq: last-modified order, NOT transaction date, so an old row that changes reappears. cursor=None starts from the beginning; a malformed cursor raises auradefi.errors.CursorError. Clients page until has_more is False before persisting next_cursor.

Parameters

tenant_idrequired, str

none

cursoroptional, str | None, default None

none

limitoptional, int, default 100

none

Raises

CursorError

get

get(self, tenant_id: str, txn_id: str) -> LedgerTransaction

Fetch one transaction within the caller's tenant scope.

Tenant-scoped (rule #6). Raises auradefi.errors.NotFoundError when the id does not exist inside this tenant. Another tenant's transaction is indistinguishable from a missing one.

Parameters

tenant_idrequired, str

none

txn_idrequired, str

none

Raises

NotFoundError

mark_removed

mark_removed(self, tenant_id: str, txn_ids: Sequence[str]) -> list[SyncEvent]

Mark transactions removed (reorg semantics) inside one tenant.

Tenant-scoped (rule #6). Returns REMOVED events ordered by ascending last-modified seq (SPEC §6.4); a reorg is removed plus a later re-added, never an in-place mutation.

Parameters

tenant_idrequired, str

none

txn_idsrequired, Sequence[str]

none

__init__

__init__(self, *args, **kwargs)

Parameters

argsrequired, any

none

kwargsoptional, any

none