Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-foltz committed Sep 16, 2024
1 parent 697a72e commit 774553f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
21 changes: 8 additions & 13 deletions client/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ fn parse_glove_proof_lite(
return None;
}

let Some(calls) = extrinsic.get_param_as::<Vec<RuntimeCall>>("calls") else {
return None;
};
let calls = extrinsic.get_param_as::<Vec<RuntimeCall>>("calls")?;

let remarks = calls
.iter()
Expand Down Expand Up @@ -151,18 +149,12 @@ fn parse_and_validate_proxy_account_vote(
let Some(MultiAddress::Id(real)) = batched_call.get_param_as::<MultiAddress>("real") else {
return None;
};
let Some(proxied_call) = batched_call.get_param_as::<RuntimeCall>("call") else {
return None;
};
let proxied_call = batched_call.get_param_as::<RuntimeCall>("call")?;
if !proxied_call.is_extrinsic("convictionvoting", "vote") {
return None;
}
let Some(poll_index) = proxied_call.get_param_as::<u32>("poll_index") else {
return None;
};
let Some(vote) = proxied_call.get_param_as::<AccountVote>("vote") else {
return None;
};
let poll_index = proxied_call.get_param_as::<u32>("poll_index")?;
let vote = proxied_call.get_param_as::<AccountVote>("vote")?;
if expected_poll_index != poll_index {
return None;
}
Expand Down Expand Up @@ -293,7 +285,10 @@ mod tests {
.unwrap()
.unwrap();
assert_eq!(verification_result.result.assigned_balances.len(), 3);
let enclave_measuremnt = verification_result.enclave_info.as_ref().map(|EnclaveInfo::Nitro(info)| info.image_measurement.clone());
let enclave_measuremnt = verification_result
.enclave_info
.as_ref()
.map(|EnclaveInfo::Nitro(info)| info.image_measurement.clone());
assert_eq!(enclave_measuremnt, Some(from_hex("4d132e40ed8d6db60d01d0116c34a4a92914de73d668821b6e019b72ae152b1180ef7c8a378e6c1925fe2bcb31c0ec80").unwrap()));
let expected_balances = vec![
(
Expand Down
6 changes: 4 additions & 2 deletions common/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl AttestationBundle {
}

pub fn decode_envelope(bytes: &[u8]) -> Result<Self, ScaleError> {
let version = bytes.first()
let version = bytes
.first()
.ok_or_else(|| ScaleError::from("Empty bytes"))?;
if *version != ATTESTATION_BUNDLE_ENCODING_VERSION {
return Err(ScaleError::from("Unknown encoding version"));
Expand Down Expand Up @@ -144,7 +145,8 @@ impl GloveProofLite {
}

pub fn decode_envelope(bytes: &[u8]) -> Result<Self, ScaleError> {
let version = bytes.first()
let version = bytes
.first()
.ok_or_else(|| ScaleError::from("Empty bytes"))?;
if *version != GLOVE_PROOF_LITE_ENCODING_VERSION {
return Err(ScaleError::from("Unknown encoding version"));
Expand Down
11 changes: 5 additions & 6 deletions enclave/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::collections::HashSet;
use std::str::FromStr;

Expand Down Expand Up @@ -105,12 +106,10 @@ pub fn mix_votes(

Ok(GloveResult {
poll_index,
direction: if ayes_balance > nays_balance {
VoteDirection::Aye
} else if ayes_balance < nays_balance {
VoteDirection::Nay
} else {
VoteDirection::Abstain
direction: match ayes_balance.cmp(&nays_balance) {
Ordering::Greater => VoteDirection::Aye,
Ordering::Less => VoteDirection::Nay,
Ordering::Equal => VoteDirection::Abstain,
},
assigned_balances,
})
Expand Down
1 change: 1 addition & 0 deletions service/src/dynamodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct DynamodbGloveStorage {
partition_key: String,
sort_key: String,
client: Client,
#[allow(clippy::type_complexity)]
cached_vote_accounts: Arc<Mutex<Option<HashMap<u32, HashSet<AccountId32>>>>>,
}

Expand Down
3 changes: 2 additions & 1 deletion service/src/enclave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ pub mod mock {
}

fn local_file(file: &str) -> io::Result<PathBuf> {
env::args().next()
env::args()
.next()
.map(|exe| {
Path::new(&exe)
.parent()
Expand Down
5 changes: 4 additions & 1 deletion service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ async fn remove_vote(
)
.await;
match remove_result {
#[allow(non_snake_case)]
Err(ProxyError::Module(_, ConvictionVoting(NotVoter))) => {
debug!("Vote not found on-chain: {:?}", signed_request.request);
}
Expand Down Expand Up @@ -628,6 +629,7 @@ async fn try_mix_votes(context: &GloveContext, poll_index: u32) -> Result<bool,
}

match result.unwrap_err() {
#[allow(non_snake_case)]
ProxyError::Module(batch_index, ConvictionVoting(InsufficientFunds)) => {
let request = &poll_requests[batch_index].request;
warn!(
Expand All @@ -648,6 +650,7 @@ async fn try_mix_votes(context: &GloveContext, poll_index: u32) -> Result<bool,
}
Ok(true)
}
#[allow(non_snake_case)]
ProxyError::Batch(BatchError::Module(batch_index, Proxy(NotProxy))) => {
let request = &poll_requests[batch_index].request;
warn!(
Expand Down Expand Up @@ -676,7 +679,7 @@ async fn try_mix_votes(context: &GloveContext, poll_index: u32) -> Result<bool,

async fn submit_glove_result_on_chain(
context: &GloveContext,
signed_requests: &Vec<SignedVoteRequest>,
signed_requests: &[SignedVoteRequest],
signed_glove_result: SignedGloveResult,
) -> Result<(), ProxyError> {
let mut batched_calls = Vec::with_capacity(signed_requests.len() + 1);
Expand Down
4 changes: 2 additions & 2 deletions service/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl GloveStorage {
GloveStorage::InMemory(store) => {
store.add_vote_request(signed_request).await;
Ok(())
},
}
GloveStorage::Dynamodb(store) => store.add_vote_request(signed_request).await,
}
}
Expand Down Expand Up @@ -55,7 +55,7 @@ impl GloveStorage {
GloveStorage::InMemory(store) => {
store.remove_poll(poll_index).await;
Ok(())
},
}
GloveStorage::Dynamodb(store) => store.remove_poll(poll_index).await,
}
}
Expand Down

0 comments on commit 774553f

Please sign in to comment.