Skip to content

Commit

Permalink
feat: add put/get methods for DAG data
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Jun 21, 2024
1 parent 9bf0624 commit 548f394
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions hermes/crates/hermes-ipfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use std::str::FromStr;

/// IPLD
pub use libipld::Ipld;
/// IPFS Content Identifier.
pub use libipld::{self as ipld, Cid};
/// Peer Info type.
Expand All @@ -21,6 +23,7 @@ pub use rust_ipfs::PeerId;
/// Builder type for IPFS Node configuration.
pub use rust_ipfs::UninitializedIpfsNoop as IpfsBuilder;
use rust_ipfs::{
dag::ResolveError,
libp2p::{futures::stream::BoxStream, kad::Record},
unixfs::AddOpt,
MessageId, PubsubEvent, Quorum, SubscriptionStream,
Expand Down Expand Up @@ -205,6 +208,40 @@ impl HermesIpfs {
self.node.dht_mode(mode).await
}

/// Add DAG data to IPFS.
///
/// ## Parameters
///
/// * `ipld` - `Ipld`
///
/// ## Returns
///
/// * `Result<Cid>`
///
/// ## Errors
///
/// Returns error if unable to add DAG content.
pub async fn dag_put(&self, ipld: Ipld) -> anyhow::Result<Cid> {
self.node.put_dag(ipld).await
}

/// Get DAG data from IPFS.
///
/// ## Parameters
///
/// * `path` - `impl Into<IpfsPath>`
///
/// ## Returns
///
/// * `Result<Ipld>`
///
/// ## Errors
///
/// Returns error if unable to get DAG content.
pub async fn dag_get<T: Into<IpfsPath>>(&self, path: T) -> Result<Ipld, ResolveError> {
self.node.get_dag(path).await
}

/// Add content to DHT.
///
/// ## Parameters
Expand Down

0 comments on commit 548f394

Please sign in to comment.