Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust code to avoid some clippy warnings #47

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ jobs:

- name: Install cargo-machete
run: cargo install cargo-machete
marcelstanley marked this conversation as resolved.
Show resolved Hide resolved
continue-on-error: true

- name: Analyze dependencies
run: cargo machete .
continue-on-error: true

- name: Check format
- name: Check code format
run: cargo fmt --all -- --check

- name: Run linter
run: cargo clippy -- -A clippy::module_inception -A clippy::new_ret_no_self
run: cargo clippy -- -A clippy::module_inception
5 changes: 2 additions & 3 deletions offchain/dispatcher/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ pub struct AuthEnvCLIConfig {
}

#[derive(Debug, Clone)]
#[allow(clippy::upper_case_acronyms)]
pub enum AuthConfig {
Mnemonic {
mnemonic: String,
account_index: Option<u32>,
},

AWS {
Aws {
key_id: String,
region: Region,
},
Expand Down Expand Up @@ -95,7 +94,7 @@ impl AuthConfig {
(Some(key_id), Some(region)) => {
let region = Region::from_str(&region)
.context(InvalidRegionSnafu)?;
Ok(AuthConfig::AWS { key_id, region })
Ok(AuthConfig::Aws { key_id, region })
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion offchain/dispatcher/src/signer/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl ConditionalSigner {
.with_chain_id(chain_id);
Ok(ConditionalSigner::LocalWallet(wallet))
}
AuthConfig::AWS { key_id, region } => {
AuthConfig::Aws { key_id, region } => {
AwsSigner::new(key_id, chain_id, region)
.await
.map(ConditionalSigner::AwsSigner)
Expand Down
42 changes: 21 additions & 21 deletions offchain/host-runner/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct Service {
impl Service {
fn new(data: SharedStateData) -> Self {
Self {
state: IdleState::new(data),
state: Box::new(IdleState::new(data)),
}
}

Expand Down Expand Up @@ -271,8 +271,8 @@ struct IdleState {
}

impl IdleState {
fn new(data: SharedStateData) -> Box<dyn State> {
Box::new(Self { data })
fn new(data: SharedStateData) -> Self {
Self { data }
}
}

Expand All @@ -285,7 +285,7 @@ impl State for IdleState {
tracing::debug!("received finish request; changing state to fetch request");
tracing::debug!("request: {:?}", request);
let (_, response_tx) = request.into_inner();
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.voucher_rx.recv() => {
Service::handle_invalid(request, self, "voucher")
Expand Down Expand Up @@ -322,11 +322,11 @@ impl FetchRequestState {
finish_response_tx: oneshot::Sender<
Result<RollupRequest, ControllerError>,
>,
) -> Box<dyn State> {
Box::new(Self {
) -> Self {
Self {
data,
finish_response_tx,
})
}
}
}

Expand All @@ -339,31 +339,31 @@ impl State for FetchRequestState {
tracing::debug!("fetch request timed out; setting state to idle");
let timeout_err = ControllerError::FetchRequestTimeout;
send_response(self.finish_response_tx, Err(timeout_err));
Some(IdleState::new(self.data))
Some(Box::new(IdleState::new(self.data)))
}
Some(request) = self.data.inspect_rx.recv() => {
tracing::debug!("received inspect request; setting state to inspect");
tracing::debug!("request: {:?}", request);
let (inspect_request, inspect_response_tx) = request.into_inner();
let rollup_request = RollupRequest::InspectState(inspect_request);
send_response(self.finish_response_tx, Ok(rollup_request));
Some(InspectState::new(self.data, inspect_response_tx))
Some(Box::new(InspectState::new(self.data, inspect_response_tx)))
}
Some(request) = self.data.advance_rx.recv() => {
tracing::debug!("received advance request; setting state to advance");
tracing::debug!("request: {:?}", request);
let (advance_request, advance_response_tx) = request.into_inner();
let rollup_request = RollupRequest::AdvanceState(advance_request);
send_response(self.finish_response_tx, Ok(rollup_request));
Some(AdvanceState::new(self.data, advance_response_tx))
Some(Box::new(AdvanceState::new(self.data, advance_response_tx)))
}
Some(request) = self.data.finish_rx.recv() => {
tracing::debug!("received finish request; terminating previous finish request");
tracing::debug!("request: {:?}", request);
let timeout_err = ControllerError::FetchRequestTimeout;
send_response(self.finish_response_tx, Err(timeout_err));
let (_, response_tx) = request.into_inner();
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.voucher_rx.recv() => {
Service::handle_invalid(request, self, "voucher")
Expand Down Expand Up @@ -399,12 +399,12 @@ impl InspectState {
fn new(
data: SharedStateData,
inspect_response_tx: oneshot::Sender<InspectResult>,
) -> Box<dyn State> {
Box::new(Self {
) -> Self {
Self {
data,
inspect_response_tx,
reports: vec![],
})
}
}
}

Expand All @@ -422,7 +422,7 @@ impl State for InspectState {
FinishStatus::Reject => InspectResult::rejected(self.reports),
};
send_response(self.inspect_response_tx, result);
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.report_rx.recv() => {
tracing::debug!("received report request");
Expand All @@ -440,7 +440,7 @@ impl State for InspectState {
let result = InspectResult::exception(self.reports, exception);
send_response(self.inspect_response_tx, result);
send_response(exception_response_tx, Ok(()));
Some(IdleState::new(self.data))
Some(Box::new(IdleState::new(self.data)))
}
Some(request) = self.data.voucher_rx.recv() => {
Service::handle_invalid(request, self, "voucher")
Expand Down Expand Up @@ -472,14 +472,14 @@ impl AdvanceState {
fn new(
data: SharedStateData,
advance_response_tx: oneshot::Sender<AdvanceResult>,
) -> Box<dyn State> {
Box::new(Self {
) -> Self {
Self {
data,
advance_response_tx,
vouchers: vec![],
notices: vec![],
reports: vec![],
})
}
}
}

Expand Down Expand Up @@ -507,7 +507,7 @@ impl State for AdvanceState {
},
};
send_response(self.advance_response_tx, result);
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.voucher_rx.recv() => {
tracing::debug!("received voucher request");
Expand Down Expand Up @@ -546,7 +546,7 @@ impl State for AdvanceState {
);
send_response(self.advance_response_tx, result);
send_response(exception_response_tx, Ok(()));
Some(IdleState::new(self.data))
Some(Box::new(IdleState::new(self.data)))
}
Some(request) = self.data.shutdown_rx.recv() => {
Service::shutdown(request)
Expand Down
Loading