fedimint_mintv2_client/
client_db.rs1use std::collections::{BTreeMap, BTreeSet};
2
3use bitcoin_hashes::hash160;
4use fedimint_core::core::Account;
5use fedimint_core::encoding::{Decodable, Encodable};
6use fedimint_core::{impl_db_lookup, impl_db_record};
7use fedimint_mintv2_common::Denomination;
8use strum::Display;
9use strum_macros::EnumIter;
10
11use crate::SpendableNoteUndecoded;
12use crate::issuance::NoteIssuanceRequest;
13
14#[repr(u8)]
15#[derive(Clone, Display, EnumIter, Debug)]
16pub enum DbKeyPrefix {
17 Note = 0x20,
18 RecoveryState = 0x21,
19}
20
21#[derive(Debug, Clone, Encodable, Decodable)]
25pub struct SpendableNoteKey(pub Account, pub SpendableNoteUndecoded);
26
27#[derive(Debug, Clone, Encodable, Decodable)]
28pub struct SpendableNotePrefix(pub Account);
29
30#[derive(Debug, Clone, Encodable, Decodable)]
33pub struct SpendableNoteAmountPrefix(pub Account, pub Denomination);
34
35impl_db_record!(
36 key = SpendableNoteKey,
37 value = (),
38 db_prefix = DbKeyPrefix::Note,
39);
40
41impl_db_lookup!(key = SpendableNoteKey, query_prefix = SpendableNotePrefix);
42
43impl_db_lookup!(
44 key = SpendableNoteKey,
45 query_prefix = SpendableNoteAmountPrefix
46);
47
48#[derive(Debug, Clone, Encodable, Decodable)]
50pub struct RecoveryStateKey;
51
52#[derive(Debug, Clone, Encodable, Decodable)]
54pub struct RecoveryState {
55 pub next_index: u64,
57 pub total_items: u64,
59 pub requests: BTreeMap<hash160::Hash, (Account, NoteIssuanceRequest)>,
63 pub nonces: BTreeSet<hash160::Hash>,
65}
66
67impl_db_record!(
68 key = RecoveryStateKey,
69 value = RecoveryState,
70 db_prefix = DbKeyPrefix::RecoveryState,
71);