Skip to content

Commit

Permalink
fix: remove max_value
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Sep 5, 2023
1 parent 5497cb9 commit 980dc63
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 33 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions crates/bitcoin/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl TryFormat for CompactUint {
fn try_format<W: Writer>(&self, w: &mut W) -> Result<(), Error> {
if self.value < 0xfd {
(self.value as u8).try_format(w)?;
} else if self.value < u16::max_value() as u64 {
} else if self.value < u16::MAX as u64 {
0xfd_u8.try_format(w)?;
(self.value as u16).try_format(w)?;
} else if self.value < u32::max_value() as u64 {
} else if self.value < u32::MAX as u64 {
0xfe_u8.try_format(w)?;
(self.value as u32).try_format(w)?;
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ where
impl TryFormat for TransactionInput {
fn try_format<W: Writer>(&self, w: &mut W) -> Result<(), Error> {
let (previous_hash, previous_index) = match self.source {
TransactionInputSource::Coinbase(_) => (H256Le::zero(), u32::max_value()),
TransactionInputSource::Coinbase(_) => (H256Le::zero(), u32::MAX),
TransactionInputSource::FromOutput(hash, index) => (hash, index),
};
previous_hash.try_format(w)?;
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {
assert_eq!(try_format(256u16), [0, 1]);
assert_eq!(try_format(0xffffu32 + 1), [0, 0, 1, 0]);
assert_eq!(try_format(0xffffffu32 + 1), [0, 0, 0, 1]);
assert_eq!(try_format(u64::max_value()), [0xff].repeat(8));
assert_eq!(try_format(u64::MAX), [0xff].repeat(8));
}

#[test]
Expand All @@ -313,9 +313,7 @@ mod tests {
assert_eq!(try_format(CompactUint { value: 0xff }), [0xfd, 0xff, 0]);
let u32_cuint = CompactUint { value: 0xffff + 1 };
assert_eq!(try_format(u32_cuint), [0xfe, 0, 0, 1, 0]);
let u64_cuint = CompactUint {
value: u64::max_value(),
};
let u64_cuint = CompactUint { value: u64::MAX };
assert_eq!(try_format(u64_cuint), [0xff].repeat(9));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bitcoin/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn parse_transaction_input(raw_input: &[u8], version: i32) -> Result<(Transactio

// fail if transaction is coinbase and previous index is not 0xffffffff
// previous_hash
if is_coinbase && previous_index != u32::max_value() {
if is_coinbase && previous_index != u32::MAX {
return Err(Error::MalformedTransaction);
}

Expand Down Expand Up @@ -559,7 +559,7 @@ pub(crate) mod tests {
let previous_hash = H256Le::from_hex_le("7b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de0398a14f3f");

assert!(matches!(input.source, TransactionInputSource::FromOutput(hash, 0) if hash == previous_hash));
assert_eq!(input.sequence, u32::max_value());
assert_eq!(input.sequence, u32::MAX);
assert_eq!(input.script.len(), 73);
}

Expand Down
7 changes: 1 addition & 6 deletions crates/bitcoin/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ pub const TARGET_TIMESPAN_DIVISOR: u64 = 4;

/// Unrounded Maximum Target
/// 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
pub const UNROUNDED_MAX_TARGET: U256 = U256([
<u64>::max_value(),
<u64>::max_value(),
<u64>::max_value(),
0x0000_0000_ffff_ffffu64,
]);
pub const UNROUNDED_MAX_TARGET: U256 = U256([<u64>::MAX, <u64>::MAX, <u64>::MAX, 0x0000_0000_ffff_ffffu64]);

// https://github.com/bitcoin/bitcoin/blob/89b910711c004c21b7d67baa888073742f7f94f0/src/pow.cpp#L49-L72
pub fn calculate_next_work_required(
Expand Down
2 changes: 1 addition & 1 deletion crates/bitcoin/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ fn generate_coinbase_transaction(
input_builder
.with_source(TransactionInputSource::Coinbase(Some(height)))
.add_witness(&[0; 32])
.with_sequence(u32::max_value());
.with_sequence(u32::MAX);
if let Some(script) = input_script {
input_builder.with_script(&script);
}
Expand Down
7 changes: 1 addition & 6 deletions crates/btc-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ pub const ACCEPTED_MAX_TRANSACTION_OUTPUTS: usize = 3;

/// Unrounded Maximum Target
/// 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
pub const UNROUNDED_MAX_TARGET: U256 = U256([
<u64>::max_value(),
<u64>::max_value(),
<u64>::max_value(),
0x0000_0000_ffff_ffffu64,
]);
pub const UNROUNDED_MAX_TARGET: U256 = U256([<u64>::MAX, <u64>::MAX, <u64>::MAX, 0x0000_0000_ffff_ffffu64]);

/// Main chain id
pub const MAIN_CHAIN_ID: u32 = 0;
Expand Down
2 changes: 1 addition & 1 deletion crates/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl<T: Config> Pallet<T> {
Self::checkpoint(who, old_locked, Default::default());

T::Currency::remove_lock(LOCK_ID, &who);
let _ = <UserPointHistory<T>>::clear_prefix(who, u32::max_value(), None);
let _ = <UserPointHistory<T>>::clear_prefix(who, u32::MAX, None);

Self::deposit_event(Event::<T>::Withdraw {
who: who.clone(),
Expand Down

0 comments on commit 980dc63

Please sign in to comment.