Skip to content

Commit e93ec72

Browse files
committed
Adjusts CLI parser.
1 parent bc37372 commit e93ec72

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

cli/src/program.rs

+24-17
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub enum ProgramCliCommand {
169169
use_lamports_unit: bool,
170170
bypass_warning: bool,
171171
},
172-
ExtendProgram {
172+
ExtendProgramChecked {
173173
program_pubkey: Pubkey,
174174
additional_bytes: u32,
175175
},
@@ -1018,7 +1018,7 @@ pub fn parse_program_subcommand(
10181018
)?;
10191019

10201020
CliCommandInfo {
1021-
command: CliCommand::Program(ProgramCliCommand::ExtendProgram {
1021+
command: CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
10221022
program_pubkey,
10231023
additional_bytes,
10241024
}),
@@ -1231,7 +1231,7 @@ pub fn process_program_subcommand(
12311231
*use_lamports_unit,
12321232
*bypass_warning,
12331233
),
1234-
ProgramCliCommand::ExtendProgram {
1234+
ProgramCliCommand::ExtendProgramChecked {
12351235
program_pubkey,
12361236
additional_bytes,
12371237
} => process_extend_program(&rpc_client, config, *program_pubkey, *additional_bytes),
@@ -2411,21 +2411,28 @@ fn process_extend_program(
24112411
_ => Err(format!("Program {program_pubkey} is closed")),
24122412
}?;
24132413

2414-
match upgrade_authority_address {
2415-
None => Err(format!("Program {program_pubkey} is not upgradeable")),
2416-
_ => Ok(()),
2417-
}?;
2414+
let upgrade_authority_address = upgrade_authority_address
2415+
.ok_or_else(|| format!("Program {program_pubkey} is not upgradeable"))?;
24182416

24192417
let blockhash = rpc_client.get_latest_blockhash()?;
2420-
2421-
let mut tx = Transaction::new_unsigned(Message::new(
2422-
&[loader_v3_instruction::extend_program(
2423-
&program_pubkey,
2424-
Some(&payer_pubkey),
2425-
additional_bytes,
2426-
)],
2427-
Some(&payer_pubkey),
2428-
));
2418+
let feature_set = fetch_feature_set(rpc_client)?;
2419+
2420+
let instruction =
2421+
if feature_set.is_active(&agave_feature_set::enable_extend_program_checked::id()) {
2422+
loader_v3_instruction::extend_program_checked(
2423+
&program_pubkey,
2424+
&upgrade_authority_address,
2425+
Some(&payer_pubkey),
2426+
additional_bytes,
2427+
)
2428+
} else {
2429+
loader_v3_instruction::extend_program(
2430+
&program_pubkey,
2431+
Some(&payer_pubkey),
2432+
additional_bytes,
2433+
)
2434+
};
2435+
let mut tx = Transaction::new_unsigned(Message::new(&[instruction], Some(&payer_pubkey)));
24292436

24302437
tx.try_sign(&[config.signers[0]], blockhash)?;
24312438
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
@@ -4406,7 +4413,7 @@ mod tests {
44064413
assert_eq!(
44074414
parse_command(&test_command, &default_signer, &mut None).unwrap(),
44084415
CliCommandInfo {
4409-
command: CliCommand::Program(ProgramCliCommand::ExtendProgram {
4416+
command: CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
44104417
program_pubkey,
44114418
additional_bytes
44124419
}),

cli/tests/program.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ fn test_cli_program_extend_program() {
14451445
let new_max_len = new_program_data.len();
14461446
let additional_bytes = (new_max_len - max_len) as u32;
14471447
config.signers = vec![&keypair];
1448-
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgram {
1448+
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
14491449
program_pubkey: program_keypair.pubkey(),
14501450
additional_bytes: additional_bytes - 1,
14511451
});
@@ -1493,7 +1493,7 @@ fn test_cli_program_extend_program() {
14931493

14941494
// Extend 1 last byte
14951495
config.signers = vec![&keypair];
1496-
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgram {
1496+
config.command = CliCommand::Program(ProgramCliCommand::ExtendProgramChecked {
14971497
program_pubkey: program_keypair.pubkey(),
14981498
additional_bytes: 1,
14991499
});

0 commit comments

Comments
 (0)