pub struct Ledger { /* private fields */ }Expand description
The append-only, Merkle-chained event ledger.
Implementations§
Source§impl Ledger
impl Ledger
pub fn new() -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn records(&self) -> &[LedgerRecord]
Sourcepub fn append(&mut self, event: LedgerEvent) -> Result<String>
pub fn append(&mut self, event: LedgerEvent) -> Result<String>
Append an event, extending the Merkle chain. Returns the new head.
Sourcepub fn stage(&self, event: LedgerEvent) -> Result<LedgerRecord>
pub fn stage(&self, event: LedgerEvent) -> Result<LedgerRecord>
Compute the record append would produce, without mutating the chain.
A write-ahead sink persists the staged record first and then commits
it with commit_staged; a durable-write failure
leaves the in-memory chain untouched, with no chain clone required.
Sourcepub fn commit_staged(&mut self, record: LedgerRecord) -> Result<()>
pub fn commit_staged(&mut self, record: LedgerRecord) -> Result<()>
Commit a record produced by stage. Rejects a record
that does not extend the current head exactly.
Sourcepub fn record_observation(&mut self, content: &[u8]) -> Result<String>
pub fn record_observation(&mut self, content: &[u8]) -> Result<String>
Record a nondeterministic observation before it is used (R2). Returns the observation handle (content address).
Sourcepub fn has_observation(&self, handle: &str) -> bool
pub fn has_observation(&self, handle: &str) -> bool
Whether an observation handle has a ledger record.
Sourcepub fn observation_hash(&self, handle: &str) -> Option<&str>
pub fn observation_hash(&self, handle: &str) -> Option<&str>
The recorded content hash for an observation handle, if any.
Sourcepub fn commit_transition(
&mut self,
event: LedgerEvent,
referenced_observations: &[String],
) -> Result<String>
pub fn commit_transition( &mut self, event: LedgerEvent, referenced_observations: &[String], ) -> Result<String>
The kernel-refusal rule: refuse to commit a transition that references an observation lacking a ledger record (PSP-8 System 11). Returns an error naming the first unrecorded handle.
Sourcepub fn verify_chain(&self) -> Result<()>
pub fn verify_chain(&self) -> Result<()>
Verify the Merkle chain end to end (tamper detection).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Ledger
impl RefUnwindSafe for Ledger
impl Send for Ledger
impl Sync for Ledger
impl Unpin for Ledger
impl UnsafeUnpin for Ledger
impl UnwindSafe for Ledger
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.