Skip to content

Commit 3fc0a92

Browse files
committed
Adds authority_signer_index to ProgramCliCommand::ExtendProgramChecked.
1 parent 51d34fd commit 3fc0a92

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

cli/src/program.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub enum ProgramCliCommand {
171171
},
172172
ExtendProgramChecked {
173173
program_pubkey: Pubkey,
174+
authority_signer_index: SignerIndex,
174175
additional_bytes: u32,
175176
},
176177
MigrateProgram {
@@ -1009,17 +1010,22 @@ pub fn parse_program_subcommand(
10091010
let program_pubkey = pubkey_of(matches, "program_id").unwrap();
10101011
let additional_bytes = value_of(matches, "additional_bytes").unwrap();
10111012

1013+
let (authority_signer, authority_pubkey) =
1014+
signer_of(matches, "authority", wallet_manager)?;
1015+
10121016
let signer_info = default_signer.generate_unique_signers(
1013-
vec![Some(
1014-
default_signer.signer_from_path(matches, wallet_manager)?,
1015-
)],
1017+
vec![
1018+
Some(default_signer.signer_from_path(matches, wallet_manager)?),
1019+
authority_signer,
1020+
],
10161021
matches,
10171022
wallet_manager,
10181023
)?;
10191024

10201025
CliCommandInfo {
10211026
command: CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
10221027
program_pubkey,
1028+
authority_signer_index: signer_info.index_of(authority_pubkey).unwrap(),
10231029
additional_bytes,
10241030
}),
10251031
signers: signer_info.signers,
@@ -1233,8 +1239,15 @@ pub fn process_program_subcommand(
12331239
),
12341240
ProgramCliCommand::ExtendProgramChecked {
12351241
program_pubkey,
1242+
authority_signer_index,
12361243
additional_bytes,
1237-
} => process_extend_program(&rpc_client, config, *program_pubkey, *additional_bytes),
1244+
} => process_extend_program(
1245+
&rpc_client,
1246+
config,
1247+
*program_pubkey,
1248+
*authority_signer_index,
1249+
*additional_bytes,
1250+
),
12381251
ProgramCliCommand::MigrateProgram {
12391252
program_pubkey,
12401253
authority_signer_index,
@@ -2366,9 +2379,11 @@ fn process_extend_program(
23662379
rpc_client: &RpcClient,
23672380
config: &CliConfig,
23682381
program_pubkey: Pubkey,
2382+
authority_signer_index: SignerIndex,
23692383
additional_bytes: u32,
23702384
) -> ProcessResult {
23712385
let payer_pubkey = config.signers[0].pubkey();
2386+
let authority_signer = config.signers[authority_signer_index];
23722387

23732388
if additional_bytes == 0 {
23742389
return Err("Additional bytes must be greater than zero".into());
@@ -2414,6 +2429,15 @@ fn process_extend_program(
24142429
let upgrade_authority_address = upgrade_authority_address
24152430
.ok_or_else(|| format!("Program {program_pubkey} is not upgradeable"))?;
24162431

2432+
if authority_signer.pubkey() != upgrade_authority_address {
2433+
return Err(format!(
2434+
"Upgrade authority {} does not match {}",
2435+
upgrade_authority_address,
2436+
authority_signer.pubkey(),
2437+
)
2438+
.into());
2439+
}
2440+
24172441
let blockhash = rpc_client.get_latest_blockhash()?;
24182442
let feature_set = fetch_feature_set(rpc_client)?;
24192443

@@ -2434,7 +2458,7 @@ fn process_extend_program(
24342458
};
24352459
let mut tx = Transaction::new_unsigned(Message::new(&[instruction], Some(&payer_pubkey)));
24362460

2437-
tx.try_sign(&[config.signers[0]], blockhash)?;
2461+
tx.try_sign(&[config.signers[0], authority_signer], blockhash)?;
24382462
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
24392463
&tx,
24402464
config.commitment,
@@ -4440,6 +4464,7 @@ mod tests {
44404464
CliCommandInfo {
44414465
command: CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
44424466
program_pubkey,
4467+
authority_signer_index: 0,
44434468
additional_bytes
44444469
}),
44454470
signers: vec![Box::new(read_keypair_file(&keypair_file).unwrap())],

cli/tests/program.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1443,9 +1443,10 @@ fn test_cli_program_extend_program() {
14431443
file.read_to_end(&mut new_program_data).unwrap();
14441444
let new_max_len = new_program_data.len();
14451445
let additional_bytes = (new_max_len - max_len) as u32;
1446-
config.signers = vec![&keypair];
1446+
config.signers = vec![&keypair, &upgrade_authority];
14471447
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
14481448
program_pubkey: program_keypair.pubkey(),
1449+
authority_signer_index: 1,
14491450
additional_bytes: additional_bytes - 1,
14501451
});
14511452
process_command(&config).unwrap();
@@ -1491,9 +1492,10 @@ fn test_cli_program_extend_program() {
14911492
wait_n_slots(&rpc_client, 1);
14921493

14931494
// Extend 1 last byte
1494-
config.signers = vec![&keypair];
1495+
config.signers = vec![&keypair, &upgrade_authority];
14951496
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
14961497
program_pubkey: program_keypair.pubkey(),
1498+
authority_signer_index: 1,
14971499
additional_bytes: 1,
14981500
});
14991501
process_command(&config).unwrap();

0 commit comments

Comments
 (0)