From 98c328fffd7202d4819a2bb9f734ef63d1b8f38d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 28 Apr 2020 19:28:52 +0200 Subject: Rewrite state.rs to app.rs Signed-off-by: Matthias Beyer --- src/app.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/app.rs (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs new file mode 100644 index 0000000..8477378 --- /dev/null +++ b/src/app.rs @@ -0,0 +1,40 @@ +use std::collections::HashMap; + +use crate::types::util::IPFSHash; +use crate::types::util::IPNSHash; + +pub struct App { + repo: Repository, + profile: Profile, + publishing_key: String +} + +impl App { + + pub fn load(profile: Profile, publishing_key: String, host: &str, port: u16) -> Result { + Repository::new(host, port).map(|repo| App { repo, profile, publishing_key }) + } + + pub async fn new_profile(repo: Repository, names: Vec) -> Result { + let payload = Payload::Profile { + names, + picture: None, + more: BTreeMap::new(), + }; + let timestamp = types::Timestamp::now(); + let content = Content::new(vec![], timestame, payload); + + let head = repository.put_content(content).await?; + let device_name = repository.publish(&publishing_key, &head).await?; + + let profile = Profile { + device_name, + devices: vec![], + }; + + Ok(App { repository, profile, publishing_key }) + } + + +} + -- cgit v1.2.3