-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathipfs.rs
46 lines (36 loc) · 1.18 KB
/
ipfs.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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();
// Add file
let added_file = ipfs.add(file).await?;
println!("{:#?}", added_file);
let hash = &added_file.ipfs_hash;
// Pin it
let pinned_file = ipfs.pin_add(hash).await?;
println!("{:#?}", pinned_file);
let hash = &pinned_file.ipfs_hash;
// List pins
let pin_list = ipfs.pin_list().await?;
println!("{:#?}", pin_list);
// List pin by ipfs_hash (id)
let pin_list_by_id = ipfs.pin_list_by_id(hash).await?;
println!("{:#?}", pin_list_by_id);
// Query contents
let gateway = ipfs.gateway(hash).await?;
let string = String::from_utf8(gateway).unwrap();
println!("content: '{:#?}'", string);
// Remove pin
let pin_removed = ipfs.pin_remove(hash).await?;
println!("{:#?}", pin_removed);
Ok(())
}