Skip to content

Commit

Permalink
fix clippy warnings in python wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Oct 7, 2022
1 parent 7fce80d commit c0bfe1b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/merkle_set.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use clvmr::sha2::{Digest, Sha256};

fn get_bit(val: &[u8; 32], bit: u8) -> u8 {
if val[(bit / 8) as usize] & (0x80 >> (bit & 7)) == 0 {
0
} else {
1
}
(val[(bit / 8) as usize] & (0x80 >> (bit & 7))) as u8
}

#[repr(u8)]
Expand Down
2 changes: 1 addition & 1 deletion wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn compute_merkle_set_root<'p>(
}

#[pyfunction]
pub fn tree_hash<'p>(py: Python<'p>, blob: pyo3::buffer::PyBuffer<u8>) -> PyResult<&'p PyBytes> {
pub fn tree_hash(py: Python, blob: pyo3::buffer::PyBuffer<u8>) -> PyResult<&PyBytes> {
if !blob.is_c_contiguous() {
panic!("tree_hash() must be called with a contiguous buffer");
}
Expand Down
8 changes: 4 additions & 4 deletions wheel/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub struct Coin {
impl Coin {
fn coin_id(&self) -> [u8; 32] {
let mut hasher = Sha256::new();
hasher.update(&self.parent_coin_info);
hasher.update(&self.puzzle_hash);
hasher.update(self.parent_coin_info);
hasher.update(self.puzzle_hash);

let amount_bytes = self.amount.to_be_bytes();
if self.amount >= 0x8000000000000000_u64 {
hasher.update(&[0_u8]);
hasher.update(&amount_bytes);
hasher.update([0_u8]);
hasher.update(amount_bytes);
} else {
let start = match self.amount {
n if n >= 0x80000000000000_u64 => 0,
Expand Down
2 changes: 2 additions & 0 deletions wheel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::borrow_deref_ref)] // https://github.com/rust-lang/rust-clippy/issues/8971

mod adapt_response;
mod api;
mod coin;
Expand Down
1 change: 1 addition & 0 deletions wheel/src/run_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn convert_spend_bundle_conds(a: &Allocator, sb: SpendBundleConditions) -> PySpe
// returns the cost of running the CLVM program along with conditions and the list of
// spends
#[pyfunction]
#[allow(clippy::borrow_deref_ref)]
pub fn run_generator(
py: Python,
program: &[u8],
Expand Down
2 changes: 2 additions & 0 deletions wheel/src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ impl LazyNode {
}
}

#[allow(clippy::borrow_deref_ref)]
#[pyfunction]
pub fn serialized_length(program: &[u8]) -> PyResult<u64> {
Ok(serialized_length_from_bytes(program)?)
}

#[allow(clippy::borrow_deref_ref)]
#[pyfunction]
pub fn run_chia_program(
py: Python,
Expand Down

0 comments on commit c0bfe1b

Please sign in to comment.