From 04869cd2a13e8315d9d3d8e43a719d459185d32b Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Wed, 17 Jan 2024 13:05:05 +0100 Subject: [PATCH] more runtime info --- README.md | 11 ++- src/commands/distance.rs | 9 +- src/commands/identity.rs | 3 +- src/commands/runtime.rs | 177 ++++++++++++++++++++++++++++++++------- src/commands/smith.rs | 28 ++----- 5 files changed, 168 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 742ffb1..f6f9e80 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,14 @@ Secret key format can be changed using `--secret-format` with the following valu - [x] implement config formatter - [x] add link/unlink account commands -- [ ] migrate all xt to submit_call_and_look_event -- [ ] add transfer with unit (ÄžD, UD...) -- [ ] add more runtime-info like cert count, sudo key... +- [x] migrate all xt to submit_call_and_look_event +- [x] add transfer with unit (ÄžD, UD...) +- [x] add more runtime-info like cert count, wot and smith params... +- [ ] add more info like sudo key, block interval +- [ ] better format runtime info block number (duration in days...) and perbill (%) +- [ ] add proper tabulation for runtime info +- [ ] add clap complete for autocompletion +- [ ] allow to listen to multiple events (like CertAdded and CertRenewed) - [ ] add more info on identity view like status, number certs emitted, received - [ ] implement squid indexer to get cert list + tx history... - [ ] diff --git a/src/commands/distance.rs b/src/commands/distance.rs index ba13b09..8ced4e1 100644 --- a/src/commands/distance.rs +++ b/src/commands/distance.rs @@ -13,13 +13,18 @@ pub async fn request_distance_evaluation(data: &Data) -> Result<(), subxt::Error } /// request distance evaluation for someone else (must be unvalidated) -pub async fn request_distance_evaluation_for(data: &Data, target: IdtyId) -> Result<(), subxt::Error> { +pub async fn request_distance_evaluation_for( + data: &Data, + target: IdtyId, +) -> Result<(), subxt::Error> { submit_call_and_look_event::< runtime::distance::events::EvaluationRequested, Payload<runtime::distance::calls::types::RequestDistanceEvaluationFor>, >( data, - &runtime::tx().distance().request_distance_evaluation_for(target), + &runtime::tx() + .distance() + .request_distance_evaluation_for(target), ) .await } diff --git a/src/commands/identity.rs b/src/commands/identity.rs index ccf51a7..52abae5 100644 --- a/src/commands/identity.rs +++ b/src/commands/identity.rs @@ -93,7 +93,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE Subcommand::RequestDistanceEvaluation => { commands::distance::request_distance_evaluation(&data).await?; } - Subcommand::RequestDistanceEvaluationFor {target} => { + Subcommand::RequestDistanceEvaluationFor { target } => { commands::distance::request_distance_evaluation_for(&data, target).await?; } Subcommand::Certify { target } => { @@ -275,7 +275,6 @@ pub async fn confirm_identity(data: &Data, name: String) -> Result<(), subxt::Er .await } - /// generate revokation document and submit it immediately pub async fn revoke_identity(data: &Data) -> Result<(), subxt::Error> { let (_payload, signature) = generate_revoc_doc(data); diff --git a/src/commands/runtime.rs b/src/commands/runtime.rs index afed9ab..0d75ea8 100644 --- a/src/commands/runtime.rs +++ b/src/commands/runtime.rs @@ -2,42 +2,155 @@ use crate::*; pub async fn runtime_info(data: Data) { let api = data.client(); + let consts = runtime::constants(); + // get constant u32 value + let getu32 = |c| api.constants().at(&c).unwrap(); + // get constant u64 value + let getu64 = |c| api.constants().at(&c).unwrap(); + // get constant perbill value + let getp = |c| api.constants().at(&c).unwrap(); + // get formatted currency value + let getf = |c| data.format_balance(api.constants().at(&c).unwrap()); - // certifications - let cert_period = api - .constants() - .at(&runtime::constants().certification().cert_period()) - .unwrap(); - let max_by_issuer = api - .constants() - .at(&runtime::constants().certification().max_by_issuer()) - .unwrap(); - let validity_period = api - .constants() - .at(&runtime::constants().certification().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(); - + // identity + println!("--- identity ---"); + println!( + "confirm period: {} blocks", + getu32(consts.identity().confirm_period()) + ); + println!( + "validation period: {} blocks", + getu32(consts.identity().validation_period()) + ); + println!( + "autorevocation period: {} blocks", + getu32(consts.identity().autorevocation_period()) + ); + println!( + "deletion period: {} blocks", + getu32(consts.identity().deletion_period()) + ); + println!( + "change owner key period: {} blocks", + getu32(consts.identity().change_owner_key_period()) + ); + println!( + "identity creation period: {} blocks", + getu32(consts.identity().idty_creation_period()) + ); + // certification + println!("--- certification ---"); + println!( + "certification period: {} blocks", + getu32(consts.certification().cert_period()) + ); + println!( + "max certs by issuer: {}", + getu32(consts.certification().max_by_issuer()) + ); + println!( + "min received cert to issue cert: {}", + getu32(consts.certification().min_received_cert_to_be_able_to_issue_cert()) + ); + println!( + "certification validity: {} blocks", + getu32(consts.certification().validity_period()) + ); + // wot + println!("--- wot ---"); + println!( + "first issuable on: {}", + getu32(consts.wot().first_issuable_on()) + ); + println!( + "min cert for membership: {}", + getu32(consts.wot().min_cert_for_membership()) + ); + println!( + "min cert for create identity: {}", + getu32(consts.wot().min_cert_for_create_idty_right()) + ); + // membership + println!("--- membership ---"); + println!( + "membership validity: {} blocks", + getu32(consts.membership().membership_period()) + ); + // smith members + println!("--- smith members ---"); + println!( + "max certs by issuer: {}", + getu32(consts.smith_members().max_by_issuer()) + ); + println!( + "min cert for membership: {}", + getu32(consts.smith_members().min_cert_for_membership()) + ); + println!( + "smith inactivity max duration: {}", + getu32(consts.smith_members().smith_inactivity_max_duration()) + ); + // todo membership renewal period + // distance + println!("--- distance ---"); + println!( + "max referee distance: {}", + getu32(consts.distance().max_referee_distance()) + ); + println!( + "min accessible referees: {:?}", + getp(consts.distance().min_accessible_referees()) + ); + println!( + "distance evaluation price: {}", + getf(consts.distance().evaluation_price()) + ); + // currency + println!("--- currency ---"); println!( "new account price: {}", - data.format_balance(new_account_price) + getf(consts.account().new_account_price()) + ); + println!( + "max new accounts per block: {}", + getu32(consts.account().max_new_accounts_per_block()) ); println!( "existential deposit: {}", - data.format_balance(existential_deposit) + getf(consts.balances().existential_deposit()) + ); + // provide randomness + println!("--- provide randomness ---"); + println!( + "max requests: {}", + getu32(consts.provide_randomness().max_requests()) + ); + println!( + "request price: {}", + getf(consts.provide_randomness().request_price()) + ); + // universal dividend + println!("--- universal dividend ---"); + println!( + "max past reevals: {}", + getu32(consts.universal_dividend().max_past_reeval()) + ); + println!( + "square money growth rate: {:?}", + getp(consts.universal_dividend().square_money_growth_rate()) + ); + println!( + "UD creation period: {}", + getu64(consts.universal_dividend().ud_creation_period()) + ); + println!( + "UD reeval period: {}", + getu64(consts.universal_dividend().ud_reeval_period()) + ); + println!( + "units per ud: {}", + getf(consts.universal_dividend().units_per_ud()) ); -} + // todo treasury, technical committee, transaction payment, authority members + // consts.system().ss58_prefix() +} \ No newline at end of file diff --git a/src/commands/smith.rs b/src/commands/smith.rs index 682474c..0081468 100644 --- a/src/commands/smith.rs +++ b/src/commands/smith.rs @@ -57,11 +57,11 @@ pub enum Subcommand { /// List online authorities ShowOnline, /// Invite identity to become smith - Invite{target: IdtyId}, + Invite { target: IdtyId }, /// Accept invitation Accept, /// Certify smith - Certify{target: IdtyId}, + Certify { target: IdtyId }, } /// handle smith commands @@ -90,18 +90,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE data = data.build_indexer().await?; commands::expire::monitor_expirations(&data, blocks, sessions).await? } - Subcommand::ShowOnline => { - online(&data).await? - } - Subcommand::Invite { target } => { - invite_smith(&data, target).await? - } - Subcommand::Accept => { - accept_invitation(&data).await? - } - Subcommand::Certify { target } => { - certify_smith(&data, target).await? - } + Subcommand::ShowOnline => online(&data).await?, + Subcommand::Invite { target } => invite_smith(&data, target).await?, + Subcommand::Accept => accept_invitation(&data).await?, + Subcommand::Certify { target } => certify_smith(&data, target).await?, }; Ok(()) @@ -294,13 +286,7 @@ pub async fn certify_smith(data: &Data, target: IdtyId) -> Result<(), subxt::Err // Payload<runtime::smith_members::calls::types::CertifySmith>, // >(data, &runtime::tx().smith_members().certify_smith(target)) // .await - let progress = submit_call( - data, - &runtime::tx() - .smith_members() - .certify_smith(target), - ) - .await?; + let progress = submit_call(data, &runtime::tx().smith_members().certify_smith(target)).await?; if data.args.no_wait { return Ok(()); } -- GitLab