Skip to main content

fedimint_mintv2_server/
db.rs

1use fedimint_core::encoding::{Decodable, Encodable};
2use fedimint_core::secp256k1::PublicKey;
3use fedimint_core::{OutPoint, impl_db_lookup, impl_db_record};
4use fedimint_mintv2_common::{Denomination, RecoveryItem};
5use serde::Serialize;
6use strum_macros::EnumIter;
7use tbs::{BlindedMessage, BlindedSignatureShare};
8
9#[repr(u8)]
10#[derive(Clone, EnumIter, Debug)]
11pub enum DbKeyPrefix {
12    NoteNonce = 0x10,
13    BlindedSignatureShare = 0x11,
14    BlindedSignatureShareRecovery = 0x12,
15    MintAuditItem = 0x13,
16    RecoveryItem = 0x14,
17}
18
19impl std::fmt::Display for DbKeyPrefix {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        write!(f, "{self:?}")
22    }
23}
24
25#[derive(Debug, Clone, Encodable, Decodable, Eq, PartialEq, Hash, Serialize)]
26pub struct NonceKey(pub PublicKey);
27
28#[derive(Debug, Encodable, Decodable)]
29pub struct NonceKeyPrefix;
30
31impl_db_record!(
32    key = NonceKey,
33    value = (),
34    db_prefix = DbKeyPrefix::NoteNonce,
35);
36impl_db_lookup!(key = NonceKey, query_prefix = NonceKeyPrefix);
37
38#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
39pub struct BlindedSignatureShareKey(pub OutPoint);
40
41#[derive(Debug, Encodable, Decodable)]
42pub struct BlindedSignatureSharePrefix;
43
44impl_db_record!(
45    key = BlindedSignatureShareKey,
46    value = BlindedSignatureShare,
47    db_prefix = DbKeyPrefix::BlindedSignatureShare,
48);
49impl_db_lookup!(
50    key = BlindedSignatureShareKey,
51    query_prefix = BlindedSignatureSharePrefix
52);
53
54#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
55pub struct BlindedSignatureShareRecoveryKey(pub BlindedMessage);
56
57#[derive(Debug, Encodable, Decodable)]
58pub struct BlindedSignatureShareRecoveryPrefix;
59
60impl_db_record!(
61    key = BlindedSignatureShareRecoveryKey,
62    value = BlindedSignatureShare,
63    db_prefix = DbKeyPrefix::BlindedSignatureShareRecovery,
64);
65impl_db_lookup!(
66    key = BlindedSignatureShareRecoveryKey,
67    query_prefix = BlindedSignatureShareRecoveryPrefix
68);
69
70#[derive(Debug, Clone, Encodable, Decodable, Serialize)]
71pub struct IssuanceCounterKey(pub Denomination);
72
73#[derive(Debug, Encodable, Decodable)]
74pub struct IssuanceCounterPrefix;
75
76impl_db_record!(
77    key = IssuanceCounterKey,
78    value = u64,
79    db_prefix = DbKeyPrefix::MintAuditItem,
80);
81impl_db_lookup!(
82    key = IssuanceCounterKey,
83    query_prefix = IssuanceCounterPrefix
84);
85
86#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
87pub struct RecoveryItemKey(pub u64);
88
89#[derive(Debug, Encodable, Decodable)]
90pub struct RecoveryItemPrefix;
91
92impl_db_record!(
93    key = RecoveryItemKey,
94    value = RecoveryItem,
95    db_prefix = DbKeyPrefix::RecoveryItem,
96);
97impl_db_lookup!(key = RecoveryItemKey, query_prefix = RecoveryItemPrefix);