Skip to content

Commit

Permalink
cli helps update, and commands order
Browse files Browse the repository at this point in the history
  • Loading branch information
prekucki committed Aug 13, 2019
1 parent ada4502 commit 1020e02
Show file tree
Hide file tree
Showing 21 changed files with 471 additions and 351 deletions.
2 changes: 1 addition & 1 deletion golem-rpc-api/src/pay.rs
Expand Up @@ -18,7 +18,7 @@ rpc_interface! {
fn get_deposit_payments_list(&self, #[kwarg] _limit : Option<usize>, #[kwarg] _offset : Option<usize>) -> Result<Option<Vec<DepositPayment>>>;

#[id = "pay.deposit_balance"]
fn get_deposit_balance(&self) -> Result<DepositBalance>;
fn get_deposit_balance(&self) -> Result<Option<DepositBalance>>;

#[id = "pay.balance"]
fn get_pay_balance(&self) -> Result<Balance>;
Expand Down
2 changes: 1 addition & 1 deletion golem-rpc-macros/src/settings.rs
Expand Up @@ -435,7 +435,7 @@ pub fn gen_settings(mut f: syn::File) -> Fallible<TokenStream> {
Ok((quote! {
#(#sections_q )*

pub fn from_name(setting_name : &str) -> Option<&DynamicSetting> {
pub fn from_name(setting_name : &str) -> Option<&'static DynamicSetting> {
match setting_name {
#(#from_name_rules)*
_ => None
Expand Down
2 changes: 1 addition & 1 deletion golemcli/Cargo.toml
Expand Up @@ -39,7 +39,7 @@ rpassword = "3.0.2"
rustc-hex = "2.0"
serde={ version ="1.0", features=["derive"]}

serde_json = "1.0.39"
serde_json = { version = "1.0.39", features= ["preserve_order"]}
serde_yaml = "0.8"
sha2 = "0.8.0"
structopt="0.2.15"
Expand Down
87 changes: 50 additions & 37 deletions golemcli/src/commands.rs
Expand Up @@ -30,68 +30,81 @@ mod resources;
pub enum CommandSection {
/// Manage account
#[structopt(name = "account")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Account(account::AccountSection),

/// Concent Service
#[cfg(feature = "concent_cli")]
#[structopt(name = "concent")]
Concent(concent::Section),

/// Debug RPC
#[cfg(feature = "debug_cli")]
#[structopt(name = "debug")]
Debug(debug::Section),

/// Manage environments
#[structopt(name = "envs")]
Envs(envs::Section),

/// Manage network
#[structopt(name = "network")]
Network(network::NetworkSection),

/// Manage peer access control lists
#[structopt(name = "acl")]
Acl(acl::Section),
/// Display general status
#[structopt(name = "status")]
Status(status::Section),

/// Display incomes
#[structopt(name = "incomes")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Incomes(incomes::Section),

/// Display payments
#[structopt(name = "payments")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Payments(payments::Section),

/// Manage disc cache
#[structopt(name = "cache")]
Cache(cache::Section),

/// Manage provider resuorces
#[structopt(name = "res")]
Res(resources::Section),
/// Manage network
#[structopt(name = "network")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Network(network::NetworkSection),

/// Manage settings
#[structopt(name = "settings")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Settings(settings::Section),

/// Manage provider resuorces
#[structopt(name = "res")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Res(resources::Section),

/// Manage tasks
#[structopt(name = "tasks")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Tasks(tasks::Section),

/// Display general status
#[structopt(name = "status")]
Status(status::Section),

/// Show and accept terms of use
#[structopt(name = "terms")]
Terms(terms::Section),

/// Manage testing tasks
#[cfg(feature = "test_task_cli")]
#[structopt(name = "test_task")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
TestTask(test_task::Section),

/// Trigger graceful shutdown of Golem
/// Manage peer access control lists
#[structopt(name = "acl")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Acl(acl::Section),

/// Manage environments
#[structopt(name = "envs")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Envs(envs::Section),

/// Concent Service
#[cfg(feature = "concent_cli")]
#[structopt(name = "concent")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Concent(concent::Section),

/// Manage disc cache
#[structopt(name = "cache")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Cache(cache::Section),

/// Debug RPC
#[cfg(feature = "debug_cli")]
#[structopt(name = "debug")]
Debug(debug::Section),

/// Show and accept terms of use
#[structopt(name = "terms")]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
Terms(terms::Section),

/// Quit after finishing ongoing tasks
#[structopt(name = "shutdown")]
Shutdown(ShutdownCommand),

Expand Down
51 changes: 29 additions & 22 deletions golemcli/src/commands/account.rs
Expand Up @@ -6,19 +6,18 @@ use failure::Fallible;
use futures::{future, prelude::*};
use golem_rpc_api::core::AsGolemCore;
use golem_rpc_api::net::AsGolemNet;
use golem_rpc_api::pay::{AsGolemPay, Balance};
use golem_rpc_api::pay::{AsGolemPay, Balance, DepositBalance};
use golem_rpc_api::rpc::*;
use serde::{Deserialize, Serialize};
use structopt::StructOpt;
use structopt::{clap, StructOpt};
use crate::formaters::*;

#[derive(StructOpt, Debug)]
#[structopt(raw(setting = "clap::AppSettings::DeriveDisplayOrder"))]
pub enum AccountSection {
/// Display account & financial info
#[structopt(name = "info")]
Info,
/// Unlock account, will prompt for your password
#[structopt(name = "unlock")]
Unlock,

/// Withdraw GNT/ETH (withdrawals are not available for the testnet)
#[structopt(name = "withdraw")]
Expand All @@ -32,6 +31,9 @@ pub enum AccountSection {
/// Gas price in wei (not gwei)
gas_price: Option<bigdecimal::BigDecimal>,
},
/// Unlock account, will prompt for your password
#[structopt(name = "unlock")]
Unlock,
}

impl AccountSection {
Expand Down Expand Up @@ -119,12 +121,23 @@ impl AccountSection {
}
}

#[derive(Serialize)]
struct AccountInfo {
#[serde(rename="Golem_ID")]
golem_id : String,
node_name : String,
requestor_reputation : u64,
provider_reputation : u64,
finances : serde_json::Value
}

fn account_info(
endpoint: impl actix_wamp::RpcEndpoint + Clone + 'static,
) -> impl Future<Item = CommandResponse, Error = Error> + 'static {
endpoint
.as_golem_net()
.get_node()
.from_err()
.and_then(move |node: golem_rpc_api::net::NodeInfo| {
let query = {
let node_id = node.key.to_string();
Expand All @@ -136,13 +149,13 @@ fn account_info(
.rpc_call("rep.requesting", &(node_id,));
let payment_address = endpoint.as_golem_pay().get_pay_ident().from_err();
let balance = endpoint.as_golem_pay().get_pay_balance().from_err();
let deposit_balance = endpoint.as_invoker().rpc_call("pay.deposit_balance", &());
let deposit_balance = endpoint.as_golem_pay().get_deposit_balance();

computing_trust.join5(requesting_trust, payment_address, balance, deposit_balance)
};

// TODO: deposit_balance formating
query.and_then(
query.from_err().and_then(
move |(
computing_trust,
requesting_trust,
Expand All @@ -162,21 +175,21 @@ fn account_info(
let gnt_unadopted = Currency::GNT.format_decimal(&balance.gnt_nonconverted);
let gnt_locked = Currency::GNT.format_decimal(&balance.gnt_lock);

Ok(CommandResponse::Object(serde_json::json!({
"node_name": node.node_name,
"Golem_ID": node.key,
"requestor_reputation": (requesting_trust.unwrap_or_default()*100.0) as u64,
"provider_reputation": (computing_trust.unwrap_or_default()*100.0) as u64,
"finances": {
CommandResponse::object(AccountInfo {
node_name: node.node_name,
golem_id: node.key,
requestor_reputation: (requesting_trust.unwrap_or_default()*100.0) as u64,
provider_reputation: (computing_trust.unwrap_or_default()*100.0) as u64,
finances: serde_json::json!({
"eth_address": payment_address,
"eth_available": eth_available,
"eth_locked": eth_locked,
"gnt_available": gnt_available,
"gnt_locked": gnt_locked,
"gnt_unadopted": gnt_unadopted,
"deposit_balance": deposit_balance
}
})))
"deposit_balance": deposit_balance.map(|b : golem_rpc_api::pay::DepositBalance| b.humanize())
})
})
},
)
})
Expand All @@ -191,9 +204,3 @@ enum DepositStatus {
Unlocked,
}

#[derive(Deserialize, Serialize)]
struct DepositBalance {
value: String,
status: DepositStatus,
timelock: String,
}

0 comments on commit 1020e02

Please sign in to comment.