From 4fd75a2148a4ea2a81105438201ba85e47499151 Mon Sep 17 00:00:00 2001 From: DanGould Date: Tue, 3 Dec 2024 12:45:23 -0500 Subject: [PATCH] Lint using cargo clippy --- .github/workflows/build.yml | 16 +++++++++++++++- src/io.rs | 12 ++++++------ src/uri.rs | 6 +++--- tests/bdk_integration_test.rs | 6 +++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c4a787..ced6a30 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,4 +21,18 @@ jobs: run: cargo build --color always --all-targets --features _danger-local-https - name: Check formatting (nightly only) if: matrix.rust == 'nightly' - run: rustup component add rustfmt && cargo fmt --all -- --check + run: rustup component add rustfmt && cargo fmt --all -- --check\ + + Lint: + runs-on: ubuntu-latest + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Install nightly toolchain" + uses: dtolnay/rust-toolchain@nightly + - name: "Use cache" + uses: Swatinem/rust-cache@v2 + - name: "Install clippy" + run: rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu + - name: "Run linting" + run: bash contrib/lint.sh diff --git a/src/io.rs b/src/io.rs index cc02a0d..f8d2517 100644 --- a/src/io.rs +++ b/src/io.rs @@ -5,11 +5,11 @@ use crate::uri::Url; /// Fetch the ohttp keys from the specified payjoin directory via proxy. /// /// * `ohttp_relay`: The http CONNNECT method proxy to request the ohttp keys from a payjoin -/// directory. Proxying requests for ohttp keys ensures a client IP address is never revealed to -/// the payjoin directory. +/// directory. Proxying requests for ohttp keys ensures a client IP address is never revealed to +/// the payjoin directory. /// /// * `payjoin_directory`: The payjoin directory from which to fetch the ohttp keys. This -/// directory stores and forwards payjoin client payloads. +/// directory stores and forwards payjoin client payloads. #[cfg(not(feature = "_danger-local-https"))] pub async fn fetch_ohttp_keys( ohttp_relay: Url, @@ -24,11 +24,11 @@ pub async fn fetch_ohttp_keys( /// Fetch the ohttp keys from the specified payjoin directory via proxy. /// /// * `ohttp_relay`: The http CONNNECT method proxy to request the ohttp keys from a payjoin -/// directory. Proxying requests for ohttp keys ensures a client IP address is never revealed to -/// the payjoin directory. +/// directory. Proxying requests for ohttp keys ensures a client IP address is never revealed to +/// the payjoin directory. /// /// * `payjoin_directory`: The payjoin directory from which to fetch the ohttp keys. This -/// directory stores and forwards payjoin client payloads. +/// directory stores and forwards payjoin client payloads. /// /// * `cert_der`: The DER-encoded certificate to use for local HTTPS connections. #[cfg(feature = "_danger-local-https")] diff --git a/src/uri.rs b/src/uri.rs index 503e3dc..a3ef2a3 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -21,7 +21,7 @@ impl From> for Uri { } impl Uri { - pub fn from_str(uri: String) -> Result { + pub fn parse(uri: String) -> Result { match payjoin::Uri::from_str(uri.as_str()) { Ok(e) => Ok(e.assume_checked().into()), Err(e) => Err(PayjoinError::PjParseError { message: e.to_string() }), @@ -110,8 +110,8 @@ pub struct Url(payjoin::Url); #[cfg_attr(feature = "uniffi", uniffi::export)] impl Url { #[cfg_attr(feature = "uniffi", uniffi::constructor)] - pub fn from_str(input: String) -> Result { - match payjoin::Url::from_str(input.as_str()) { + pub fn parse(input: String) -> Result { + match payjoin::Url::parse(input.as_str()) { Ok(e) => Ok(Self(e)), Err(e) => Err(PayjoinError::UnexpectedError { message: e.to_string() }), } diff --git a/tests/bdk_integration_test.rs b/tests/bdk_integration_test.rs index 40b1261..ee2262c 100644 --- a/tests/bdk_integration_test.rs +++ b/tests/bdk_integration_test.rs @@ -248,9 +248,9 @@ mod v2 { async fn v2_to_v2_full_cycle() { let (cert, key) = local_cert_key(); let ohttp_relay_port = find_free_port(); - let ohttp_relay = Url::from_str(format!("http://localhost:{}", ohttp_relay_port)).unwrap(); + let ohttp_relay = Url::parse(format!("http://localhost:{}", ohttp_relay_port)).unwrap(); let directory_port = find_free_port(); - let directory = Url::from_str(format!("https://localhost:{}", directory_port)).unwrap(); + let directory = Url::parse(format!("https://localhost:{}", directory_port)).unwrap(); let gateway_origin = http::Uri::from_str(directory.as_string().as_str()).unwrap(); tokio::select!( _ = ohttp_relay::listen_tcp(ohttp_relay_port, gateway_origin) => assert!(false, "Ohttp relay is long running"), @@ -289,7 +289,7 @@ mod v2 { // ********************** // Inside the Sender: // Create a funded PSBT (not broadcasted) to address with amount given in the pj_uri - let pj_uri = Uri::from_str(pj_uri_string).unwrap().check_pj_supported().unwrap(); + let pj_uri = Uri::parse(pj_uri_string).unwrap().check_pj_supported().unwrap(); let psbt = build_original_psbt(&sender, &pj_uri)?; println!("\nOriginal sender psbt: {:#?}", psbt.to_string());