diff options
Diffstat (limited to 'lib/src/profile/state.rs')
-rw-r--r-- | lib/src/profile/state.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/src/profile/state.rs b/lib/src/profile/state.rs index 33f0bd6..921a2bf 100644 --- a/lib/src/profile/state.rs +++ b/lib/src/profile/state.rs @@ -6,6 +6,9 @@ use anyhow::Context; use anyhow::Result; use tokio::io::AsyncWriteExt; +use crate::profile::device::Device; +use crate::profile::device::DeviceSaveable; + #[derive(Debug)] pub struct StateDir(PathBuf); @@ -39,6 +42,9 @@ pub struct ProfileState { #[getset(get = "pub")] keypair: libp2p::identity::Keypair, + + #[getset(get = "pub")] + other_devices: Vec<Device>, } impl ProfileState { @@ -46,7 +52,8 @@ impl ProfileState { Self { profile_head: None, profile_name, - keypair + keypair, + other_devices: vec![], } } @@ -67,6 +74,7 @@ pub(super) struct ProfileStateSaveable { profile_head: Option<Vec<u8>>, profile_name: String, keypair: Vec<u8>, + other_devices: Vec<DeviceSaveable> } impl ProfileStateSaveable { @@ -77,7 +85,14 @@ impl ProfileStateSaveable { keypair: match s.keypair { libp2p::identity::Keypair::Ed25519(ref kp) => Vec::from(kp.encode()), _ => anyhow::bail!("Only keypair type ed25519 supported"), - } + }, + other_devices: { + s.other_devices + .iter() + .cloned() + .map(DeviceSaveable::try_from) + .collect::<Result<Vec<_>>>()? + }, }) } @@ -127,6 +142,12 @@ impl TryInto<ProfileState> for ProfileStateSaveable { let kp = libp2p::identity::ed25519::Keypair::decode(&mut self.keypair)?; libp2p::identity::Keypair::Ed25519(kp) }, + other_devices: { + self.other_devices + .into_iter() + .map(DeviceSaveable::try_into) + .collect::<Result<Vec<_>>>()? + }, }) } } |