fedimint_mintv2_server/
db.rs1use 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 notify_on_modify = true
49);
50impl_db_lookup!(
51 key = BlindedSignatureShareKey,
52 query_prefix = BlindedSignatureSharePrefix
53);
54
55#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
56pub struct BlindedSignatureShareRecoveryKey(pub BlindedMessage);
57
58#[derive(Debug, Encodable, Decodable)]
59pub struct BlindedSignatureShareRecoveryPrefix;
60
61impl_db_record!(
62 key = BlindedSignatureShareRecoveryKey,
63 value = BlindedSignatureShare,
64 db_prefix = DbKeyPrefix::BlindedSignatureShareRecovery,
65);
66impl_db_lookup!(
67 key = BlindedSignatureShareRecoveryKey,
68 query_prefix = BlindedSignatureShareRecoveryPrefix
69);
70
71#[derive(Debug, Clone, Encodable, Decodable, Serialize)]
72pub struct IssuanceCounterKey(pub Denomination);
73
74#[derive(Debug, Encodable, Decodable)]
75pub struct IssuanceCounterPrefix;
76
77impl_db_record!(
78 key = IssuanceCounterKey,
79 value = u64,
80 db_prefix = DbKeyPrefix::MintAuditItem,
81);
82impl_db_lookup!(
83 key = IssuanceCounterKey,
84 query_prefix = IssuanceCounterPrefix
85);
86
87#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
88pub struct RecoveryItemKey(pub u64);
89
90#[derive(Debug, Encodable, Decodable)]
91pub struct RecoveryItemPrefix;
92
93impl_db_record!(
94 key = RecoveryItemKey,
95 value = RecoveryItem,
96 db_prefix = DbKeyPrefix::RecoveryItem,
97);
98impl_db_lookup!(key = RecoveryItemKey, query_prefix = RecoveryItemPrefix);