feat(persist): persist BankBook under banks key, retire legacy bank_index, route capture to active bank (B2)

This commit is contained in:
2026-07-23 20:26:15 -04:00
parent 5b19525ec0
commit 85993ebc3e
6 changed files with 218 additions and 55 deletions
+20
View File
@@ -668,4 +668,24 @@ std::optional<BankBook> BankBook::deserialize(const std::string& json) {
return book;
}
BankBook BankBook::loadFromPersisted(const std::string& banksJson,
const std::string& legacyJson) {
// Precedence 1: the authoritative `banks` blob. A present-but-malformed blob is
// an error, not an absence — degrade to an empty book rather than falling through
// to a stale legacy key (which would resurrect superseded single-bank state).
if (!banksJson.empty()) {
auto book = deserialize(banksJson);
return book ? std::move(*book) : BankBook{};
}
// Precedence 2: no `banks` yet, but a legacy `bank_index` — one-way pool migration
// (deserialize's parse-time legacy path promotes it into the pool). A malformed
// legacy blob likewise degrades to empty.
if (!legacyJson.empty()) {
auto book = deserialize(legacyJson);
return book ? std::move(*book) : BankBook{};
}
// Precedence 3: a brand-new / never-captured project — a fresh empty book.
return BankBook{};
}
} // namespace reasampler