fedimint_dummy_server/
db.rs

1use fedimint_core::encoding::{Decodable, Encodable};
2use fedimint_core::{Amount, InPoint, OutPoint, impl_db_lookup, impl_db_record};
3use serde::Serialize;
4use strum_macros::EnumIter;
5
6/// Namespaces DB keys for this module
7#[repr(u8)]
8#[derive(Clone, EnumIter, Debug)]
9pub enum DbKeyPrefix {
10    InputAudit = 0x01,
11    OutputAudit = 0x02,
12}
13
14impl std::fmt::Display for DbKeyPrefix {
15    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16        write!(f, "{self:?}")
17    }
18}
19
20/// Tracks inputs for audit (assets)
21#[derive(Debug, Clone, Encodable, Decodable, Eq, PartialEq, Hash, Serialize)]
22pub struct DummyInputAuditKey(pub InPoint);
23
24#[derive(Debug, Encodable, Decodable)]
25pub struct DummyInputAuditPrefix;
26
27impl_db_record!(
28    key = DummyInputAuditKey,
29    value = Amount,
30    db_prefix = DbKeyPrefix::InputAudit,
31);
32impl_db_lookup!(
33    key = DummyInputAuditKey,
34    query_prefix = DummyInputAuditPrefix
35);
36
37/// Tracks outputs for audit (liabilities)
38#[derive(Debug, Clone, Encodable, Decodable, Eq, PartialEq, Hash, Serialize)]
39pub struct DummyOutputAuditKey(pub OutPoint);
40
41#[derive(Debug, Encodable, Decodable)]
42pub struct DummyOutputAuditPrefix;
43
44impl_db_record!(
45    key = DummyOutputAuditKey,
46    value = Amount,
47    db_prefix = DbKeyPrefix::OutputAudit,
48);
49impl_db_lookup!(
50    key = DummyOutputAuditKey,
51    query_prefix = DummyOutputAuditPrefix
52);