use blockfrost::{BlockfrostIPFS, BlockfrostResult, IpfsSettings};
use std::fs;
fn build_ipfs() -> BlockfrostResult<BlockfrostIPFS> {
let api = BlockfrostIPFS::new(
"mainnetxvMK4xOpp5mHJgihi055KDLU64JJv2be",
IpfsSettings::new(),
);
Ok(api)
}
#[tokio::main]
async fn main() -> BlockfrostResult<()> {
let ipfs = build_ipfs()?;
let file = fs::read_to_string("/etc/fstab")?.into_bytes();
let added_file = ipfs.add(file).await?;
println!("{added_file:#?}");
let hash = &added_file.ipfs_hash;
let pinned_file = ipfs.pin_add(hash).await?;
println!("{pinned_file:#?}");
let hash = &pinned_file.ipfs_hash;
let pin_list = ipfs.pin_list().await?;
println!("{pin_list:#?}");
let pin_list_by_id = ipfs.pin_list_by_id(hash).await?;
println!("{pin_list_by_id:#?}");
let gateway = ipfs.gateway(hash).await?;
let string = String::from_utf8(gateway).unwrap();
println!("content: '{string:#?}'");
let pin_removed = ipfs.pin_remove(hash).await?;
println!("{pin_removed:#?}");
Ok(())
}