Skip to content

Commit

Permalink
Move list command to use aptos_rest_client
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-white authored and aptos-bot committed Apr 15, 2022
1 parent 108377b commit 7d285e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions crates/aptos/src/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use reqwest;
pub struct CreateAccount {
#[clap(flatten)]
private_key_input_options: PrivateKeyInputOptions,

#[clap(flatten)]
encoding_options: EncodingOptions,

Expand All @@ -40,7 +40,7 @@ pub struct CreateAccount {

/// Public Key of account you want to create
public_key: String,

/// Chain ID
chain_id: u8,
}
Expand Down
25 changes: 14 additions & 11 deletions crates/aptos/src/account/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -26,14 +27,16 @@ pub struct ListResources {
}

impl ListResources {
async fn get_resources(self) -> Result<Vec<serde_json::Value>, reqwest::Error> {
reqwest::get(format!(
"{}/accounts/{}/resources",
self.node.url, self.account
))
.await?
.json()
.await
async fn get_resources(self) -> Result<Vec<serde_json::Value>, Error> {
let client = Client::new(self.node.url);
let response: Vec<Resource> = client
.get_account_resources(self.account)
.await?
.into_inner();
Ok(response
.iter()
.map(|json| json.data.clone())
.collect::<Vec<serde_json::Value>>())
}

// TODO: Format this in a reasonable way while providing all information
Expand All @@ -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)
}
}

0 comments on commit 7d285e6

Please sign in to comment.