fedimint_mint_server/
db.rs1use fedimint_core::encoding::{Decodable, Encodable};
2use fedimint_core::{impl_db_lookup, impl_db_record, Amount, OutPoint};
3use fedimint_mint_common::{BlindNonce, MintOutputOutcome, Nonce};
4use serde::Serialize;
5use strum_macros::EnumIter;
6
7#[repr(u8)]
8#[derive(Clone, EnumIter, Debug)]
9pub enum DbKeyPrefix {
10 NoteNonce = 0x10,
11 OutputOutcome = 0x13,
12 MintAuditItem = 0x14,
13 BlindNonce = 0x16,
15}
16
17impl std::fmt::Display for DbKeyPrefix {
18 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19 write!(f, "{self:?}")
20 }
21}
22
23#[derive(Debug, Clone, Encodable, Decodable, Eq, PartialEq, Hash, Serialize)]
26pub struct NonceKey(pub Nonce);
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, Encodable, Decodable, Serialize)]
41pub struct BlindNonceKey(pub BlindNonce);
42
43#[derive(Debug, Encodable, Decodable)]
44pub struct BlindNonceKeyPrefix;
45
46impl_db_record!(
47 key = BlindNonceKey,
48 value = (),
49 db_prefix = DbKeyPrefix::BlindNonce,
50);
51impl_db_lookup!(key = BlindNonceKey, query_prefix = BlindNonceKeyPrefix);
52
53#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
55pub struct MintOutputOutcomeKey(pub OutPoint);
56
57#[derive(Debug, Encodable, Decodable)]
58pub struct MintOutputOutcomePrefix;
59
60impl_db_record!(
61 key = MintOutputOutcomeKey,
62 value = MintOutputOutcome,
63 db_prefix = DbKeyPrefix::OutputOutcome,
64);
65impl_db_lookup!(
66 key = MintOutputOutcomeKey,
67 query_prefix = MintOutputOutcomePrefix
68);
69
70#[derive(Debug, Clone, Encodable, Decodable, Serialize)]
73pub enum MintAuditItemKey {
74 Issuance(OutPoint),
75 IssuanceTotal,
76 Redemption(NonceKey),
77 RedemptionTotal,
78}
79
80#[derive(Debug, Encodable, Decodable)]
81pub struct MintAuditItemKeyPrefix;
82
83impl_db_record!(
84 key = MintAuditItemKey,
85 value = Amount,
86 db_prefix = DbKeyPrefix::MintAuditItem,
87);
88impl_db_lookup!(
89 key = MintAuditItemKey,
90 query_prefix = MintAuditItemKeyPrefix
91);