Skip to content

Commit ab75a89

Browse files
authored
chore: Format and lint existing source - add lint step to CI (#23)
* Enforce fmt, clippy, cargo test * CI uses 1.85.0, squash deadcode and expect err warnings
1 parent 6a94d3f commit ab75a89

21 files changed

+412
-230
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ on:
1010
- master
1111

1212
jobs:
13+
lint:
14+
name: lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
20+
- uses: actions-rust-lang/setup-rust-toolchain@v1
21+
with:
22+
components: rustfmt, clippy
23+
toolchain: "1.85.0"
24+
- name: Install cargo-sort from crates.io
25+
uses: baptiste0928/cargo-install@v3
26+
with:
27+
crate: cargo-sort
28+
- run: sudo apt-get install protobuf-compiler -y
29+
- run: cargo sort --workspace --check
30+
- run: cargo fmt --all --check
31+
- run: cargo clippy --all-features --all-targets --tests -- -D warnings
1332
verified_build:
1433
name: verified_build
1534
runs-on: ubuntu-latest
@@ -19,7 +38,7 @@ jobs:
1938
submodules: recursive
2039
- uses: actions-rust-lang/setup-rust-toolchain@v1
2140
with:
22-
toolchain: "1.75.0"
41+
toolchain: "1.85.0"
2342
- name: Install solana-verify from crates.io
2443
uses: baptiste0928/cargo-install@v3
2544
with:
@@ -35,4 +54,3 @@ jobs:
3554
with:
3655
name: program.so
3756
path: target/deploy/*.so
38-

api/src/error.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use solana_sdk::pubkey::Pubkey;
99
use thiserror::Error;
1010
use tracing::error;
1111

12+
#[allow(clippy::large_enum_variant)]
1213
#[derive(Error, Debug)]
1314
pub enum ApiError {
1415
#[error("Rpc Error")]
@@ -41,7 +42,10 @@ impl IntoResponse for ApiError {
4142
}
4243
ApiError::ParseStakeDepositAuthorityError(e) => {
4344
error!("Parse StakePoolDepositStakeAuthority error: {e}");
44-
(StatusCode::INTERNAL_SERVER_ERROR, "Pubkey StakePoolDepositStakeAuthority error")
45+
(
46+
StatusCode::INTERNAL_SERVER_ERROR,
47+
"Pubkey StakePoolDepositStakeAuthority error",
48+
)
4549
}
4650
ApiError::ParseStakePoolError(e) => {
4751
error!("Parse StakePool error: {e}");
@@ -53,9 +57,15 @@ impl IntoResponse for ApiError {
5357
}
5458
ApiError::ParseValidatorListError(e) => {
5559
error!("Parse ValidatorList error: {e}");
56-
(StatusCode::INTERNAL_SERVER_ERROR, "Pubkey ValidatorList error")
60+
(
61+
StatusCode::INTERNAL_SERVER_ERROR,
62+
"Pubkey ValidatorList error",
63+
)
5764
}
58-
ApiError::InvalidStakeVoteAccount => (StatusCode::BAD_REQUEST, "Stake voter_pubkey is invalid or missing"),
65+
ApiError::InvalidStakeVoteAccount => (
66+
StatusCode::BAD_REQUEST,
67+
"Stake voter_pubkey is invalid or missing",
68+
),
5969
ApiError::InternalError => (StatusCode::INTERNAL_SERVER_ERROR, "Internal Server Error"),
6070
};
6171
(

api/src/router/get_deposit_stake_instructions.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ use stake_deposit_interceptor::{
1818
instruction::create_deposit_stake_instruction, state::StakePoolDepositStakeAuthority,
1919
};
2020

21-
use crate::{error::ApiError, utils::{pubkey_from_str, Instruction}};
21+
use crate::{
22+
error::ApiError,
23+
utils::{pubkey_from_str, Instruction},
24+
};
2225

2326
use super::RouterState;
2427

@@ -50,7 +53,7 @@ struct GetDepositStakeResponse {
5053
}
5154

5255
/// Constructs the instructions necessary to `DepositStake` via the stake-pool-interceptor program.
53-
///
56+
///
5457
pub(crate) async fn get_deposit_stake_instructions(
5558
State(state): State<Arc<RouterState>>,
5659
Query(query): Query<GetDepositStakeQuery>,

api/src/utils.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ impl Serialize for Instruction {
3939

4040
state.serialize_field("programId", &self.program_id.to_string())?;
4141

42-
let accounts_as_objects: Vec<_> = self.accounts.iter().map(|a| {
43-
serde_json::json!({
44-
"pubkey": a.pubkey.to_string(),
45-
"isSigner": a.is_signer,
46-
"isWritable": a.is_writable
42+
let accounts_as_objects: Vec<_> = self
43+
.accounts
44+
.iter()
45+
.map(|a| {
46+
serde_json::json!({
47+
"pubkey": a.pubkey.to_string(),
48+
"isSigner": a.is_signer,
49+
"isWritable": a.is_writable
50+
})
4751
})
48-
}).collect();
52+
.collect();
4953
state.serialize_field("accounts", &accounts_as_objects)?;
5054

5155
state.serialize_field(
@@ -55,4 +59,4 @@ impl Serialize for Instruction {
5559

5660
state.end()
5761
}
58-
}
62+
}

stake_deposit_interceptor/build.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
fn main() {
2-
println!("cargo:rerun-if-env-changed=GIT_SHA");
3-
println!(
4-
"cargo:rustc-env=GIT_SHA={}",
5-
option_env!("GIT_SHA").unwrap_or("GIT_SHA_MISSING")
6-
);
2+
println!("cargo:rerun-if-env-changed=GIT_SHA");
3+
println!(
4+
"cargo:rustc-env=GIT_SHA={}",
5+
option_env!("GIT_SHA").unwrap_or("GIT_SHA_MISSING")
6+
);
77

8-
println!("cargo:rerun-if-env-changed=GIT_REF_NAME");
9-
println!(
10-
"cargo:rustc-env=GIT_REF_NAME={}",
11-
option_env!("GIT_REF_NAME").unwrap_or("GIT_REF_NAME_MISSING")
12-
);
8+
println!("cargo:rerun-if-env-changed=GIT_REF_NAME");
9+
println!(
10+
"cargo:rustc-env=GIT_REF_NAME={}",
11+
option_env!("GIT_REF_NAME").unwrap_or("GIT_REF_NAME_MISSING")
12+
);
1313
}

0 commit comments

Comments
 (0)