backup.rs
1 //! Federation-stored client backups 2 //! 3 //! Federations can store client-encrypted backups to help 4 //! clients recover from a snapshot, instead of a blank slate. 5 use std::time::SystemTime; 6 7 use fedimint_core::encoding::{Decodable, Encodable}; 8 use fedimint_core::{impl_db_lookup, impl_db_record}; 9 use serde::{Deserialize, Serialize}; 10 11 use crate::db::DbKeyPrefix; 12 13 /// Key used to store user's ecash backups 14 #[derive(Debug, Clone, Copy, Encodable, Decodable, Serialize)] 15 pub struct ClientBackupKey(pub secp256k1_zkp::PublicKey); 16 17 #[derive(Debug, Encodable, Decodable)] 18 pub struct ClientBackupKeyPrefix; 19 20 impl_db_record!( 21 key = ClientBackupKey, 22 value = ClientBackupSnapshot, 23 db_prefix = DbKeyPrefix::ClientBackup, 24 ); 25 impl_db_lookup!(key = ClientBackupKey, query_prefix = ClientBackupKeyPrefix); 26 27 /// User's backup, received at certain time, containing encrypted payload 28 #[derive(Debug, Clone, PartialEq, Eq, Encodable, Decodable, Serialize, Deserialize)] 29 pub struct ClientBackupSnapshot { 30 pub timestamp: SystemTime, 31 #[serde(with = "fedimint_core::hex::serde")] 32 pub data: Vec<u8>, 33 }