From 00b46d6d9d2cce97e42c99773c89206d1a3e0aea Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 16 Mar 2023 20:12:58 +0100 Subject: [PATCH] Indent functions This fixes indentatiion that was intentionally "messed up" to make code review easier. --- bitcoin/src/blockdata/transaction.rs | 38 ++++++++++++++-------------- bitcoin/src/consensus/encode.rs | 28 ++++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 160d57dd..b2260460 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -1251,25 +1251,25 @@ pub fn predict_weight(inputs: I, output_script_lens: O) -> Weight } crate::internal_macros::maybe_const_fn! { -fn predict_weight_internal(input_count: usize, partial_input_weight: usize, inputs_with_witnesses: usize, output_count: usize, output_scripts_size: usize) -> Weight { - let input_weight = partial_input_weight + input_count * 4 * (32 + 4 + 4); - let output_size = 8 * output_count + output_scripts_size; - let non_input_size = - // version: - 4 + - // count varints: - VarInt(input_count as u64).len() + - VarInt(output_count as u64).len() + - output_size + - // lock_time - 4; - let weight = if inputs_with_witnesses == 0 { - non_input_size * 4 + input_weight - } else { - non_input_size * 4 + input_weight + input_count - inputs_with_witnesses + 2 - }; - Weight::from_wu(weight as u64) -} + fn predict_weight_internal(input_count: usize, partial_input_weight: usize, inputs_with_witnesses: usize, output_count: usize, output_scripts_size: usize) -> Weight { + let input_weight = partial_input_weight + input_count * 4 * (32 + 4 + 4); + let output_size = 8 * output_count + output_scripts_size; + let non_input_size = + // version: + 4 + + // count varints: + VarInt(input_count as u64).len() + + VarInt(output_count as u64).len() + + output_size + + // lock_time + 4; + let weight = if inputs_with_witnesses == 0 { + non_input_size * 4 + input_weight + } else { + non_input_size * 4 + input_weight + input_count - inputs_with_witnesses + 2 + }; + Weight::from_wu(weight as u64) + } } /// Predicts the weight of a to-be-constructed transaction in const context. diff --git a/bitcoin/src/consensus/encode.rs b/bitcoin/src/consensus/encode.rs index e2131b4f..860f1226 100644 --- a/bitcoin/src/consensus/encode.rs +++ b/bitcoin/src/consensus/encode.rs @@ -373,22 +373,22 @@ impl_int_encodable!(i64, read_i64, emit_i64); #[allow(clippy::len_without_is_empty)] // VarInt has on concept of 'is_empty'. impl VarInt { crate::internal_macros::maybe_const_fn! { - /// Gets the length of this VarInt when encoded. - /// - /// *Important: this method is only `const` in Rust 1.46 or higher!* - /// - /// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1), - /// and 9 otherwise. - #[inline] - pub fn len(&self) -> usize { - match self.0 { - 0..=0xFC => { 1 } - 0xFD..=0xFFFF => { 3 } - 0x10000..=0xFFFFFFFF => { 5 } - _ => { 9 } + /// Gets the length of this VarInt when encoded. + /// + /// *Important: this method is only `const` in Rust 1.46 or higher!* + /// + /// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1), + /// and 9 otherwise. + #[inline] + pub fn len(&self) -> usize { + match self.0 { + 0..=0xFC => { 1 } + 0xFD..=0xFFFF => { 3 } + 0x10000..=0xFFFFFFFF => { 5 } + _ => { 9 } + } } } - } } impl Encodable for VarInt {