Add show-vote-account command (#3814)
This commit is contained in:
@ -148,19 +148,15 @@ setup_vote_account() {
|
|||||||
|
|
||||||
if [[ -f "$vote_id_path".configured ]]; then
|
if [[ -f "$vote_id_path".configured ]]; then
|
||||||
echo "Vote account has already been configured"
|
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
|
fi
|
||||||
|
|
||||||
# A fullnode requires 43 lamports to function:
|
$solana_wallet --host "$drone_address" show-vote-account "$vote_id"
|
||||||
# - 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
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(
|
||||||
SubCommand::with_name("deploy")
|
SubCommand::with_name("deploy")
|
||||||
.about("Deploy a program")
|
.about("Deploy a program")
|
||||||
|
@ -38,6 +38,7 @@ pub enum WalletCommand {
|
|||||||
// ConfigureStakingAccount(delegate_id, authorized_voter_id)
|
// ConfigureStakingAccount(delegate_id, authorized_voter_id)
|
||||||
AuthorizeVoter(Pubkey),
|
AuthorizeVoter(Pubkey),
|
||||||
CreateVoteAccount(Pubkey, Pubkey, u32, u64),
|
CreateVoteAccount(Pubkey, Pubkey, u32, u64),
|
||||||
|
ShowVoteAccount(Pubkey),
|
||||||
Deploy(String),
|
Deploy(String),
|
||||||
GetTransactionCount,
|
GetTransactionCount,
|
||||||
// Pay(lamports, to, timestamp, timestamp_pubkey, witness(es), cancelable)
|
// Pay(lamports, to, timestamp, timestamp_pubkey, witness(es), cancelable)
|
||||||
@ -184,6 +185,10 @@ pub fn parse_command(
|
|||||||
lamports,
|
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", Some(deploy_matches)) => Ok(WalletCommand::Deploy(
|
||||||
deploy_matches
|
deploy_matches
|
||||||
.value_of("program_location")
|
.value_of("program_location")
|
||||||
@ -368,6 +373,43 @@ fn process_create_staking(
|
|||||||
Ok(signature_str.to_string())
|
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(
|
fn process_deploy(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &WalletConfig,
|
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
|
// Deploy a custom program to the chain
|
||||||
WalletCommand::Deploy(ref program_location) => {
|
WalletCommand::Deploy(ref program_location) => {
|
||||||
process_deploy(&rpc_client, config, program_location)
|
process_deploy(&rpc_client, config, program_location)
|
||||||
|
Reference in New Issue
Block a user