summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/profile.rs2
-rw-r--r--src/profile/mod.rs18
-rw-r--r--src/profile/state.rs12
3 files changed, 11 insertions, 21 deletions
diff --git a/src/commands/profile.rs b/src/commands/profile.rs
index 4da70f1..853984f 100644
--- a/src/commands/profile.rs
+++ b/src/commands/profile.rs
@@ -44,7 +44,7 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> {
log::info!("Loading '{}' from {}", name, state_dir.display());
let profile = Profile::load(Config::default(), &name).await?;
log::info!("Profile loaded");
- log::info!("Profile HEAD = {}", profile.head());
+ log::info!("Profile HEAD = {:?}", profile.head());
if let Some(connect_to) = connect_peer {
log::info!("Connecting to {:?}", connect_to);
diff --git a/src/profile/mod.rs b/src/profile/mod.rs
index 4a37bca..56b4ac9 100644
--- a/src/profile/mod.rs
+++ b/src/profile/mod.rs
@@ -53,24 +53,18 @@ impl Profile {
async fn new(ipfs: IpfsClient, config: Config, profile_name: String, keypair: libp2p::identity::Keypair) -> Result<Self> {
let client = Client::new(ipfs, config);
- let profile_head = Self::post_hello_world(&client, &profile_name).await?;
- let state = ProfileState::new(profile_head, profile_name, keypair);
+ let state = ProfileState::new(profile_name, keypair);
Ok(Profile { state, client })
}
- pub fn head(&self) -> &cid::Cid {
- self.state.profile_head()
+ pub fn head(&self) -> Option<&cid::Cid> {
+ self.state.profile_head().as_ref()
}
pub async fn connect(&self, peer: ipfs::MultiaddrWithPeerId) -> Result<()> {
self.client.connect(peer).await
}
- async fn post_hello_world(client: &Client, name: &str) -> Result<cid::Cid> {
- let text = format!("Hello world, I am {}", name);
- client.post_text_node(vec![], text).await
- }
-
async fn ipfs_path(state_dir: &StateDir) -> Result<PathBuf> {
let path = state_dir.ipfs();
tokio::fs::create_dir_all(&path).await?;
@@ -180,11 +174,7 @@ mod tests {
let profile = Profile::new_inmemory(Config::default(), "test-create-profile-and-helloworld").await;
assert!(profile.is_ok());
let profile = profile.unwrap();
- let head = profile.head();
- let exp_cid = cid::Cid::try_from("bafyreig2koltmta6tvag37dwnzfjf5ft2qxrafymqt56a7r4e5dfkhy3zu").unwrap();
- assert_eq!(*head, exp_cid, "{} != {}", *head, exp_cid);
- let exit = profile.exit().await;
- assert!(exit.is_ok(), "Not cleanly exited: {:?}", exit);
+ assert!(profile.head().is_none());
}
}
diff --git a/src/profile/state.rs b/src/profile/state.rs
index a84ff23..4075b52 100644
--- a/src/profile/state.rs
+++ b/src/profile/state.rs
@@ -32,7 +32,7 @@ impl From<PathBuf> for StateDir {
#[derive(getset::Getters)]
pub struct ProfileState {
#[getset(get = "pub")]
- profile_head: cid::Cid,
+ profile_head: Option<cid::Cid>,
#[getset(get = "pub")]
profile_name: String,
@@ -42,9 +42,9 @@ pub struct ProfileState {
}
impl ProfileState {
- pub(super) fn new(profile_head: cid::Cid, profile_name: String, keypair: libp2p::identity::Keypair) -> Self {
+ pub(super) fn new(profile_name: String, keypair: libp2p::identity::Keypair) -> Self {
Self {
- profile_head,
+ profile_head: None,
profile_name,
keypair
}
@@ -59,7 +59,7 @@ impl std::fmt::Debug for ProfileState {
#[derive(Debug, serde::Serialize, serde::Deserialize, getset::Getters)]
pub(super) struct ProfileStateSaveable {
- profile_head: Vec<u8>,
+ profile_head: Option<Vec<u8>>,
profile_name: String,
keypair: Vec<u8>,
}
@@ -67,7 +67,7 @@ pub(super) struct ProfileStateSaveable {
impl ProfileStateSaveable {
pub(super) fn new(s: &ProfileState) -> Result<Self> {
Ok(Self {
- profile_head: s.profile_head.to_bytes(),
+ profile_head: s.profile_head.clone().map(|v| v.to_bytes()),
profile_name: s.profile_name.clone(),
keypair: match s.keypair {
libp2p::identity::Keypair::Ed25519(ref kp) => Vec::from(kp.encode()),
@@ -116,7 +116,7 @@ impl TryInto<ProfileState> for ProfileStateSaveable {
fn try_into(mut self) -> Result<ProfileState> {
Ok(ProfileState {
- profile_head: cid::Cid::try_from(self.profile_head)?,
+ profile_head: self.profile_head.map(|h| cid::Cid::try_from(h)).transpose()?,
profile_name: self.profile_name,
keypair: {
let kp = libp2p::identity::ed25519::Keypair::decode(&mut self.keypair)?;