novaplan-decentralized-priv.../nova_plan/ledger.py

34 lines
1.0 KiB
Python

"""A lightweight mission ledger with optional anchoring capability.
- append-only log of decisions
- optional anchoring to an external ground link (simulated for MVP)
"""
from __future__ import annotations
from datetime import datetime
from typing import List
class LedgerEntry:
def __init__(self, key: str, value: str, anchor: str | None = None):
self.key = key
self.value = value
self.timestamp = datetime.utcnow().isoformat()
self.anchor = anchor
def __repr__(self) -> str:
return f"LedgerEntry(key={self.key}, timestamp={self.timestamp}, anchor={self.anchor})"
class Ledger:
def __init__(self):
self.entries: List[LedgerEntry] = []
def log(self, key: str, value: str, anchor: str | None = None) -> LedgerEntry:
e = LedgerEntry(key, value, anchor)
self.entries.append(e)
return e
def last_anchor(self) -> str | None:
for e in reversed(self.entries):
if e.anchor:
return e.anchor
return None