Add offline and fee-payer utilities to CLI vote module (#21579)
* create-vote-account: add offline, nonce, fee_payer capabilities * vote-authorize: add offline, nonce, fee-payer * vote-update-things: add offline, nonce, fee-payer * withdraw-vote: add offline, nonce, fee-payer * close-vote-acct: add fee-payer * Allow WithdrawVoteAccount to empty account, since offline operations cannot perform account state queries as in CloseVoteAccount * Fix lint * Update offline-signing docs * Add some parse unit tests * Add offline integration test
This commit is contained in:
parent
f493a88258
commit
873fe81bc0
129
cli/src/cli.rs
129
cli/src/cli.rs
|
@ -298,7 +298,13 @@ pub enum CliCommand {
|
||||||
authorized_voter: Option<Pubkey>,
|
authorized_voter: Option<Pubkey>,
|
||||||
authorized_withdrawer: Pubkey,
|
authorized_withdrawer: Pubkey,
|
||||||
commission: u8,
|
commission: u8,
|
||||||
|
sign_only: bool,
|
||||||
|
dump_transaction_message: bool,
|
||||||
|
blockhash_query: BlockhashQuery,
|
||||||
|
nonce_account: Option<Pubkey>,
|
||||||
|
nonce_authority: SignerIndex,
|
||||||
memo: Option<String>,
|
memo: Option<String>,
|
||||||
|
fee_payer: SignerIndex,
|
||||||
},
|
},
|
||||||
ShowVoteAccount {
|
ShowVoteAccount {
|
||||||
pubkey: Pubkey,
|
pubkey: Pubkey,
|
||||||
|
@ -310,19 +316,32 @@ pub enum CliCommand {
|
||||||
destination_account_pubkey: Pubkey,
|
destination_account_pubkey: Pubkey,
|
||||||
withdraw_authority: SignerIndex,
|
withdraw_authority: SignerIndex,
|
||||||
withdraw_amount: SpendAmount,
|
withdraw_amount: SpendAmount,
|
||||||
|
sign_only: bool,
|
||||||
|
dump_transaction_message: bool,
|
||||||
|
blockhash_query: BlockhashQuery,
|
||||||
|
nonce_account: Option<Pubkey>,
|
||||||
|
nonce_authority: SignerIndex,
|
||||||
memo: Option<String>,
|
memo: Option<String>,
|
||||||
|
fee_payer: SignerIndex,
|
||||||
},
|
},
|
||||||
CloseVoteAccount {
|
CloseVoteAccount {
|
||||||
vote_account_pubkey: Pubkey,
|
vote_account_pubkey: Pubkey,
|
||||||
destination_account_pubkey: Pubkey,
|
destination_account_pubkey: Pubkey,
|
||||||
withdraw_authority: SignerIndex,
|
withdraw_authority: SignerIndex,
|
||||||
memo: Option<String>,
|
memo: Option<String>,
|
||||||
|
fee_payer: SignerIndex,
|
||||||
},
|
},
|
||||||
VoteAuthorize {
|
VoteAuthorize {
|
||||||
vote_account_pubkey: Pubkey,
|
vote_account_pubkey: Pubkey,
|
||||||
new_authorized_pubkey: Pubkey,
|
new_authorized_pubkey: Pubkey,
|
||||||
vote_authorize: VoteAuthorize,
|
vote_authorize: VoteAuthorize,
|
||||||
|
sign_only: bool,
|
||||||
|
dump_transaction_message: bool,
|
||||||
|
blockhash_query: BlockhashQuery,
|
||||||
|
nonce_account: Option<Pubkey>,
|
||||||
|
nonce_authority: SignerIndex,
|
||||||
memo: Option<String>,
|
memo: Option<String>,
|
||||||
|
fee_payer: SignerIndex,
|
||||||
authorized: SignerIndex,
|
authorized: SignerIndex,
|
||||||
new_authorized: Option<SignerIndex>,
|
new_authorized: Option<SignerIndex>,
|
||||||
},
|
},
|
||||||
|
@ -330,13 +349,25 @@ pub enum CliCommand {
|
||||||
vote_account_pubkey: Pubkey,
|
vote_account_pubkey: Pubkey,
|
||||||
new_identity_account: SignerIndex,
|
new_identity_account: SignerIndex,
|
||||||
withdraw_authority: SignerIndex,
|
withdraw_authority: SignerIndex,
|
||||||
|
sign_only: bool,
|
||||||
|
dump_transaction_message: bool,
|
||||||
|
blockhash_query: BlockhashQuery,
|
||||||
|
nonce_account: Option<Pubkey>,
|
||||||
|
nonce_authority: SignerIndex,
|
||||||
memo: Option<String>,
|
memo: Option<String>,
|
||||||
|
fee_payer: SignerIndex,
|
||||||
},
|
},
|
||||||
VoteUpdateCommission {
|
VoteUpdateCommission {
|
||||||
vote_account_pubkey: Pubkey,
|
vote_account_pubkey: Pubkey,
|
||||||
commission: u8,
|
commission: u8,
|
||||||
withdraw_authority: SignerIndex,
|
withdraw_authority: SignerIndex,
|
||||||
|
sign_only: bool,
|
||||||
|
dump_transaction_message: bool,
|
||||||
|
blockhash_query: BlockhashQuery,
|
||||||
|
nonce_account: Option<Pubkey>,
|
||||||
|
nonce_authority: SignerIndex,
|
||||||
memo: Option<String>,
|
memo: Option<String>,
|
||||||
|
fee_payer: SignerIndex,
|
||||||
},
|
},
|
||||||
// Wallet Commands
|
// Wallet Commands
|
||||||
Address,
|
Address,
|
||||||
|
@ -1384,7 +1415,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
authorized_voter,
|
authorized_voter,
|
||||||
authorized_withdrawer,
|
authorized_withdrawer,
|
||||||
commission,
|
commission,
|
||||||
|
sign_only,
|
||||||
|
dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
ref nonce_account,
|
||||||
|
nonce_authority,
|
||||||
memo,
|
memo,
|
||||||
|
fee_payer,
|
||||||
} => process_create_vote_account(
|
} => process_create_vote_account(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
|
@ -1394,7 +1431,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
authorized_voter,
|
authorized_voter,
|
||||||
*authorized_withdrawer,
|
*authorized_withdrawer,
|
||||||
*commission,
|
*commission,
|
||||||
|
*sign_only,
|
||||||
|
*dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
nonce_account.as_ref(),
|
||||||
|
*nonce_authority,
|
||||||
memo.as_ref(),
|
memo.as_ref(),
|
||||||
|
*fee_payer,
|
||||||
),
|
),
|
||||||
CliCommand::ShowVoteAccount {
|
CliCommand::ShowVoteAccount {
|
||||||
pubkey: vote_account_pubkey,
|
pubkey: vote_account_pubkey,
|
||||||
|
@ -1412,7 +1455,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
withdraw_authority,
|
withdraw_authority,
|
||||||
withdraw_amount,
|
withdraw_amount,
|
||||||
destination_account_pubkey,
|
destination_account_pubkey,
|
||||||
|
sign_only,
|
||||||
|
dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
ref nonce_account,
|
||||||
|
nonce_authority,
|
||||||
memo,
|
memo,
|
||||||
|
fee_payer,
|
||||||
} => process_withdraw_from_vote_account(
|
} => process_withdraw_from_vote_account(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
|
@ -1420,13 +1469,20 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
*withdraw_authority,
|
*withdraw_authority,
|
||||||
*withdraw_amount,
|
*withdraw_amount,
|
||||||
destination_account_pubkey,
|
destination_account_pubkey,
|
||||||
|
*sign_only,
|
||||||
|
*dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
nonce_account.as_ref(),
|
||||||
|
*nonce_authority,
|
||||||
memo.as_ref(),
|
memo.as_ref(),
|
||||||
|
*fee_payer,
|
||||||
),
|
),
|
||||||
CliCommand::CloseVoteAccount {
|
CliCommand::CloseVoteAccount {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
withdraw_authority,
|
withdraw_authority,
|
||||||
destination_account_pubkey,
|
destination_account_pubkey,
|
||||||
memo,
|
memo,
|
||||||
|
fee_payer,
|
||||||
} => process_close_vote_account(
|
} => process_close_vote_account(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
|
@ -1434,12 +1490,19 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
*withdraw_authority,
|
*withdraw_authority,
|
||||||
destination_account_pubkey,
|
destination_account_pubkey,
|
||||||
memo.as_ref(),
|
memo.as_ref(),
|
||||||
|
*fee_payer,
|
||||||
),
|
),
|
||||||
CliCommand::VoteAuthorize {
|
CliCommand::VoteAuthorize {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
new_authorized_pubkey,
|
new_authorized_pubkey,
|
||||||
vote_authorize,
|
vote_authorize,
|
||||||
|
sign_only,
|
||||||
|
dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
nonce_account,
|
||||||
|
nonce_authority,
|
||||||
memo,
|
memo,
|
||||||
|
fee_payer,
|
||||||
authorized,
|
authorized,
|
||||||
new_authorized,
|
new_authorized,
|
||||||
} => process_vote_authorize(
|
} => process_vote_authorize(
|
||||||
|
@ -1450,33 +1513,63 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
*vote_authorize,
|
*vote_authorize,
|
||||||
*authorized,
|
*authorized,
|
||||||
*new_authorized,
|
*new_authorized,
|
||||||
|
*sign_only,
|
||||||
|
*dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
*nonce_account,
|
||||||
|
*nonce_authority,
|
||||||
memo.as_ref(),
|
memo.as_ref(),
|
||||||
|
*fee_payer,
|
||||||
),
|
),
|
||||||
CliCommand::VoteUpdateValidator {
|
CliCommand::VoteUpdateValidator {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
new_identity_account,
|
new_identity_account,
|
||||||
withdraw_authority,
|
withdraw_authority,
|
||||||
|
sign_only,
|
||||||
|
dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
nonce_account,
|
||||||
|
nonce_authority,
|
||||||
memo,
|
memo,
|
||||||
|
fee_payer,
|
||||||
} => process_vote_update_validator(
|
} => process_vote_update_validator(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
*new_identity_account,
|
*new_identity_account,
|
||||||
*withdraw_authority,
|
*withdraw_authority,
|
||||||
|
*sign_only,
|
||||||
|
*dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
*nonce_account,
|
||||||
|
*nonce_authority,
|
||||||
memo.as_ref(),
|
memo.as_ref(),
|
||||||
|
*fee_payer,
|
||||||
),
|
),
|
||||||
CliCommand::VoteUpdateCommission {
|
CliCommand::VoteUpdateCommission {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
commission,
|
commission,
|
||||||
withdraw_authority,
|
withdraw_authority,
|
||||||
|
sign_only,
|
||||||
|
dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
nonce_account,
|
||||||
|
nonce_authority,
|
||||||
memo,
|
memo,
|
||||||
|
fee_payer,
|
||||||
} => process_vote_update_commission(
|
} => process_vote_update_commission(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
*commission,
|
*commission,
|
||||||
*withdraw_authority,
|
*withdraw_authority,
|
||||||
|
*sign_only,
|
||||||
|
*dump_transaction_message,
|
||||||
|
blockhash_query,
|
||||||
|
*nonce_account,
|
||||||
|
*nonce_authority,
|
||||||
memo.as_ref(),
|
memo.as_ref(),
|
||||||
|
*fee_payer,
|
||||||
),
|
),
|
||||||
|
|
||||||
// Wallet Commands
|
// Wallet Commands
|
||||||
|
@ -1975,7 +2068,13 @@ mod tests {
|
||||||
authorized_voter: Some(bob_pubkey),
|
authorized_voter: Some(bob_pubkey),
|
||||||
authorized_withdrawer: bob_pubkey,
|
authorized_withdrawer: bob_pubkey,
|
||||||
commission: 0,
|
commission: 0,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
config.signers = vec![&keypair, &bob_keypair, &identity_keypair];
|
config.signers = vec![&keypair, &bob_keypair, &identity_keypair];
|
||||||
let result = process_command(&config);
|
let result = process_command(&config);
|
||||||
|
@ -2006,7 +2105,13 @@ mod tests {
|
||||||
vote_account_pubkey: bob_pubkey,
|
vote_account_pubkey: bob_pubkey,
|
||||||
new_authorized_pubkey,
|
new_authorized_pubkey,
|
||||||
vote_authorize: VoteAuthorize::Withdrawer,
|
vote_authorize: VoteAuthorize::Withdrawer,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
authorized: 0,
|
authorized: 0,
|
||||||
new_authorized: None,
|
new_authorized: None,
|
||||||
};
|
};
|
||||||
|
@ -2019,7 +2124,13 @@ mod tests {
|
||||||
vote_account_pubkey: bob_pubkey,
|
vote_account_pubkey: bob_pubkey,
|
||||||
new_identity_account: 2,
|
new_identity_account: 2,
|
||||||
withdraw_authority: 1,
|
withdraw_authority: 1,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
let result = process_command(&config);
|
let result = process_command(&config);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
@ -2195,7 +2306,13 @@ mod tests {
|
||||||
authorized_voter: Some(bob_pubkey),
|
authorized_voter: Some(bob_pubkey),
|
||||||
authorized_withdrawer: bob_pubkey,
|
authorized_withdrawer: bob_pubkey,
|
||||||
commission: 0,
|
commission: 0,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
config.signers = vec![&keypair, &bob_keypair, &identity_keypair];
|
config.signers = vec![&keypair, &bob_keypair, &identity_keypair];
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
@ -2204,7 +2321,13 @@ mod tests {
|
||||||
vote_account_pubkey: bob_pubkey,
|
vote_account_pubkey: bob_pubkey,
|
||||||
new_authorized_pubkey: bob_pubkey,
|
new_authorized_pubkey: bob_pubkey,
|
||||||
vote_authorize: VoteAuthorize::Voter,
|
vote_authorize: VoteAuthorize::Voter,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
authorized: 0,
|
authorized: 0,
|
||||||
new_authorized: None,
|
new_authorized: None,
|
||||||
};
|
};
|
||||||
|
@ -2214,7 +2337,13 @@ mod tests {
|
||||||
vote_account_pubkey: bob_pubkey,
|
vote_account_pubkey: bob_pubkey,
|
||||||
new_identity_account: 1,
|
new_identity_account: 1,
|
||||||
withdraw_authority: 1,
|
withdraw_authority: 1,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
|
||||||
|
|
857
cli/src/vote.rs
857
cli/src/vote.rs
File diff suppressed because it is too large
Load Diff
|
@ -59,7 +59,13 @@ fn test_stake_delegation_force() {
|
||||||
authorized_voter: None,
|
authorized_voter: None,
|
||||||
authorized_withdrawer,
|
authorized_withdrawer,
|
||||||
commission: 0,
|
commission: 0,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ use {
|
||||||
spend_utils::SpendAmount,
|
spend_utils::SpendAmount,
|
||||||
test_utils::check_recent_balance,
|
test_utils::check_recent_balance,
|
||||||
},
|
},
|
||||||
|
solana_cli_output::{parse_sign_only_reply_string, OutputFormat},
|
||||||
solana_client::{
|
solana_client::{
|
||||||
blockhash_query::{self, BlockhashQuery},
|
blockhash_query::{self, BlockhashQuery},
|
||||||
rpc_client::RpcClient,
|
rpc_client::RpcClient,
|
||||||
|
@ -12,7 +13,7 @@ use {
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, NullSigner, Signer},
|
||||||
},
|
},
|
||||||
solana_streamer::socket::SocketAddrSpace,
|
solana_streamer::socket::SocketAddrSpace,
|
||||||
solana_test_validator::TestValidator,
|
solana_test_validator::TestValidator,
|
||||||
|
@ -49,7 +50,13 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
authorized_voter: None,
|
authorized_voter: None,
|
||||||
authorized_withdrawer: config.signers[0].pubkey(),
|
authorized_withdrawer: config.signers[0].pubkey(),
|
||||||
commission: 0,
|
commission: 0,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let vote_account = rpc_client
|
let vote_account = rpc_client
|
||||||
|
@ -93,7 +100,13 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
new_authorized_pubkey: first_withdraw_authority.pubkey(),
|
new_authorized_pubkey: first_withdraw_authority.pubkey(),
|
||||||
vote_authorize: VoteAuthorize::Withdrawer,
|
vote_authorize: VoteAuthorize::Withdrawer,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
authorized: 0,
|
authorized: 0,
|
||||||
new_authorized: None,
|
new_authorized: None,
|
||||||
};
|
};
|
||||||
|
@ -112,7 +125,13 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
new_authorized_pubkey: withdraw_authority.pubkey(),
|
new_authorized_pubkey: withdraw_authority.pubkey(),
|
||||||
vote_authorize: VoteAuthorize::Withdrawer,
|
vote_authorize: VoteAuthorize::Withdrawer,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
authorized: 1,
|
authorized: 1,
|
||||||
new_authorized: Some(1),
|
new_authorized: Some(1),
|
||||||
};
|
};
|
||||||
|
@ -126,7 +145,13 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
new_authorized_pubkey: withdraw_authority.pubkey(),
|
new_authorized_pubkey: withdraw_authority.pubkey(),
|
||||||
vote_authorize: VoteAuthorize::Withdrawer,
|
vote_authorize: VoteAuthorize::Withdrawer,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
authorized: 1,
|
authorized: 1,
|
||||||
new_authorized: Some(2),
|
new_authorized: Some(2),
|
||||||
};
|
};
|
||||||
|
@ -146,7 +171,13 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
withdraw_authority: 1,
|
withdraw_authority: 1,
|
||||||
withdraw_amount: SpendAmount::Some(100),
|
withdraw_amount: SpendAmount::Some(100),
|
||||||
destination_account_pubkey: destination_account,
|
destination_account_pubkey: destination_account,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let expected_balance = expected_balance - 100;
|
let expected_balance = expected_balance - 100;
|
||||||
|
@ -160,7 +191,13 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
new_identity_account: 2,
|
new_identity_account: 2,
|
||||||
withdraw_authority: 1,
|
withdraw_authority: 1,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
|
@ -172,8 +209,283 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
withdraw_authority: 1,
|
withdraw_authority: 1,
|
||||||
destination_account_pubkey: destination_account,
|
destination_account_pubkey: destination_account,
|
||||||
memo: None,
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_recent_balance(0, &rpc_client, &vote_account_pubkey);
|
check_recent_balance(0, &rpc_client, &vote_account_pubkey);
|
||||||
check_recent_balance(expected_balance, &rpc_client, &destination_account);
|
check_recent_balance(expected_balance, &rpc_client, &destination_account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_offline_vote_authorize_and_withdraw() {
|
||||||
|
let mint_keypair = Keypair::new();
|
||||||
|
let mint_pubkey = mint_keypair.pubkey();
|
||||||
|
let faucet_addr = run_local_faucet(mint_keypair, None);
|
||||||
|
let test_validator =
|
||||||
|
TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
|
||||||
|
|
||||||
|
let rpc_client =
|
||||||
|
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
|
||||||
|
let default_signer = Keypair::new();
|
||||||
|
|
||||||
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
|
config_payer.json_rpc_url = test_validator.rpc_url();
|
||||||
|
config_payer.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
|
config_offline.json_rpc_url = String::default();
|
||||||
|
config_offline.command = CliCommand::ClusterVersion;
|
||||||
|
let offline_keypair = Keypair::new();
|
||||||
|
config_offline.signers = vec![&offline_keypair];
|
||||||
|
// Verify that we cannot reach the cluster
|
||||||
|
process_command(&config_offline).unwrap_err();
|
||||||
|
|
||||||
|
request_and_confirm_airdrop(
|
||||||
|
&rpc_client,
|
||||||
|
&config_payer,
|
||||||
|
&config_payer.signers[0].pubkey(),
|
||||||
|
100_000,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
check_recent_balance(100_000, &rpc_client, &config_payer.signers[0].pubkey());
|
||||||
|
|
||||||
|
request_and_confirm_airdrop(
|
||||||
|
&rpc_client,
|
||||||
|
&config_offline,
|
||||||
|
&config_offline.signers[0].pubkey(),
|
||||||
|
100_000,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
check_recent_balance(100_000, &rpc_client, &config_offline.signers[0].pubkey());
|
||||||
|
|
||||||
|
// Create vote account with specific withdrawer
|
||||||
|
let vote_account_keypair = Keypair::new();
|
||||||
|
let vote_account_pubkey = vote_account_keypair.pubkey();
|
||||||
|
config_payer.signers = vec![&default_signer, &vote_account_keypair];
|
||||||
|
config_payer.command = CliCommand::CreateVoteAccount {
|
||||||
|
vote_account: 1,
|
||||||
|
seed: None,
|
||||||
|
identity_account: 0,
|
||||||
|
authorized_voter: None,
|
||||||
|
authorized_withdrawer: offline_keypair.pubkey(),
|
||||||
|
commission: 0,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
process_command(&config_payer).unwrap();
|
||||||
|
let vote_account = rpc_client
|
||||||
|
.get_account(&vote_account_keypair.pubkey())
|
||||||
|
.unwrap();
|
||||||
|
let vote_state: VoteStateVersions = vote_account.state().unwrap();
|
||||||
|
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
|
||||||
|
assert_eq!(authorized_withdrawer, offline_keypair.pubkey());
|
||||||
|
let expected_balance = rpc_client
|
||||||
|
.get_minimum_balance_for_rent_exemption(VoteState::size_of())
|
||||||
|
.unwrap()
|
||||||
|
.max(1);
|
||||||
|
check_recent_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
||||||
|
|
||||||
|
// Transfer in some more SOL
|
||||||
|
config_payer.signers = vec![&default_signer];
|
||||||
|
config_payer.command = CliCommand::Transfer {
|
||||||
|
amount: SpendAmount::Some(1_000),
|
||||||
|
to: vote_account_pubkey,
|
||||||
|
from: 0,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
allow_unfunded_recipient: true,
|
||||||
|
no_wait: false,
|
||||||
|
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
derived_address_seed: None,
|
||||||
|
derived_address_program_id: None,
|
||||||
|
};
|
||||||
|
process_command(&config_payer).unwrap();
|
||||||
|
let expected_balance = expected_balance + 1_000;
|
||||||
|
check_recent_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
||||||
|
|
||||||
|
// Authorize vote account withdrawal to another signer, offline
|
||||||
|
let withdraw_authority = Keypair::new();
|
||||||
|
let blockhash = rpc_client.get_latest_blockhash().unwrap();
|
||||||
|
config_offline.command = CliCommand::VoteAuthorize {
|
||||||
|
vote_account_pubkey,
|
||||||
|
new_authorized_pubkey: withdraw_authority.pubkey(),
|
||||||
|
vote_authorize: VoteAuthorize::Withdrawer,
|
||||||
|
sign_only: true,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::None(blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
authorized: 0,
|
||||||
|
new_authorized: None,
|
||||||
|
};
|
||||||
|
config_offline.output_format = OutputFormat::JsonCompact;
|
||||||
|
let sig_response = process_command(&config_offline).unwrap();
|
||||||
|
let sign_only = parse_sign_only_reply_string(&sig_response);
|
||||||
|
assert!(sign_only.has_all_signers());
|
||||||
|
let offline_presigner = sign_only
|
||||||
|
.presigner_of(&config_offline.signers[0].pubkey())
|
||||||
|
.unwrap();
|
||||||
|
config_payer.signers = vec![&offline_presigner];
|
||||||
|
config_payer.command = CliCommand::VoteAuthorize {
|
||||||
|
vote_account_pubkey,
|
||||||
|
new_authorized_pubkey: withdraw_authority.pubkey(),
|
||||||
|
vote_authorize: VoteAuthorize::Withdrawer,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
authorized: 0,
|
||||||
|
new_authorized: None,
|
||||||
|
};
|
||||||
|
process_command(&config_payer).unwrap();
|
||||||
|
let vote_account = rpc_client
|
||||||
|
.get_account(&vote_account_keypair.pubkey())
|
||||||
|
.unwrap();
|
||||||
|
let vote_state: VoteStateVersions = vote_account.state().unwrap();
|
||||||
|
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
|
||||||
|
assert_eq!(authorized_withdrawer, withdraw_authority.pubkey());
|
||||||
|
|
||||||
|
// Withdraw from vote account offline
|
||||||
|
let destination_account = solana_sdk::pubkey::new_rand(); // Send withdrawal to new account to make balance check easy
|
||||||
|
let blockhash = rpc_client.get_latest_blockhash().unwrap();
|
||||||
|
let fee_payer_null_signer = NullSigner::new(&default_signer.pubkey());
|
||||||
|
config_offline.signers = vec![&fee_payer_null_signer, &withdraw_authority];
|
||||||
|
config_offline.command = CliCommand::WithdrawFromVoteAccount {
|
||||||
|
vote_account_pubkey,
|
||||||
|
withdraw_authority: 1,
|
||||||
|
withdraw_amount: SpendAmount::Some(100),
|
||||||
|
destination_account_pubkey: destination_account,
|
||||||
|
sign_only: true,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::None(blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
config_offline.output_format = OutputFormat::JsonCompact;
|
||||||
|
let sig_response = process_command(&config_offline).unwrap();
|
||||||
|
let sign_only = parse_sign_only_reply_string(&sig_response);
|
||||||
|
let offline_presigner = sign_only
|
||||||
|
.presigner_of(&config_offline.signers[1].pubkey())
|
||||||
|
.unwrap();
|
||||||
|
config_payer.signers = vec![&default_signer, &offline_presigner];
|
||||||
|
config_payer.command = CliCommand::WithdrawFromVoteAccount {
|
||||||
|
vote_account_pubkey,
|
||||||
|
withdraw_authority: 1,
|
||||||
|
withdraw_amount: SpendAmount::Some(100),
|
||||||
|
destination_account_pubkey: destination_account,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
process_command(&config_payer).unwrap();
|
||||||
|
let expected_balance = expected_balance - 100;
|
||||||
|
check_recent_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
||||||
|
check_recent_balance(100, &rpc_client, &destination_account);
|
||||||
|
|
||||||
|
// Re-assign validator identity offline
|
||||||
|
let blockhash = rpc_client.get_latest_blockhash().unwrap();
|
||||||
|
let new_identity_keypair = Keypair::new();
|
||||||
|
let new_identity_null_signer = NullSigner::new(&new_identity_keypair.pubkey());
|
||||||
|
config_offline.signers = vec![
|
||||||
|
&fee_payer_null_signer,
|
||||||
|
&withdraw_authority,
|
||||||
|
&new_identity_null_signer,
|
||||||
|
];
|
||||||
|
config_offline.command = CliCommand::VoteUpdateValidator {
|
||||||
|
vote_account_pubkey,
|
||||||
|
new_identity_account: 2,
|
||||||
|
withdraw_authority: 1,
|
||||||
|
sign_only: true,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::None(blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
process_command(&config_offline).unwrap();
|
||||||
|
config_offline.output_format = OutputFormat::JsonCompact;
|
||||||
|
let sig_response = process_command(&config_offline).unwrap();
|
||||||
|
let sign_only = parse_sign_only_reply_string(&sig_response);
|
||||||
|
let offline_presigner = sign_only
|
||||||
|
.presigner_of(&config_offline.signers[1].pubkey())
|
||||||
|
.unwrap();
|
||||||
|
config_payer.signers = vec![&default_signer, &offline_presigner, &new_identity_keypair];
|
||||||
|
config_payer.command = CliCommand::VoteUpdateValidator {
|
||||||
|
vote_account_pubkey,
|
||||||
|
new_identity_account: 2,
|
||||||
|
withdraw_authority: 1,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
process_command(&config_payer).unwrap();
|
||||||
|
|
||||||
|
// Close vote account offline. Must use WithdrawFromVoteAccount and specify amount, since
|
||||||
|
// CloseVoteAccount requires RpcClient
|
||||||
|
let destination_account = solana_sdk::pubkey::new_rand(); // Send withdrawal to new account to make balance check easy
|
||||||
|
config_offline.signers = vec![&fee_payer_null_signer, &withdraw_authority];
|
||||||
|
config_offline.command = CliCommand::WithdrawFromVoteAccount {
|
||||||
|
vote_account_pubkey,
|
||||||
|
withdraw_authority: 1,
|
||||||
|
withdraw_amount: SpendAmount::Some(expected_balance),
|
||||||
|
destination_account_pubkey: destination_account,
|
||||||
|
sign_only: true,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::None(blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
process_command(&config_offline).unwrap();
|
||||||
|
config_offline.output_format = OutputFormat::JsonCompact;
|
||||||
|
let sig_response = process_command(&config_offline).unwrap();
|
||||||
|
let sign_only = parse_sign_only_reply_string(&sig_response);
|
||||||
|
let offline_presigner = sign_only
|
||||||
|
.presigner_of(&config_offline.signers[1].pubkey())
|
||||||
|
.unwrap();
|
||||||
|
config_payer.signers = vec![&default_signer, &offline_presigner];
|
||||||
|
config_payer.command = CliCommand::WithdrawFromVoteAccount {
|
||||||
|
vote_account_pubkey,
|
||||||
|
withdraw_authority: 1,
|
||||||
|
withdraw_amount: SpendAmount::Some(expected_balance),
|
||||||
|
destination_account_pubkey: destination_account,
|
||||||
|
sign_only: false,
|
||||||
|
dump_transaction_message: false,
|
||||||
|
blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
|
||||||
|
nonce_account: None,
|
||||||
|
nonce_authority: 0,
|
||||||
|
memo: None,
|
||||||
|
fee_payer: 0,
|
||||||
|
};
|
||||||
|
let result = process_command(&config_payer).unwrap();
|
||||||
|
println!("{:?}", result);
|
||||||
|
check_recent_balance(0, &rpc_client, &vote_account_pubkey);
|
||||||
|
println!("what");
|
||||||
|
check_recent_balance(expected_balance, &rpc_client, &destination_account);
|
||||||
|
}
|
||||||
|
|
|
@ -19,14 +19,26 @@ transaction.
|
||||||
At present, the following commands support offline signing:
|
At present, the following commands support offline signing:
|
||||||
|
|
||||||
- [`create-stake-account`](cli/usage.md#solana-create-stake-account)
|
- [`create-stake-account`](cli/usage.md#solana-create-stake-account)
|
||||||
|
- [`create-stake-account-checked`](cli/usage.md#solana-create-stake-account-checked)
|
||||||
- [`deactivate-stake`](cli/usage.md#solana-deactivate-stake)
|
- [`deactivate-stake`](cli/usage.md#solana-deactivate-stake)
|
||||||
- [`delegate-stake`](cli/usage.md#solana-delegate-stake)
|
- [`delegate-stake`](cli/usage.md#solana-delegate-stake)
|
||||||
- [`split-stake`](cli/usage.md#solana-split-stake)
|
- [`split-stake`](cli/usage.md#solana-split-stake)
|
||||||
- [`stake-authorize`](cli/usage.md#solana-stake-authorize)
|
- [`stake-authorize`](cli/usage.md#solana-stake-authorize)
|
||||||
|
- [`stake-authorize-checked`](cli/usage.md#solana-stake-authorize-checked)
|
||||||
- [`stake-set-lockup`](cli/usage.md#solana-stake-set-lockup)
|
- [`stake-set-lockup`](cli/usage.md#solana-stake-set-lockup)
|
||||||
|
- [`stake-set-lockup-checked`](cli/usage.md#solana-stake-set-lockup-checked)
|
||||||
- [`transfer`](cli/usage.md#solana-transfer)
|
- [`transfer`](cli/usage.md#solana-transfer)
|
||||||
- [`withdraw-stake`](cli/usage.md#solana-withdraw-stake)
|
- [`withdraw-stake`](cli/usage.md#solana-withdraw-stake)
|
||||||
|
|
||||||
|
- [`create-vote-account`](cli/usage.md#solana-create-vote-account)
|
||||||
|
- [`vote-authorize-voter`](cli/usage.md#solana-vote-authorize-voter)
|
||||||
|
- [`vote-authorize-voter-checked`](cli/usage.md#solana-vote-authorize-voter-checked)
|
||||||
|
- [`vote-authorize-withdrawer`](cli/usage.md#solana-vote-authorize-withdrawer)
|
||||||
|
- [`vote-authorize-withdrawer-checked`](cli/usage.md#solana-vote-authorize-withdrawer-checked)
|
||||||
|
- [`vote-update-commission`](cli/usage.md#solana-vote-update-commission)
|
||||||
|
- [`vote-update-validator`](cli/usage.md#solana-vote-update-validator)
|
||||||
|
- [`withdraw-from-vote-account`](cli/usage.md#solana-withdraw-from-vote-account)
|
||||||
|
|
||||||
## Signing Transactions Offline
|
## Signing Transactions Offline
|
||||||
|
|
||||||
To sign a transaction offline, pass the following arguments on the command line
|
To sign a transaction offline, pass the following arguments on the command line
|
||||||
|
|
Loading…
Reference in New Issue