Skip to content
Permalink
Browse files

Create JCLI REST command for getting account state

  • Loading branch information...
CodeSandwich committed May 15, 2019
1 parent bd6073a commit 3bb5c61145835e96459b31377c690e5ed1d9952e
Showing with 40 additions and 0 deletions.
  1. +36 −0 src/bin/jcli_app/rest/v0/account/mod.rs
  2. +4 −0 src/bin/jcli_app/rest/v0/mod.rs
@@ -0,0 +1,36 @@
use jcli_app::utils::HostAddr;
use structopt::StructOpt;

#[derive(StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub enum Account {
/// Get account state
Get {
#[structopt(flatten)]
addr: HostAddr,
/// ID of an account, bech32-encoded
account_id: String,
},
}

impl Account {
pub fn exec(self) {
let (addr, account_id) = match self {
Account::Get { addr, account_id } => (addr, account_id),
};
let url = addr
.with_segments(&["v0", "account", &account_id])
.unwrap()
.into_url();
let state: serde_json::Value = reqwest::Client::new()
.get(url)
.send()
.unwrap()
.error_for_status()
.unwrap()
.json()
.unwrap();
let state_yaml = serde_yaml::to_string(&state).unwrap();
println!("{}", state_yaml);
}
}
@@ -1,3 +1,4 @@
mod account;
mod block;
mod message;
mod node;
@@ -9,6 +10,8 @@ use structopt::StructOpt;
#[derive(StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub enum V0 {
/// Account operations
Account(account::Account),
/// Block operations
Block(block::Block),
/// Message sending
@@ -24,6 +27,7 @@ pub enum V0 {
impl V0 {
pub fn exec(self) {
match self {
V0::Account(account) => account.exec(),
V0::Block(block) => block.exec(),
V0::Message(message) => message.exec(),
V0::Node(node) => node.exec(),

0 comments on commit 3bb5c61

Please sign in to comment.
You can’t perform that action at this time.