Skip to content

Commit

Permalink
chore: fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 17, 2024
1 parent aea1971 commit 9237216
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
12 changes: 7 additions & 5 deletions consensus/src/coding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,27 @@ impl AsRef<[u8]> for ByteStr {
}

impl From<Vec<u8>> for ByteStr {
fn from(value: Vec<u8>) -> Self { Self(Confined::try_from(value).expect("u32 >= usize")) }
fn from(value: Vec<u8>) -> Self {
Self(Confined::try_from(value).expect("byte string size exceeds 4GB"))
}

Check warning on line 103 in consensus/src/coding.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/coding.rs#L101-L103

Added lines #L101 - L103 were not covered by tests
}

impl From<TinyBlob> for ByteStr {
fn from(vec: TinyBlob) -> Self { ByteStr(Confined::from_collection_unsafe(vec.into_inner())) }
fn from(vec: TinyBlob) -> Self { ByteStr(Confined::from_checked(vec.release())) }

Check warning on line 107 in consensus/src/coding.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/coding.rs#L107

Added line #L107 was not covered by tests
}

impl From<SmallBlob> for ByteStr {
fn from(vec: SmallBlob) -> Self { ByteStr(Confined::from_collection_unsafe(vec.into_inner())) }
fn from(vec: SmallBlob) -> Self { ByteStr(Confined::from_checked(vec.release())) }

Check warning on line 111 in consensus/src/coding.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/coding.rs#L111

Added line #L111 was not covered by tests
}

impl From<MediumBlob> for ByteStr {
fn from(vec: MediumBlob) -> Self { ByteStr(Confined::from_collection_unsafe(vec.into_inner())) }
fn from(vec: MediumBlob) -> Self { ByteStr(Confined::from_checked(vec.release())) }

Check warning on line 115 in consensus/src/coding.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/coding.rs#L115

Added line #L115 was not covered by tests
}

impl ByteStr {
pub fn len_var_int(&self) -> VarInt { VarInt(self.len() as u64) }

pub fn into_vec(self) -> Vec<u8> { self.0.into_inner() }
pub fn into_vec(self) -> Vec<u8> { self.0.release() }

Check warning on line 121 in consensus/src/coding.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/coding.rs#L121

Added line #L121 was not covered by tests
}

#[cfg(feature = "serde")]
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl ScriptBytes {

pub fn len_var_int(&self) -> VarInt { VarInt(self.len() as u64) }

pub fn into_vec(self) -> Vec<u8> { self.0.into_inner() }
pub fn into_vec(self) -> Vec<u8> { self.0.release() }

Check warning on line 309 in consensus/src/script.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/script.rs#L309

Added line #L309 was not covered by tests

pub(crate) fn as_var_int_bytes(&self) -> &VarIntBytes { &self.0 }
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/sigcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,12 @@ impl<Prevout: Borrow<TxOut>, Tx: Borrow<Transaction>> SighashCache<Prevout, Tx>
// Add all necessary inputs...
let sig_script = script_pubkey.as_script_bytes().clone().into();
if anyone_can_pay {
tx.inputs = confined_vec![TxIn {
tx.inputs = VarIntArray::from_checked(vec![TxIn {

Check warning on line 424 in consensus/src/sigcache.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/sigcache.rs#L424

Added line #L424 was not covered by tests
prev_output: tx_src.inputs[input_index].prev_output,
sig_script,
sequence: tx_src.inputs[input_index].sequence,
witness: none!(),
}];
}]);

Check warning on line 429 in consensus/src/sigcache.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/sigcache.rs#L429

Added line #L429 was not covered by tests
} else {
let inputs = tx_src.inputs.iter().enumerate().map(|(n, input)| TxIn {
prev_output: input.prev_output,
Expand All @@ -444,7 +444,7 @@ impl<Prevout: Borrow<TxOut>, Tx: Borrow<Transaction>> SighashCache<Prevout, Tx>
},
witness: none!(),
});
tx.inputs = VarIntArray::from_iter_unsafe(inputs);
tx.inputs = VarIntArray::from_iter_checked(inputs);

Check warning on line 447 in consensus/src/sigcache.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/sigcache.rs#L447

Added line #L447 was not covered by tests
}
// ...then all outputs
tx.outputs = match sighash_flag {
Expand All @@ -454,7 +454,7 @@ impl<Prevout: Borrow<TxOut>, Tx: Borrow<Transaction>> SighashCache<Prevout, Tx>
.take(input_index + 1) // sign all outputs up to and including this one, but erase
.enumerate() // all of them except for this one
.map(|(n, out)| if n == input_index { out.clone() } else { TxOut::default() });
VarIntArray::from_iter_unsafe(outputs)
VarIntArray::from_iter_checked(outputs)

Check warning on line 457 in consensus/src/sigcache.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/sigcache.rs#L457

Added line #L457 was not covered by tests
}
SighashFlag::None => none!(),
};
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ pub enum AnnexError {
#[wrapper(Deref, AsSlice, Hex)]
#[wrapper_mut(DerefMut, AsSliceMut)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BITCOIN, dumb = Self(confined_vec![0x50]))]
#[strict_type(lib = LIB_NAME_BITCOIN, dumb = { Self(VarIntBytes::with(0x50)) })]
pub struct Annex(VarIntBytes<1>);

impl TryFrom<Vec<u8>> for Annex {
Expand All @@ -877,7 +877,7 @@ impl Annex {

pub fn len_var_int(&self) -> VarInt { VarInt(self.len() as u64) }

pub fn into_vec(self) -> Vec<u8> { self.0.into_inner() }
pub fn into_vec(self) -> Vec<u8> { self.0.release() }

Check warning on line 880 in consensus/src/taproot.rs

View check run for this annotation

Codecov / codecov/patch

consensus/src/taproot.rs#L880

Added line #L880 was not covered by tests

/// Returns the Annex bytes data (including first byte `0x50`).
pub fn as_slice(&self) -> &[u8] { self.0.as_slice() }
Expand Down
4 changes: 2 additions & 2 deletions dbc/src/tapret/tapscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl StrictDeserialize for TapretCommitment {}

impl From<[u8; 33]> for TapretCommitment {
fn from(value: [u8; 33]) -> Self {
let buf = Confined::try_from_iter(value).expect("exact size match");
let buf = Confined::from_iter_checked(value);

Check warning on line 58 in dbc/src/tapret/tapscript.rs

View check run for this annotation

Codecov / codecov/patch

dbc/src/tapret/tapscript.rs#L58

Added line #L58 was not covered by tests
Self::from_strict_serialized::<33>(buf).expect("exact size match")
}
}
Expand All @@ -65,7 +65,7 @@ impl TapretCommitment {
pub fn to_vec(&self) -> Vec<u8> {
self.to_strict_serialized::<33>()
.expect("exact size match")
.into_inner()
.release()
}
}

Expand Down

0 comments on commit 9237216

Please sign in to comment.