`reveal_next_spk` should have a way of reversing the change
If you fail to persist the changeset you should be able to reverse the revelation if (for example, the index increment failed to persist).
How about a callback method?
pub fn reveal_next_spk_on_persist<C, E>(&mut self, keychain: &K, persist: C) -> Result<(u32, &Script), E>
where
C: FnMut(super::ChangeSet<K>) -> Result<(), E>
{
todo!()
}
That seems like a reasonable approach. The problem is that we will now need to create async versions to satisfy async people. But maybe we can make an exception here and do that because this is the only "change" that is actually important to persist
I'm not sure if I actually need this for user facing applications like mine though. The right approach is probably to crash the whole application if the database has a problem.
I think perhaps we just need to have KeychainTxOutIndex::unreveal_last_spk(keychain) which would be enough to solve the immediate problem without crashing the application.