Add show-vote-account command (#3814)

This commit is contained in:
Michael Vines 2019-04-17 07:45:07 -07:00 committed by GitHub
parent b9bb5af4a5
commit aa6c82cfdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 11 deletions

View File

@ -148,19 +148,15 @@ setup_vote_account() {
if [[ -f "$vote_id_path".configured ]]; then
echo "Vote account has already been configured"
return 0
else
airdrop "$node_id_path" "$drone_address" "$stake" || return $?
# Fund the vote account from the node, with the node as the node_id
$solana_wallet --keypair "$node_id_path" --host "$drone_address" \
create-vote-account "$vote_id" "$node_id" $((stake - 1)) || return $?
fi
# A fullnode requires 43 lamports to function:
# - one lamport to keep the node identity public key valid. TODO: really??
# - 42 more for the vote account we fund
airdrop "$node_id_path" "$drone_address" "$stake" || return $?
# Fund the vote account from the node, with the node as the node_id
$solana_wallet --keypair "$node_id_path" --host "$drone_address" \
create-vote-account "$vote_id" "$node_id" $((stake - 1)) || return $?
touch "$vote_id_path".configured
$solana_wallet --host "$drone_address" show-vote-account "$vote_id"
return 0
}

View File

@ -268,6 +268,19 @@ fn main() -> Result<(), Box<dyn error::Error>> {
),
)
.subcommand(
SubCommand::with_name("show-vote-account")
.about("Show the contents of a vote account")
.arg(
Arg::with_name("voting_account_id")
.index(1)
.value_name("PUBKEY")
.takes_value(true)
.required(true)
.validator(is_pubkey)
.help("Vote account pubkey"),
)
)
.subcommand(
SubCommand::with_name("deploy")
.about("Deploy a program")

View File

@ -38,6 +38,7 @@ pub enum WalletCommand {
// ConfigureStakingAccount(delegate_id, authorized_voter_id)
AuthorizeVoter(Pubkey),
CreateVoteAccount(Pubkey, Pubkey, u32, u64),
ShowVoteAccount(Pubkey),
Deploy(String),
GetTransactionCount,
// Pay(lamports, to, timestamp, timestamp_pubkey, witness(es), cancelable)
@ -184,6 +185,10 @@ pub fn parse_command(
lamports,
))
}
("show-vote-account", Some(matches)) => {
let voting_account_id = pubkey_of(matches, "voting_account_id").unwrap();
Ok(WalletCommand::ShowVoteAccount(voting_account_id))
}
("deploy", Some(deploy_matches)) => Ok(WalletCommand::Deploy(
deploy_matches
.value_of("program_location")
@ -368,6 +373,43 @@ fn process_create_staking(
Ok(signature_str.to_string())
}
fn process_show_staking(
rpc_client: &RpcClient,
_config: &WalletConfig,
voting_account_id: &Pubkey,
) -> ProcessResult {
use solana_vote_api::vote_state::VoteState;
let vote_account_lamports = rpc_client.retry_get_balance(voting_account_id, 5)?;
let vote_account_data = rpc_client.get_account_data(voting_account_id)?;
let vote_state = VoteState::deserialize(&vote_account_data).unwrap();
println!("account lamports: {}", vote_account_lamports.unwrap());
println!("node id: {}", vote_state.node_id);
println!("authorized voter id: {}", vote_state.authorized_voter_id);
println!("credits: {}", vote_state.credits());
println!(
"commission: {}%",
f64::from(vote_state.commission) / f64::from(std::u32::MAX)
);
println!(
"root slot: {}",
match vote_state.root_slot {
Some(slot) => slot.to_string(),
None => "~".to_string(),
}
);
if !vote_state.votes.is_empty() {
println!("votes:");
for vote in vote_state.votes {
println!(
"- slot={}, confirmation count={}",
vote.slot, vote.confirmation_count
);
}
}
Ok("".to_string())
}
fn process_deploy(
rpc_client: &RpcClient,
config: &WalletConfig,
@ -635,6 +677,10 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
)
}
WalletCommand::ShowVoteAccount(voting_account_id) => {
process_show_staking(&rpc_client, config, &voting_account_id)
}
// Deploy a custom program to the chain
WalletCommand::Deploy(ref program_location) => {
process_deploy(&rpc_client, config, program_location)