From 7d285e66905c7e97d9b3f2006049498004dbe035 Mon Sep 17 00:00:00 2001 From: Kent White Date: Fri, 15 Apr 2022 15:12:08 -0700 Subject: [PATCH] Move list command to use aptos_rest_client Closes: #529 --- crates/aptos/src/account/create.rs | 4 ++-- crates/aptos/src/account/list.rs | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/crates/aptos/src/account/create.rs b/crates/aptos/src/account/create.rs index f195b217ac5ab..52c1ec0ef4ae9 100644 --- a/crates/aptos/src/account/create.rs +++ b/crates/aptos/src/account/create.rs @@ -31,7 +31,7 @@ use reqwest; pub struct CreateAccount { #[clap(flatten)] private_key_input_options: PrivateKeyInputOptions, - + #[clap(flatten)] encoding_options: EncodingOptions, @@ -40,7 +40,7 @@ pub struct CreateAccount { /// Public Key of account you want to create public_key: String, - + /// Chain ID chain_id: u8, } diff --git a/crates/aptos/src/account/list.rs b/crates/aptos/src/account/list.rs index 7e88ffe5e2570..6ad4f5c17f417 100644 --- a/crates/aptos/src/account/list.rs +++ b/crates/aptos/src/account/list.rs @@ -8,11 +8,12 @@ use crate::{ common::{types::NodeOptions, utils::to_common_result}, - CliResult, Error, + CliResult, Error as CommonError, }; +use anyhow::Error; +use aptos_rest_client::{types::Resource, Client}; use aptos_types::account_address::AccountAddress; use clap::Parser; -use reqwest; /// Command to list resources owned by an address /// @@ -26,14 +27,16 @@ pub struct ListResources { } impl ListResources { - async fn get_resources(self) -> Result, reqwest::Error> { - reqwest::get(format!( - "{}/accounts/{}/resources", - self.node.url, self.account - )) - .await? - .json() - .await + async fn get_resources(self) -> Result, Error> { + let client = Client::new(self.node.url); + let response: Vec = client + .get_account_resources(self.account) + .await? + .into_inner(); + Ok(response + .iter() + .map(|json| json.data.clone()) + .collect::>()) } // TODO: Format this in a reasonable way while providing all information @@ -42,7 +45,7 @@ impl ListResources { let result = self .get_resources() .await - .map_err(|err| Error::UnexpectedError(err.to_string())); + .map_err(|err| CommonError::UnexpectedError(err.to_string())); to_common_result(result) } }