db.rs
 1  use fedimint_core::encoding::{Decodable, Encodable};
 2  use fedimint_core::{impl_db_lookup, impl_db_record};
 3  use serde::Serialize;
 4  use strum_macros::EnumIter;
 5  
 6  /// Namespaces DB keys for this module
 7  #[repr(u8)]
 8  #[derive(Clone, EnumIter, Debug)]
 9  pub enum DbKeyPrefix {
10      Example = 0x01,
11  }
12  
13  // TODO: Boilerplate-code
14  impl 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  #[derive(Debug, Clone, Encodable, Decodable, Eq, PartialEq, Hash, Serialize)]
21  pub struct EmptyExampleKey(#[serde(with = "::fedimint_core::encoding::as_hex")] pub Vec<u8>);
22  
23  #[derive(Debug, Encodable, Decodable)]
24  pub struct EmptyExampleKeyPrefix;
25  
26  impl_db_record!(
27      key = EmptyExampleKey,
28      value = Vec<u8>,
29      db_prefix = DbKeyPrefix::Example,
30  );
31  impl_db_lookup!(key = EmptyExampleKey, query_prefix = EmptyExampleKeyPrefix,);