pub struct MemLedger { /* private fields */ }Expand description
An in-memory single-writer double-entry ledger.
Implementations§
Source§impl MemLedger
impl MemLedger
Sourcepub fn new(ledger_id: Did, mint_authority: Option<MintAuthority>) -> Self
pub fn new(ledger_id: Did, mint_authority: Option<MintAuthority>) -> Self
Create an empty ledger for the given cell identity (logical clock at 0) with the given issuance authority.
The authority is a construction parameter, not a setter: once a
MemLedger exists, what it will accept as a mint authorization cannot
be changed. None yields a ledger that cannot mint at all.
Sourcepub fn advance_clock(&mut self, to: u64)
pub fn advance_clock(&mut self, to: u64)
Advance the logical commit clock to at least to (monotone — the clock
never regresses). This is the WASM-safe substitute for a wall clock:
tests and the actor drive time explicitly, which is what makes the
expiry-vs-post race deterministic.
Sourcepub fn journal(&self) -> &[JournalEntry]
pub fn journal(&self) -> &[JournalEntry]
The full journal (reference/oracle inspection).
Sourcepub fn accounts(&self) -> impl Iterator<Item = &Account>
pub fn accounts(&self) -> impl Iterator<Item = &Account>
Iterator over all accounts (for conservation checks in tests).
Sourcepub fn last_checkpoint(&self) -> Option<&SignedCheckpoint>
pub fn last_checkpoint(&self) -> Option<&SignedCheckpoint>
The last signed checkpoint, if any.
Trait Implementations§
Source§impl LedgerBackend for MemLedger
impl LedgerBackend for MemLedger
Source§fn open_account(&mut self, spec: AccountSpec) -> Result<Account, LedgerError>
fn open_account(&mut self, spec: AccountSpec) -> Result<Account, LedgerError>
Idempotent. Creates the account iff absent and returns it; if it already
exists the existing row is returned (its unit must match, else
LedgerError::AccountUnitConflict).Source§fn credit(&mut self, cap: MintCapability<'_>) -> Outcome
fn credit(&mut self, cap: MintCapability<'_>) -> Outcome
Single-phase issuance: issuer liability → destination. INV-1: the only
entry point that grows a unit’s supply; the debit side MUST be the
issuer’s
IssuerLiability account for the unit (checked). Read moreVerify an issuance authorization against this backend’s mint authority,
yielding the capability
Self::credit requires. Read moreSource§fn debit(&mut self, t: Transfer) -> Outcome
fn debit(&mut self, t: Transfer) -> Outcome
Single-phase spend. Overdraft-checked on the debit side (plan §2b.1).
Source§fn reserve(&mut self, t: Transfer, timeout_s: u32) -> Outcome
fn reserve(&mut self, t: Transfer, timeout_s: u32) -> Outcome
Two-phase phase 1: places pending holds on both sides (plan §2b). The
transfer’s
id is also the reservation id used by post/void.Source§fn post(
&mut self,
id: TransferId,
pending: TransferId,
amount: Option<u128>,
) -> Outcome
fn post( &mut self, id: TransferId, pending: TransferId, amount: Option<u128>, ) -> Outcome
Two-phase phase 2.
amount: None = full post; Some(p) = partial, the
remainder released. At most one second phase succeeds per reservation.Source§fn void(&mut self, id: TransferId, pending: TransferId) -> Outcome
fn void(&mut self, id: TransferId, pending: TransferId) -> Outcome
Two-phase phase 2 cancel: releases the pending holds.
Source§fn balance(&self, account: AccountId) -> Result<BalanceView, LedgerError>
fn balance(&self, account: AccountId) -> Result<BalanceView, LedgerError>
Read-only balance projection (served from a consistent snapshot; safe
concurrent with the writer).
Source§fn checkpoint(
&mut self,
signer: &dyn CheckpointSigner,
) -> Result<SignedCheckpoint, LedgerError>
fn checkpoint( &mut self, signer: &dyn CheckpointSigner, ) -> Result<SignedCheckpoint, LedgerError>
Force a signed checkpoint now and return it. Periodic checkpoints are the
backend’s own duty (driven from
tick).Source§fn tick(
&mut self,
_signer: &dyn CheckpointSigner,
) -> Result<TickReport, LedgerError>
fn tick( &mut self, _signer: &dyn CheckpointSigner, ) -> Result<TickReport, LedgerError>
Housekeeping: expiry sweep (plan §2b.4), outcome pruning (plan §2c — later
item), and scheduled checkpoints. Called by the actor on an interval.
Source§fn outbox_peek(&self, max: usize) -> Result<Vec<OutboxItem>, LedgerError>
fn outbox_peek(&self, max: usize) -> Result<Vec<OutboxItem>, LedgerError>
Ordered peek at committed-but-unemitted proof-plane items (plan §2e).
Source§fn outbox_ack(&mut self, up_to: OutboxSeq) -> Result<(), LedgerError>
fn outbox_ack(&mut self, up_to: OutboxSeq) -> Result<(), LedgerError>
Acknowledge (drop) drained outbox items up to and including
up_to.Source§fn journal_range(
&self,
from_seq: u64,
max: usize,
) -> Result<Vec<JournalEntry>, LedgerError>
fn journal_range( &self, from_seq: u64, max: usize, ) -> Result<Vec<JournalEntry>, LedgerError>
Replay/inspection window into the journal (for verify tools and
settlement framing).
Source§impl StateView for MemLedger
impl StateView for MemLedger
Source§fn pending(&self, id: TransferId) -> Option<&PendingReservation>
fn pending(&self, id: TransferId) -> Option<&PendingReservation>
Look up a pending reservation by its phase-1 transfer id.
Auto Trait Implementations§
impl Freeze for MemLedger
impl RefUnwindSafe for MemLedger
impl Send for MemLedger
impl Sync for MemLedger
impl Unpin for MemLedger
impl UnsafeUnpin for MemLedger
impl UnwindSafe for MemLedger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more