pub struct Ledger { /* private fields */ }Expand description
An append-only ledger held in memory. Persistent storage is the
caller’s responsibility: call Ledger::serialize to get a CAS-ready
blob, Ledger::deserialize to restore.
Implementations§
Source§impl Ledger
impl Ledger
Sourcepub fn new(secret: SessionSecret) -> Self
pub fn new(secret: SessionSecret) -> Self
Open a fresh ledger with the given session secret.
Sourcepub fn entries(&self) -> &[LedgerEntry]
pub fn entries(&self) -> &[LedgerEntry]
Borrow the ledger entries in causal order.
Sourcepub fn append(
&mut self,
timestamp: DateTime<Utc>,
tool_id: impl Into<String>,
args_hash: Digest256,
idempotency_key: impl Into<String>,
result_hash: Digest256,
side_effect_class: SideEffectClass,
) -> Result<&LedgerEntry>
pub fn append( &mut self, timestamp: DateTime<Utc>, tool_id: impl Into<String>, args_hash: Digest256, idempotency_key: impl Into<String>, result_hash: Digest256, side_effect_class: SideEffectClass, ) -> Result<&LedgerEntry>
Append a new entry and chain its HMAC. The caller supplies everything
except session_hmac, which we compute here.
Sourcepub fn verify(&self) -> Result<()>
pub fn verify(&self) -> Result<()>
Verify the entire HMAC chain. Returns Ok(()) if every entry verifies
in order; otherwise the first bad-entry index in Err.
Sourcepub fn serialize(&self, blobs: &dyn BlobStore) -> Result<Digest256>
pub fn serialize(&self, blobs: &dyn BlobStore) -> Result<Digest256>
Serialize the ledger to a single JSONL blob and store via blobs.
Note: the secret is NOT serialized — it must be re-supplied at
deserialization time.
Sourcepub fn deserialize(
blobs: &dyn BlobStore,
digest: &Digest256,
secret: SessionSecret,
) -> Result<Self>
pub fn deserialize( blobs: &dyn BlobStore, digest: &Digest256, secret: SessionSecret, ) -> Result<Self>
Restore a ledger from a previously-stored blob. The caller must supply
the same secret that signed the chain; otherwise Self::verify
will fail.