fedimint_mintv2_client/
migrations.rs1use fedimint_core::core::{Account, OperationId};
4use fedimint_core::db::{
5 DatabaseTransaction, DbMigrationError, IDatabaseTransactionOpsCore,
6 IDatabaseTransactionOpsCoreTyped,
7};
8use fedimint_core::encoding::Decodable;
9use fedimint_core::module::registry::ModuleDecoderRegistry;
10use futures::StreamExt;
11
12use crate::SpendableNote;
13use crate::client_db::{DbKeyPrefix, RecoveryState, RecoveryStateKey, SpendableNoteKey};
14
15pub(crate) async fn migrate_to_accounts_v1(
24 dbtx: &mut DatabaseTransaction<'_>,
25 _active_states: Vec<(Vec<u8>, OperationId)>,
26 _inactive_states: Vec<(Vec<u8>, OperationId)>,
27) -> Result<Option<(Vec<(Vec<u8>, OperationId)>, Vec<(Vec<u8>, OperationId)>)>, DbMigrationError> {
28 let prefix = vec![DbKeyPrefix::Note as u8];
32
33 let notes = dbtx
34 .raw_find_by_prefix(&prefix)
35 .await?
36 .map(|(key, _)| key)
37 .collect::<Vec<Vec<u8>>>()
38 .await;
39
40 for key in notes {
41 let note = SpendableNote::consensus_decode_whole(
42 &key[prefix.len()..],
43 &ModuleDecoderRegistry::default(),
44 )?;
45
46 dbtx.raw_remove_entry(&key).await?;
47
48 dbtx.insert_new_entry(&SpendableNoteKey(Account::Primary, note.into()), &())
49 .await;
50 }
51
52 if let Some(state) = dbtx.remove_entry(&legacy::RecoveryStateKey).await {
59 let state = RecoveryState {
60 next_index: state.next_index,
61 total_items: state.total_items,
62 requests: state
63 .requests
64 .into_iter()
65 .map(|(nonce_hash, request)| (nonce_hash, (Account::Primary, request)))
66 .collect(),
67 nonces: state.nonces,
68 };
69
70 dbtx.insert_new_entry(&RecoveryStateKey, &state).await;
71 }
72
73 Ok(None)
74}
75
76mod legacy;