From 95435c1ad08dad0767ea283babe54e205442e35a Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:02:12 -0400 Subject: [PATCH] [tools] remove tbd query subcommands (#76) --- tools/query/src/query_type.rs | 176 +++++++++++++++++----------------- 1 file changed, 86 insertions(+), 90 deletions(-) diff --git a/tools/query/src/query_type.rs b/tools/query/src/query_type.rs index 0b32ab199..3ddf28f95 100644 --- a/tools/query/src/query_type.rs +++ b/tools/query/src/query_type.rs @@ -31,10 +31,8 @@ pub enum QueryType { }, /// Epoch and waypoint Epoch, - /// Network block height - BlockHeight, /// All account resources - Resources { + Resource { #[clap(short, long)] /// account to query txs of account: AccountAddress, @@ -85,39 +83,26 @@ pub enum QueryType { #[clap(short, long)] auth_key: AuthenticationKey, // we use account address to parse, because that's the format needed to lookup users. AuthKeys and AccountAddress are the same formats. }, - - /// get a move value from account blob - MoveValue { - #[clap(short, long)] - /// account to query txs of - account: AccountAddress, - #[clap(long)] - /// move module name - module_name: String, - #[clap(long)] - /// move struct name - struct_name: String, - #[clap(long)] - /// move key name - key_name: String, - }, /// How far behind the local is from the upstream nodes SyncDelay, - /// Get transaction history - Txs { - #[clap(short, long)] - /// account to query txs of - account: AccountAddress, - #[clap(long)] - /// get transactions after this height - txs_height: Option, - #[clap(long)] - /// limit how many txs - txs_count: Option, - #[clap(long)] - /// filter by type - txs_type: Option, - }, + // TODO: + // /// Network block height + // BlockHeight, + // /// Get transaction history + // Txs { + // #[clap(short, long)] + // /// account to query txs of + // account: AccountAddress, + // #[clap(long)] + // /// get transactions after this height + // txs_height: Option, + // #[clap(long)] + // /// limit how many txs + // txs_count: Option, + // #[clap(long)] + // /// filter by type + // txs_type: Option, + // }, // /// Get events // Events { // /// account to query events @@ -137,66 +122,77 @@ impl QueryType { }; match self { - QueryType::Balance { account } => { - let res = get_account_balance_libra(&client, *account).await?; - Ok(json!(res.scaled())) - }, - QueryType::Tower { account } => { - let res = get_tower_state(&client, *account).await?; - Ok(json!(res)) - }, - QueryType::View { - function_id, - type_args, - args, - } => { - let res = get_view(&client, function_id, type_args.to_owned(), args.to_owned()).await?; - let json = json!({ - "body": res - }); - Ok(json) - }, - QueryType::Epoch => { - let res = get_view(&client, "0x1::reconfiguration::get_current_epoch", None, None).await?; + QueryType::Balance { account } => { + let res = get_account_balance_libra(&client, *account).await?; + Ok(json!(res.scaled())) + } + QueryType::Tower { account } => { + let res = get_tower_state(&client, *account).await?; + Ok(json!(res)) + } + QueryType::View { + function_id, + type_args, + args, + } => { + let res = + get_view(&client, function_id, type_args.to_owned(), args.to_owned()).await?; + let json = json!({ "body": res }); + Ok(json) + } + QueryType::Epoch => { + let res = get_view( + &client, + "0x1::reconfiguration::get_current_epoch", + None, + None, + ) + .await?; - let num: Vec = serde_json::from_value(res)?; - let json = json!({ - "epoch": num.first().unwrap().parse::()?, - }); - Ok(json) - }, - QueryType::LookupAddress { auth_key } => { - let addr = client.lookup_originating_address( auth_key.to_owned()).await?; + let num: Vec = serde_json::from_value(res)?; + let json = json!({ + "epoch": num.first().unwrap().parse::()?, + }); + Ok(json) + } + QueryType::LookupAddress { auth_key } => { + let addr = client + .lookup_originating_address(auth_key.to_owned()) + .await?; - Ok(json!({ - "address": addr - })) - }, - QueryType::Resources { account , resource_path_string} => { - let res = client.get_account_resource(*account, resource_path_string).await?; + Ok(json!({ "address": addr })) + } + QueryType::Resource { + account, + resource_path_string, + } => { + let res = client + .get_account_resource(*account, resource_path_string) + .await?; - if let Some(r) = res.inner() { - Ok(r.data.clone()) - } else { - bail!("no resource {resource_path_string}, found at address {account}"); - } - }, - QueryType::ValConfig { account } => { - let res = get_val_config(&client, *account).await?; + if let Some(r) = res.inner() { + Ok(r.data.clone()) + } else { + 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().context("can't BCS decode the validator network address")?, - "fullnode_network_addresses": res.validator_network_addresses().context("can't BCS decode the fullnode network address")?, - "validator_index": res.validator_index, - })) + // 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().context("can't BCS decode the validator network address")?, + "fullnode_network_addresses": res.validator_network_addresses().context("can't BCS decode the fullnode network address")?, + "validator_index": res.validator_index, + })) + } + _ => { + bail!( + "Not implemented for type: {:?}\n Ground control to major tom.", + self + ) + } } - - _ => { bail!("Not implemented for type: {:?}\n Ground control to major tom.", self) } - // QueryType::BlockHeight => todo!(), - // QueryType::MoveValue { account, module_name, struct_name, key_name } => todo!(), - - } } }