Skip to content

Commit 62f5b70

Browse files
authored
Refactor - Adds CLI parameter "--with-compute-unit-price" to program-v4 (anza-xyz#5086)
* Changes underscore to dash for consistency. * Adds helper closure for constructing messages. * Removes the closure parameter from calculate_max_chunk_size(). * Adds "--with-compute-unit-price". * Sends both instructions of process_close_program() in a single transaction. * Factors redundant code into a message_factory().
1 parent 844c1b3 commit 62f5b70

File tree

3 files changed

+151
-99
lines changed

3 files changed

+151
-99
lines changed

cargo-registry/src/crate_handler.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl Program {
132132
None..None,
133133
Some(signer),
134134
false,
135+
None,
135136
)
136137
.map_err(|e| {
137138
error!("Failed to deploy the program: {}", e);

cli/src/program.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -2551,11 +2551,7 @@ fn process_migrate_program(
25512551
}))
25522552
}
25532553

2554-
pub fn calculate_max_chunk_size<F>(create_msg: &F) -> usize
2555-
where
2556-
F: Fn(u32, Vec<u8>) -> Message,
2557-
{
2558-
let baseline_msg = create_msg(0, Vec::new());
2554+
pub fn calculate_max_chunk_size(baseline_msg: Message) -> usize {
25592555
let tx_size = bincode::serialized_size(&Transaction {
25602556
signatures: vec![
25612557
Signature::default();
@@ -2637,7 +2633,7 @@ fn do_process_program_deploy(
26372633
};
26382634

26392635
let mut write_messages = vec![];
2640-
let chunk_size = calculate_max_chunk_size(&create_msg);
2636+
let chunk_size = calculate_max_chunk_size(create_msg(0, Vec::new()));
26412637
for (chunk, i) in program_data.chunks(chunk_size).zip(0usize..) {
26422638
let offset = i.saturating_mul(chunk_size);
26432639
if chunk != &buffer_program_data[offset..offset.saturating_add(chunk.len())] {
@@ -2770,7 +2766,7 @@ fn do_process_write_buffer(
27702766
};
27712767

27722768
let mut write_messages = vec![];
2773-
let chunk_size = calculate_max_chunk_size(&create_msg);
2769+
let chunk_size = calculate_max_chunk_size(create_msg(0, Vec::new()));
27742770
for (chunk, i) in program_data.chunks(chunk_size).zip(0usize..) {
27752771
let offset = i.saturating_mul(chunk_size);
27762772
if chunk != &buffer_program_data[offset..offset.saturating_add(chunk.len())] {
@@ -2895,7 +2891,7 @@ fn do_process_program_upgrade(
28952891

28962892
// Create and add write messages
28972893
let mut write_messages = vec![];
2898-
let chunk_size = calculate_max_chunk_size(&create_msg);
2894+
let chunk_size = calculate_max_chunk_size(create_msg(0, Vec::new()));
28992895
for (chunk, i) in program_data.chunks(chunk_size).zip(0usize..) {
29002896
let offset = i.saturating_mul(chunk_size);
29012897
if chunk != &buffer_program_data[offset..offset.saturating_add(chunk.len())] {

0 commit comments

Comments
 (0)