Skip to main content

MemLedger

Struct MemLedger 

Source
pub struct MemLedger { /* private fields */ }
Expand description

An in-memory single-writer double-entry ledger.

Implementations§

Source§

impl MemLedger

Source

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.

Source

pub fn ledger_id(&self) -> &Did

The cell identity.

Source

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.

Source

pub fn clock(&self) -> u64

The current logical clock.

Source

pub fn journal(&self) -> &[JournalEntry]

The full journal (reference/oracle inspection).

Source

pub fn accounts(&self) -> impl Iterator<Item = &Account>

Iterator over all accounts (for conservation checks in tests).

Source

pub fn last_checkpoint(&self) -> Option<&SignedCheckpoint>

The last signed checkpoint, if any.

Trait Implementations§

Source§

impl Debug for MemLedger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LedgerBackend for MemLedger

Source§

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

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 more
Source§

fn authorize_mint<'a>( &self, t: &'a IssueTransfer, sig: &[u8], ) -> Result<MintCapability<'a>, LedgerError>

Verify an issuance authorization against this backend’s mint authority, yielding the capability Self::credit requires. Read more
Source§

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

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

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

Two-phase phase 2 cancel: releases the pending holds.
Source§

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>

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>

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>

Ordered peek at committed-but-unemitted proof-plane items (plan §2e).
Source§

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>

Replay/inspection window into the journal (for verify tools and settlement framing).
Source§

fn head(&self) -> ChainHead

The current head of the hash chain.
Source§

impl StateView for MemLedger

Source§

fn account(&self, id: AccountId) -> Option<&Account>

Look up an account by id.
Source§

fn pending(&self, id: TransferId) -> Option<&PendingReservation>

Look up a pending reservation by its phase-1 transfer id.
Source§

fn now(&self) -> u64

The ledger’s logical commit clock (seconds). Deadlines are judged against this at apply time (plan §2b.5) — never a caller clock.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.