diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-04-28 19:28:52 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-04-28 20:26:27 +0200 |
commit | 98c328fffd7202d4819a2bb9f734ef63d1b8f38d (patch) | |
tree | 47d81aeb3326d26183a2fc67bf3748d7be761c4b /src/app.rs | |
parent | c665eeaafa170a3bdcec21c606a96a2cfc0dff47 (diff) |
Rewrite state.rs to app.rs
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 40 |
1 files changed, 40 insertions, 0 deletions
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<Self, Error> { + Repository::new(host, port).map(|repo| App { repo, profile, publishing_key }) + } + + pub async fn new_profile(repo: Repository, names: Vec<String>) -> Result<Self> { + 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 }) + } + + +} + |