From 0ba7a6f2838c30d1df8505c470e80c80d7332bb0 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Tue, 31 Oct 2023 02:15:13 +0000 Subject: [PATCH] create query view for validator config --- tools/genesis/Makefile | 4 ++-- tools/query/src/account_queries.rs | 11 ++++++++++- tools/query/src/query_type.rs | 20 ++++++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/genesis/Makefile b/tools/genesis/Makefile index 8dd398b26..2a02f1aab 100644 --- a/tools/genesis/Makefile +++ b/tools/genesis/Makefile @@ -41,7 +41,7 @@ genesis: --target-future-uses ${FUTURE_USES} \ --years-escrow ${YEARS} \ --map-dd-to-slow 3A6C51A0B786D644590E8A21591FA8E2 \ - --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 + --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 wizard: @@ -54,7 +54,7 @@ wizard: --target-future-uses ${FUTURE_USES} \ --years-escrow ${YEARS} \ --map-dd-to-slow 3A6C51A0B786D644590E8A21591FA8E2 \ - --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 + --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 stdlib: cargo r -p libra-framework -- release diff --git a/tools/query/src/account_queries.rs b/tools/query/src/account_queries.rs index 95f0d03a7..40f5d0c66 100644 --- a/tools/query/src/account_queries.rs +++ b/tools/query/src/account_queries.rs @@ -1,6 +1,6 @@ use diem_sdk::{ rest_client::{diem_api_types::ViewRequest, Client}, - types::account_address::AccountAddress, + types::{account_address::AccountAddress, validator_config::ValidatorConfig}, }; use libra_types::{ legacy_types::tower::TowerProofHistoryView, @@ -33,3 +33,12 @@ pub async fn get_tower_state( .get_move_resource::(account) .await } + +pub async fn get_val_config( + client: &Client, + account: AccountAddress, +) -> anyhow::Result { + client + .get_move_resource::(account) + .await +} \ No newline at end of file diff --git a/tools/query/src/query_type.rs b/tools/query/src/query_type.rs index 40e15b1c0..0c973e49c 100644 --- a/tools/query/src/query_type.rs +++ b/tools/query/src/query_type.rs @@ -1,5 +1,5 @@ use crate::{ - account_queries::{get_account_balance_libra, get_tower_state}, + account_queries::{get_account_balance_libra, get_tower_state, get_val_config}, query_view::get_view, }; use anyhow::{bail, Result}; @@ -23,6 +23,12 @@ pub enum QueryType { /// account to query txs of account: AccountAddress, }, + /// A validator's on-chain configuration + ValConfig { + #[clap(short, long)] + /// account to query txs of + account: AccountAddress, + }, /// Epoch and waypoint Epoch, /// Network block height @@ -143,7 +149,6 @@ impl QueryType { QueryType::Tower { account } => { let res = get_tower_state(&client, *account).await?; Ok(json!(res)) - }, QueryType::View { function_id, @@ -181,6 +186,17 @@ impl QueryType { bail!("no resource {resource_path_string}, found at address {account}"); } }, + QueryType::ValConfig { account } => { + let res = get_val_config(&client, *account).await?; + + // make this readable, turn the network address into a string + Ok(json!({ + "consensus_public_key": res.consensus_public_key, + "validator_network_addresses": res.validator_network_addresses().unwrap(), + "fullnode_network_addresses": res.fullnode_network_addresses().unwrap(), + "validator_index": res.validator_index, + })) + } _ => { bail!("Not implemented for type: {:?}\n Ground control to major tom.", self) } // QueryType::BlockHeight => todo!(),