Skip to content

Commit f2acf2e

Browse files
authored
Merge pull request #1298 from NickeZ/nickez/ci-rustfmt
Nickez/ci rustfmt
2 parents 255ed44 + 8b24509 commit f2acf2e

File tree

9 files changed

+191
-150
lines changed

9 files changed

+191
-150
lines changed

.ci/check-style

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set -e
99
set -o pipefail
1010

1111
CLANGFORMAT=${CLANGFORMAT:-clang-format-18}
12+
RUSTFMT=${RUSTFMT:-rustfmt}
1213

1314
command -v git >/dev/null 2>&1 || { echo >&2 "git is missing"; exit 1; }
1415
command -v xargs >/dev/null 2>&1 || { echo >&2 "xargs is missing"; exit 1; }
@@ -37,3 +38,9 @@ if git --no-pager diff --diff-filter=d --name-only ${TARGET_BRANCH} HEAD | grep
3738
git --no-pager diff
3839
exit 1
3940
fi
41+
42+
RUST_SOURCES=$(git --no-pager diff --diff-filter=d --name-only ${TARGET_BRANCH} HEAD | grep -E "^src/rust.*\.rs\$" | grep -v -E "^src/rust/vendor" || true)
43+
if [ -n "$RUST_SOURCES" ] ; then
44+
echo $RUST_SOURCES
45+
"$RUSTFMT" --check $RUST_SOURCES
46+
fi

.ci/ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -e
66
# Deny warnings in rust. CI will fail to compile any code with warnings in it.
77
export RUSTFLAGS="-Dwarnings"
88

9-
# Check style for C
9+
# Check style for C and Rust
1010
./.ci/check-style
1111

1212
# Check that we can generate protobuf definitions for python

src/rust/bitbox02-rust/src/hww/api/ethereum/address.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ pub fn from_pubkey_hash(recipient: &[u8; 20], address_case: pb::EthAddressCase)
4444
// valid utf8 because hex and the uppercasing above is correct.
4545
core::str::from_utf8_unchecked(&hex[..])
4646
})
47-
},
47+
}
4848
pb::EthAddressCase::Upper => {
4949
format!("0x{}", hex::encode_upper(recipient))
50-
},
50+
}
5151
pb::EthAddressCase::Lower => {
5252
format!("0x{}", hex::encode(recipient))
5353
}
@@ -58,7 +58,10 @@ pub fn from_pubkey_hash(recipient: &[u8; 20], address_case: pb::EthAddressCase)
5858
/// `recipient` - 20 byte tail (last 20 bytes of the pubkeyhash).
5959
pub fn from_pubkey(pubkey_uncompressed: &[u8; 65]) -> String {
6060
let hash = sha3::Keccak256::digest(&pubkey_uncompressed[1..]);
61-
from_pubkey_hash(hash[hash.len() - 20..].try_into().unwrap(), pb::EthAddressCase::Mixed)
61+
from_pubkey_hash(
62+
hash[hash.len() - 20..].try_into().unwrap(),
63+
pb::EthAddressCase::Mixed,
64+
)
6265
}
6366

6467
#[cfg(test)]

src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ impl<'a> Transaction<'a> {
9393
fn case(&self) -> Result<pb::EthAddressCase, Error> {
9494
match self {
9595
Transaction::Legacy(legacy) => Ok(pb::EthAddressCase::try_from(legacy.address_case)?),
96-
Transaction::Eip1559(eip1559) => Ok(pb::EthAddressCase::try_from(eip1559.address_case)?),
96+
Transaction::Eip1559(eip1559) => {
97+
Ok(pb::EthAddressCase::try_from(eip1559.address_case)?)
98+
}
9799
}
98100
}
99101
}
@@ -268,7 +270,7 @@ async fn verify_standard_transaction(
268270
})
269271
.await?;
270272
}
271-
273+
272274
let address = super::address::from_pubkey_hash(&recipient, request.case()?);
273275
let amount = Amount {
274276
unit: params.unit,

src/rust/bitbox02-rust/src/hww/api/sdcard.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ pub async fn process(
2525
) -> Result<Response, Error> {
2626
let inserted = bitbox02::sd::sdcard_inserted();
2727
match SdCardAction::try_from(action) {
28-
Ok(SdCardAction::InsertCard) => {},
28+
Ok(SdCardAction::InsertCard) => {}
2929
_ => return Ok(Response::Success(pb::Success {})),
3030
};
31-
if inserted
32-
{
31+
if inserted {
3332
return Ok(Response::Success(pb::Success {}));
3433
}
3534
sdcard::sdcard().await?;

src/rust/bitbox02-rust/src/workflow/mnemonic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,4 +502,4 @@ mod tests {
502502
&bruteforce_lastword(&mnemonic)
503503
);
504504
}
505-
}
505+
}

src/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ pub async fn get() -> Result<zeroize::Zeroizing<String>, CancelError> {
3030
let words = "boring mistake dish oyster truth pigeon viable emerge sort crash wire portion cannon couple enact box walk height pull today solid off enable tide";
3131
bitbox02::println_stdout("Restored from recovery words below:");
3232
bitbox02::println_stdout(words);
33-
34-
Ok(zeroize::Zeroizing::new(
35-
words
36-
.to_string()
37-
))
38-
}
33+
34+
Ok(zeroize::Zeroizing::new(words.to_string()))
35+
}

0 commit comments

Comments
 (0)