bdk icon indicating copy to clipboard operation
bdk copied to clipboard

`reveal_next_spk` should have a way of reversing the change

Open LLFourn opened this issue 1 year ago • 3 comments

If you fail to persist the changeset you should be able to reverse the revelation if (for example, the index increment failed to persist).

LLFourn avatar Feb 05 '24 05:02 LLFourn

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!()
}

evanlinjin avatar Feb 05 '24 15:02 evanlinjin

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.

LLFourn avatar Feb 06 '24 02:02 LLFourn

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.

LLFourn avatar Feb 06 '24 23:02 LLFourn