Skip to content

Commit

Permalink
create query view for validator config
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 31, 2023
1 parent ef35292 commit 0ba7a6f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tools/genesis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion tools/query/src/account_queries.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -33,3 +33,12 @@ pub async fn get_tower_state(
.get_move_resource::<TowerProofHistoryView>(account)
.await
}

pub async fn get_val_config(
client: &Client,
account: AccountAddress,
) -> anyhow::Result<ValidatorConfig> {
client
.get_move_resource::<ValidatorConfig>(account)
.await
}
20 changes: 18 additions & 2 deletions tools/query/src/query_type.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -143,7 +149,6 @@ impl QueryType {
QueryType::Tower { account } => {
let res = get_tower_state(&client, *account).await?;
Ok(json!(res))

},
QueryType::View {
function_id,
Expand Down Expand Up @@ -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!(),
Expand Down

0 comments on commit 0ba7a6f

Please sign in to comment.