use std::time::SystemTime;
use fedimint_core::encoding::{Decodable, Encodable};
use fedimint_core::{impl_db_lookup, impl_db_record, Amount, OutPoint};
use fedimint_mint_common::{BlindNonce, MintOutputOutcome, Nonce};
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
#[repr(u8)]
#[derive(Clone, EnumIter, Debug)]
pub enum DbKeyPrefix {
NoteNonce = 0x10,
OutputOutcome = 0x13,
MintAuditItem = 0x14,
EcashBackup = 0x15,
BlindNonce = 0x16,
}
impl std::fmt::Display for DbKeyPrefix {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
#[derive(Debug, Clone, Encodable, Decodable, Eq, PartialEq, Hash, Serialize)]
pub struct NonceKey(pub Nonce);
#[derive(Debug, Encodable, Decodable)]
pub struct NonceKeyPrefix;
impl_db_record!(
key = NonceKey,
value = (),
db_prefix = DbKeyPrefix::NoteNonce,
);
impl_db_lookup!(key = NonceKey, query_prefix = NonceKeyPrefix);
#[derive(Debug, Encodable, Decodable, Serialize)]
pub struct BlindNonceKey(pub BlindNonce);
#[derive(Debug, Encodable, Decodable)]
pub struct BlindNonceKeyPrefix;
impl_db_record!(
key = BlindNonceKey,
value = (),
db_prefix = DbKeyPrefix::BlindNonce,
);
impl_db_lookup!(key = BlindNonceKey, query_prefix = BlindNonceKeyPrefix);
#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
pub struct MintOutputOutcomeKey(pub OutPoint);
#[derive(Debug, Encodable, Decodable)]
pub struct MintOutputOutcomePrefix;
impl_db_record!(
key = MintOutputOutcomeKey,
value = MintOutputOutcome,
db_prefix = DbKeyPrefix::OutputOutcome,
);
impl_db_lookup!(
key = MintOutputOutcomeKey,
query_prefix = MintOutputOutcomePrefix
);
#[derive(Debug, Clone, Encodable, Decodable, Serialize)]
pub enum MintAuditItemKey {
Issuance(OutPoint),
IssuanceTotal,
Redemption(NonceKey),
RedemptionTotal,
}
#[derive(Debug, Encodable, Decodable)]
pub struct MintAuditItemKeyPrefix;
impl_db_record!(
key = MintAuditItemKey,
value = Amount,
db_prefix = DbKeyPrefix::MintAuditItem,
);
impl_db_lookup!(
key = MintAuditItemKey,
query_prefix = MintAuditItemKeyPrefix
);
#[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)]
pub struct EcashBackupKey(pub fedimint_core::secp256k1::PublicKey);
#[derive(Debug, Encodable, Decodable)]
pub struct EcashBackupKeyPrefix;
impl_db_record!(
key = EcashBackupKey,
value = ECashUserBackupSnapshot,
db_prefix = DbKeyPrefix::EcashBackup,
);
impl_db_lookup!(key = EcashBackupKey, query_prefix = EcashBackupKeyPrefix);
#[derive(Debug, Clone, PartialEq, Eq, Encodable, Decodable, Serialize, Deserialize)]
pub struct ECashUserBackupSnapshot {
pub timestamp: SystemTime,
#[serde(with = "fedimint_core::hex::serde")]
pub data: Vec<u8>,
}