fedimint_mintv2_client/
client_db.rs1use std::collections::{BTreeMap, BTreeSet};
2
3use bitcoin_hashes::hash160;
4use fedimint_core::encoding::{Decodable, Encodable};
5use fedimint_core::{impl_db_lookup, impl_db_record};
6use fedimint_mintv2_common::Denomination;
7use strum::Display;
8use strum_macros::EnumIter;
9
10use crate::SpendableNote;
11use crate::issuance::NoteIssuanceRequest;
12
13#[repr(u8)]
14#[derive(Clone, Display, EnumIter, Debug)]
15pub enum DbKeyPrefix {
16 Note = 0x20,
17 RecoveryState = 0x21,
18}
19
20#[derive(Debug, Clone, Encodable, Decodable)]
21pub struct SpendableNoteKey(pub SpendableNote);
22
23#[derive(Debug, Clone, Encodable, Decodable)]
24pub struct SpendableNotePrefix;
25
26#[derive(Debug, Clone, Encodable, Decodable)]
27pub struct SpendableNoteAmountPrefix(pub Denomination);
28
29impl_db_record!(
30 key = SpendableNoteKey,
31 value = (),
32 db_prefix = DbKeyPrefix::Note,
33);
34
35impl_db_lookup!(key = SpendableNoteKey, query_prefix = SpendableNotePrefix);
36
37impl_db_lookup!(
38 key = SpendableNoteKey,
39 query_prefix = SpendableNoteAmountPrefix
40);
41
42#[derive(Debug, Clone, Encodable, Decodable)]
44pub struct RecoveryStateKey;
45
46#[derive(Debug, Clone, Encodable, Decodable)]
48pub struct RecoveryState {
49 pub next_index: u64,
51 pub total_items: u64,
53 pub requests: BTreeMap<hash160::Hash, NoteIssuanceRequest>,
56 pub nonces: BTreeSet<hash160::Hash>,
58}
59
60impl_db_record!(
61 key = RecoveryStateKey,
62 value = RecoveryState,
63 db_prefix = DbKeyPrefix::RecoveryState,
64);