Skip to content

Commit

Permalink
[tools] remove tbd query subcommands (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally authored and hemulin committed Nov 7, 2023
1 parent 41c0274 commit 0596d77
Showing 1 changed file with 86 additions and 90 deletions.
176 changes: 86 additions & 90 deletions tools/query/src/query_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<u64>,
#[clap(long)]
/// limit how many txs
txs_count: Option<u64>,
#[clap(long)]
/// filter by type
txs_type: Option<String>,
},
// 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<u64>,
// #[clap(long)]
// /// limit how many txs
// txs_count: Option<u64>,
// #[clap(long)]
// /// filter by type
// txs_type: Option<String>,
// },
// /// Get events
// Events {
// /// account to query events
Expand All @@ -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<String> = serde_json::from_value(res)?;
let json = json!({
"epoch": num.first().unwrap().parse::<u64>()?,
});
Ok(json)
},
QueryType::LookupAddress { auth_key } => {
let addr = client.lookup_originating_address( auth_key.to_owned()).await?;
let num: Vec<String> = serde_json::from_value(res)?;
let json = json!({
"epoch": num.first().unwrap().parse::<u64>()?,
});
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!(),

}
}
}

0 comments on commit 0596d77

Please sign in to comment.