LedgerSnapshot is a structure used to store a snapshot of a ledger that can be restored for use in environments as a LedgerInfo and a SnapshotSource. It captures protocol version, sequence number, timestamp, network ID, and various TTL settings, along with a collection of ledger entries.
Key capabilities include:
- Creation: Build a snapshot from existing
LedgerInfo and a set of entries using from(). - Persistence: Read from or write to files/readers using JSON serialization.
- State Management: Update ledger info or replace/update specific entries.
- Integration: Implements
SnapshotSource, allowing it to be used as a source of truth for ledger entries in a host environment.
```rust
// Example of creating a snapshot from info and entries
let snapshot = LedgerSnapshot::from(ledger_info, entries_iterator);
// Writing the snapshot to a file
snapshot.write_file("snapshot.json")?;
// Reading a snapshot from a file
let loaded_snapshot = LedgerSnapshot::read_file("snapshot.json")?;
```埋