From bf4ac99c146d09629260465f007f4e7a9786cab1 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Sat, 3 Jun 2023 23:24:36 +0200 Subject: [PATCH] add some runtime constants --- src/commands/runtime.rs | 45 ++++++++++++++++++++++++++++++++++++----- src/data.rs | 5 ++++- src/main.rs | 5 ++++- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/commands/runtime.rs b/src/commands/runtime.rs index be6ee97..8238d8c 100644 --- a/src/commands/runtime.rs +++ b/src/commands/runtime.rs @@ -1,8 +1,43 @@ use crate::*; -pub async fn runtime_info(_data: Data) -> () { - // TODO get information from runtime - // certification duration for example - println!("TODO"); - () +pub async fn runtime_info(data: Data) -> () { + let api = data.client(); + + // certifications + let cert_period = api + .constants() + .at(&runtime::constants().cert().cert_period()) + .unwrap(); + let max_by_issuer = api + .constants() + .at(&runtime::constants().cert().max_by_issuer()) + .unwrap(); + let validity_period = api + .constants() + .at(&runtime::constants().cert().validity_period()) + .unwrap(); + + println!("certification period: {cert_period} blocks"); + println!("max certs by issuer: {max_by_issuer}"); + println!("certification validity: {validity_period} blocks"); + + // account + let new_account_price = api + .constants() + .at(&runtime::constants().account().new_account_price()) + .unwrap(); + // balances + let existential_deposit = api + .constants() + .at(&runtime::constants().balances().existential_deposit()) + .unwrap(); + + println!( + "new account price: {}", + data.format_balance(new_account_price) + ); + println!( + "existential deposit: {}", + data.format_balance(existential_deposit) + ); } diff --git a/src/data.rs b/src/data.rs index 58d1418..8639b9d 100644 --- a/src/data.rs +++ b/src/data.rs @@ -103,7 +103,10 @@ impl Data { /// build a client from url // TODO get client from a pre-defined list pub async fn build_client(mut self) -> Self { - self.client = Some(Client::from_url(&self.args.url).await.expect("needed")); + self.client = Some(Client::from_url(&self.args.url).await.expect(&format!( + "could not establish connection with the server {}", + self.args.url + ))); self } /// build an indexer if not disabled diff --git a/src/main.rs b/src/main.rs index fbdf1e8..a656192 100644 --- a/src/main.rs +++ b/src/main.rs @@ -563,7 +563,10 @@ async fn main() -> Result<(), GcliError> { ) .await .unwrap(), - Subcommand::RuntimeInfo => commands::runtime::runtime_info(data).await, + Subcommand::RuntimeInfo => { + data = data.build_client().await.fetch_system_properties().await?; + commands::runtime::runtime_info(data).await; + } Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?, } -- GitLab