restoreStateFromMap method
Rebuilds the wallet state from a snapshot written by getSnapshotState
(after the event store's CBOR round trip).
Implementation
@override
Future<WalletState> restoreStateFromMap(Map<String, dynamic> map, int sequenceNumber) async {
final restored = WalletState.fromMap(map);
if (restored.walletId != aggregateId) {
throw StateError('Snapshot at $sequenceNumber belongs to wallet ${restored.walletId}, '
'not $aggregateId');
}
final state = restored.toBuilder();
// The round trip hands back untyped maps; the derivation records are
// read as typed maps.
AddressBook.typeRestoredDerivationRecords(state);
UtxoLedger.namePluginsOfRestoredUtxos(state);
// Balances are derived data: recompute them once from the restored UTXOs
// rather than trusting the cached values in the snapshot.
state.recomputeBalances();
return state.build();
}