-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stuff.rs
73 lines (56 loc) · 2.29 KB
/
test_stuff.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
extern crate ipfs_api;
extern crate tokio_core;
use ipfs_api::{IpfsApi, unmarshal, AddInfo, CommandInfo, IdInfo, ObjectInfo,
ObjectLinkInfo, VersionInfo};
use std::io::{self, Write};
use tokio_core::reactor;
fn main() {
let core = reactor::Core::new().unwrap();
let mut ipfs = IpfsApi::default(&core.handle());
if let Err(e) = run_commands(core, &mut ipfs) {
panic!("Error making API request: {:?}", e)
}
}
fn run_commands(mut core: reactor::Core, ipfs: &mut IpfsApi) -> Result<(), ipfs_api::RequestError> {
/*
let chunk = ipfs.commands()?;
let command_info: CommandInfo = unmarshal(&chunk).expect("could not unmarshal");
println!("commands result: {:?}", command_info);
println!("~~~~~~~~~~~~~~~~~~~~~");
/* TODO: update these
let res = ipfs.config_get("Addresses");
println!("config_get result: {:?}", res);
let res = ipfs.config_show();
println!("config_show result: {:?}", res);
*/
let chunk = ipfs.id()?;
let id_info: IdInfo = unmarshal(&chunk).expect("could not unmarshal");
println!("id result: {:?}", id_info);
println!("~~~~~~~~~~~~~~~~~~~~~");
let readme_path = "/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme";
let out_bytes = ipfs.cat(readme_path)?;
io::stdout().write(&out_bytes[..]).unwrap();
println!("~~~~~~~~~~~~~~~~~~~~~");
let path = std::path::Path::new("lorem_ipsum.txt");
let chunk = ipfs.add(&[path])?;
let add_info: AddInfo = unmarshal(&chunk[0]).expect("could not unmarshal");
println!("added file {:?}", path);
println!("add info: {:?}", add_info);
println!("~~~~~~~~~~~~~~~~~~~~~");
let chunk = ipfs.version()?;
let version_info: VersionInfo = unmarshal(&chunk).expect("could not unmarshal");
println!("version result: {:?}", version_info);
*/
let obj_get = ipfs.object_get("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG");
let chunk = core.run(obj_get)?;
let obj_info: ObjectInfo = unmarshal(&chunk).expect("could not unmarshal");
println!("object get result:");
for obj_link in obj_info.Links.iter() {
println!(" Link {{ name: {}, hash: {}, size: {} }}", obj_link.Name,
obj_link.Hash, obj_link.Size);
}
/*
let readme_hash = obj_info.Links[4].Hash;
*/
Ok(())
}