@ -48,7 +48,9 @@ pub enum WalletCommand {
|
||||
CreateVoteAccount(Pubkey, Pubkey, u32, u64),
|
||||
ShowVoteAccount(Pubkey),
|
||||
CreateStakeAccount(Pubkey, u64),
|
||||
CreateMiningPoolAccount(Pubkey, u64),
|
||||
DelegateStake(Keypair, Pubkey),
|
||||
RedeemVoteCredits(Pubkey, Pubkey, Pubkey),
|
||||
ShowStakeAccount(Pubkey),
|
||||
Deploy(String),
|
||||
GetTransactionCount,
|
||||
@ -216,6 +218,14 @@ pub fn parse_command(
|
||||
lamports,
|
||||
))
|
||||
}
|
||||
("create-mining-pool-account", Some(matches)) => {
|
||||
let mining_pool_account_id = pubkey_of(matches, "mining_pool_account_id").unwrap();
|
||||
let lamports = matches.value_of("lamports").unwrap().parse()?;
|
||||
Ok(WalletCommand::CreateMiningPoolAccount(
|
||||
mining_pool_account_id,
|
||||
lamports,
|
||||
))
|
||||
}
|
||||
("delegate-stake", Some(matches)) => {
|
||||
let staking_account_keypair =
|
||||
keypair_of(matches, "staking_account_keypair_file").unwrap();
|
||||
@ -225,6 +235,16 @@ pub fn parse_command(
|
||||
voting_account_id,
|
||||
))
|
||||
}
|
||||
("redeem-vote-credits", Some(matches)) => {
|
||||
let mining_pool_account_id = pubkey_of(matches, "mining_pool_account_id").unwrap();
|
||||
let staking_account_id = pubkey_of(matches, "staking_account_id").unwrap();
|
||||
let voting_account_id = pubkey_of(matches, "voting_account_id").unwrap();
|
||||
Ok(WalletCommand::RedeemVoteCredits(
|
||||
mining_pool_account_id,
|
||||
staking_account_id,
|
||||
voting_account_id,
|
||||
))
|
||||
}
|
||||
("show-stake-account", Some(matches)) => {
|
||||
let staking_account_id = pubkey_of(matches, "staking_account_id").unwrap();
|
||||
Ok(WalletCommand::ShowStakeAccount(staking_account_id))
|
||||
@ -469,11 +489,28 @@ fn process_create_stake_account(
|
||||
lamports: u64,
|
||||
) -> ProcessResult {
|
||||
let (recent_blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||
let ixs = vec![stake_instruction::create_account(
|
||||
let ixs = stake_instruction::create_delegate_account(
|
||||
&config.keypair.pubkey(),
|
||||
staking_account_id,
|
||||
lamports,
|
||||
)];
|
||||
);
|
||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
}
|
||||
|
||||
fn process_create_mining_pool_account(
|
||||
rpc_client: &RpcClient,
|
||||
config: &WalletConfig,
|
||||
mining_pool_account_id: &Pubkey,
|
||||
lamports: u64,
|
||||
) -> ProcessResult {
|
||||
let (recent_blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||
let ixs = stake_instruction::create_mining_pool_account(
|
||||
&config.keypair.pubkey(),
|
||||
mining_pool_account_id,
|
||||
lamports,
|
||||
);
|
||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
@ -501,6 +538,25 @@ fn process_delegate_stake(
|
||||
Ok(signature_str.to_string())
|
||||
}
|
||||
|
||||
fn process_redeem_vote_credits(
|
||||
rpc_client: &RpcClient,
|
||||
config: &WalletConfig,
|
||||
mining_pool_account_id: &Pubkey,
|
||||
staking_account_id: &Pubkey,
|
||||
voting_account_id: &Pubkey,
|
||||
) -> ProcessResult {
|
||||
let (recent_blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||
let ixs = vec![stake_instruction::redeem_vote_credits(
|
||||
&config.keypair.pubkey(),
|
||||
mining_pool_account_id,
|
||||
staking_account_id,
|
||||
voting_account_id,
|
||||
)];
|
||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
}
|
||||
|
||||
fn process_show_stake_account(
|
||||
rpc_client: &RpcClient,
|
||||
_config: &WalletConfig,
|
||||
@ -518,6 +574,10 @@ fn process_show_stake_account(
|
||||
println!("credits observed: {}", credits_observed);
|
||||
Ok("".to_string())
|
||||
}
|
||||
Ok(StakeState::MiningPool) => {
|
||||
println!("account lamports: {}", stake_account.lamports);
|
||||
Ok("".to_string())
|
||||
}
|
||||
_ => Err(WalletError::RpcRequestError(
|
||||
"Account data could not be deserialized to stake state".to_string(),
|
||||
))?,
|
||||
@ -813,7 +873,15 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
|
||||
process_create_stake_account(&rpc_client, config, &staking_account_id, *lamports)
|
||||
}
|
||||
|
||||
// Create stake account
|
||||
WalletCommand::CreateMiningPoolAccount(mining_pool_account_id, lamports) => {
|
||||
process_create_mining_pool_account(
|
||||
&rpc_client,
|
||||
config,
|
||||
&mining_pool_account_id,
|
||||
*lamports,
|
||||
)
|
||||
}
|
||||
|
||||
WalletCommand::DelegateStake(staking_account_keypair, voting_account_id) => {
|
||||
process_delegate_stake(
|
||||
&rpc_client,
|
||||
@ -822,6 +890,19 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
|
||||
&voting_account_id,
|
||||
)
|
||||
}
|
||||
|
||||
WalletCommand::RedeemVoteCredits(
|
||||
mining_pool_account_id,
|
||||
staking_account_id,
|
||||
voting_account_id,
|
||||
) => process_redeem_vote_credits(
|
||||
&rpc_client,
|
||||
config,
|
||||
&mining_pool_account_id,
|
||||
&staking_account_id,
|
||||
&voting_account_id,
|
||||
),
|
||||
|
||||
// Show a vote account
|
||||
WalletCommand::ShowStakeAccount(staking_account_id) => {
|
||||
process_show_stake_account(&rpc_client, config, &staking_account_id)
|
||||
@ -1099,6 +1180,27 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("create-mining-pool-account")
|
||||
.about("Create mining pool account")
|
||||
.arg(
|
||||
Arg::with_name("mining_pool_account_id")
|
||||
.index(1)
|
||||
.value_name("PUBKEY")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.validator(is_pubkey)
|
||||
.help("Staking account address to fund"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("lamports")
|
||||
.index(2)
|
||||
.value_name("NUM")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.help("The number of lamports to assign to the mining pool account"),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("create-stake-account")
|
||||
.about("Create staking account")
|
||||
.arg(
|
||||
@ -1141,6 +1243,37 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("redeem-vote-credits")
|
||||
.about("Redeem credits in the staking account")
|
||||
.arg(
|
||||
Arg::with_name("mining_pool_account_id")
|
||||
.index(1)
|
||||
.value_name("PUBKEY")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.validator(is_pubkey)
|
||||
.help("Mining pool account to redeem credits from"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("staking_account_id")
|
||||
.index(2)
|
||||
.value_name("PUBKEY")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.validator(is_pubkey)
|
||||
.help("Staking account address to redeem credits for"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("voting_account_id")
|
||||
.index(3)
|
||||
.value_name("PUBKEY")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.validator(is_pubkey)
|
||||
.help("The voting account to which the stake was previously delegated."),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("show-stake-account")
|
||||
.about("Show the contents of a stake account")
|
||||
.arg(
|
||||
|
Reference in New Issue
Block a user