summaryrefslogtreecommitdiffstats
path: root/ipfs-api/examples/resolve_name.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipfs-api/examples/resolve_name.rs')
-rw-r--r--ipfs-api/examples/resolve_name.rs59
1 files changed, 30 insertions, 29 deletions
diff --git a/ipfs-api/examples/resolve_name.rs b/ipfs-api/examples/resolve_name.rs
index d50011f..2b263d5 100644
--- a/ipfs-api/examples/resolve_name.rs
+++ b/ipfs-api/examples/resolve_name.rs
@@ -6,43 +6,44 @@
// copied, modified, or distributed except according to those terms.
//
-use futures::Future;
use ipfs_api::IpfsClient;
-use tokio::runtime::current_thread::Runtime;
const IPFS_IPNS: &str = "/ipns/ipfs.io";
// Creates an Ipfs client, and resolves the Ipfs domain name, and
// publishes a path to Ipns.
//
-fn main() {
- println!("connecting to localhost:5001...");
+#[tokio::main]
+async fn main() {
+ eprintln!("connecting to localhost:5001...");
let client = IpfsClient::default();
- let name_resolve = client
- .name_resolve(Some(IPFS_IPNS), true, false)
- .map(|resolved| {
- println!("{} resolves to: {}", IPFS_IPNS, &resolved.path);
- });
- let name_publish = client
- .name_publish(IPFS_IPNS, true, None, None, None)
- .and_then(move |publish| {
- println!("published {} to: /ipns/{}", IPFS_IPNS, &publish.name);
-
- client
- .name_resolve(Some(&publish.name), true, false)
- .map(move |resolved| {
- println!("/ipns/{} resolves to: {}", &publish.name, &resolved.path);
- })
- });
-
- let fut = name_resolve
- .and_then(|_| name_publish)
- .map_err(|e| eprintln!("{}", e));
-
- Runtime::new()
- .expect("tokio runtime")
- .block_on(fut)
- .expect("successful response");
+ match client.name_resolve(Some(IPFS_IPNS), true, false).await {
+ Ok(resolved) => eprintln!("{} resolves to: {}", IPFS_IPNS, &resolved.path),
+ Err(e) => {
+ eprintln!("error resolving {}: {}", IPFS_IPNS, e);
+ return;
+ }
+ }
+
+ let publish = match client.name_publish(IPFS_IPNS, true, None, None, None).await {
+ Ok(publish) => {
+ eprintln!("published {} to: /ipns/{}", IPFS_IPNS, &publish.name);
+ publish
+ }
+ Err(e) => {
+ eprintln!("error publishing name: {}", e);
+ return;
+ }
+ };
+
+ match client.name_resolve(Some(&publish.name), true, false).await {
+ Ok(resolved) => {
+ eprintln!("/ipns/{} resolves to: {}", &publish.name, &resolved.path);
+ }
+ Err(e) => {
+ eprintln!("error resolving name: {}", e);
+ }
+ }
}