Solana-wallet: prevent duplicate pubkeys (#5497)
* Add helper function to compare wallet pubkey args for uniqueness * Fix test
This commit is contained in:
parent
c68ebbb0a6
commit
b6151b5200
|
@ -435,6 +435,20 @@ fn check_account_for_multiple_fees(
|
||||||
Err(WalletError::InsufficientFundsForFee)?
|
Err(WalletError::InsufficientFundsForFee)?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_unique_pubkeys(
|
||||||
|
pubkey0: (&Pubkey, String),
|
||||||
|
pubkey1: (&Pubkey, String),
|
||||||
|
) -> Result<(), WalletError> {
|
||||||
|
if pubkey0.0 == pubkey1.0 {
|
||||||
|
Err(WalletError::BadParameter(format!(
|
||||||
|
"Identical pubkeys found: `{}` and `{}` must be unique",
|
||||||
|
pubkey0.1, pubkey1.1
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn process_fees(rpc_client: &RpcClient) -> ProcessResult {
|
fn process_fees(rpc_client: &RpcClient) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||||
|
|
||||||
|
@ -522,6 +536,10 @@ fn process_create_vote_account(
|
||||||
commission: u8,
|
commission: u8,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
|
check_unique_pubkeys(
|
||||||
|
(vote_account_pubkey, "vote_account_pubkey".to_string()),
|
||||||
|
(node_pubkey, "node_pubkey".to_string()),
|
||||||
|
)?;
|
||||||
let ixs = vote_instruction::create_account(
|
let ixs = vote_instruction::create_account(
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
|
@ -544,6 +562,13 @@ fn process_authorize_voter(
|
||||||
authorized_voter_keypair: &Keypair,
|
authorized_voter_keypair: &Keypair,
|
||||||
new_authorized_voter_pubkey: &Pubkey,
|
new_authorized_voter_pubkey: &Pubkey,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
|
check_unique_pubkeys(
|
||||||
|
(vote_account_pubkey, "vote_account_pubkey".to_string()),
|
||||||
|
(
|
||||||
|
new_authorized_voter_pubkey,
|
||||||
|
"new_authorized_voter_pubkey".to_string(),
|
||||||
|
),
|
||||||
|
)?;
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||||
let ixs = vec![vote_instruction::authorize_voter(
|
let ixs = vec![vote_instruction::authorize_voter(
|
||||||
vote_account_pubkey, // vote account to update
|
vote_account_pubkey, // vote account to update
|
||||||
|
@ -2334,7 +2359,9 @@ mod tests {
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
|
||||||
let bob_keypair = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
config.command = WalletCommand::AuthorizeVoter(bob_pubkey, bob_keypair, bob_pubkey);
|
let new_authorized_voter_pubkey = Pubkey::new_rand();
|
||||||
|
config.command =
|
||||||
|
WalletCommand::AuthorizeVoter(bob_pubkey, bob_keypair, new_authorized_voter_pubkey);
|
||||||
let signature = process_command(&config);
|
let signature = process_command(&config);
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue