From c92fbf3c09bddb006141a6677029d0dd7b85bb1c Mon Sep 17 00:00:00 2001 From: Eason Gao Date: Sun, 3 Dec 2023 10:11:52 +0800 Subject: [PATCH] fix(axon-tools): cargo clippy --all-features errors (#1614) * fix(axon-tools): cargo clippy --all-features * refactor workflow --- Makefile | 8 +++++++- devtools/axon-tools/Cargo.toml | 3 ++- devtools/axon-tools/src/hex.rs | 4 ++++ devtools/axon-tools/src/lib.rs | 1 + devtools/axon-tools/src/rlp_codec.rs | 8 ++------ devtools/axon-tools/src/types.rs | 26 +++++++++++++------------- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 53872ab19..e9d56061a 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,16 @@ check-fmt: fmt: cargo +nightly fmt ${VERBOSE} --all -clippy: +clippy: axon-clippy axon-tools-clippy + +axon-clippy: ${CARGO} clippy ${VERBOSE} --all --all-targets --all-features -- \ -D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use +axon-tools-clippy: + ${CARGO} clippy ${VERBOSE} --manifest-path=devtools/axon-tools/Cargo.toml --all-features -- \ + -D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use + sort: cargo sort -gw diff --git a/devtools/axon-tools/Cargo.toml b/devtools/axon-tools/Cargo.toml index 459e28afa..e08daf0e2 100644 --- a/devtools/axon-tools/Cargo.toml +++ b/devtools/axon-tools/Cargo.toml @@ -32,7 +32,7 @@ hash = ["tiny-keccak"] hex = ["faster-hex"] impl-rlp = ["rlp", "rlp-derive", "ethereum-types/rlp"] impl-serde = ["serde", "ethereum-types/serialize"] -precompile = ["ethers-contract", "ethers-core"] +precompile = ["ckb-types", "ethers-contract", "ethers-core", "std"] std = ["cita_trie", "hex", "log", "derive_more", "serde_json"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -98,6 +98,7 @@ features = ["derive"] [dependencies.serde_json] version = "1.0" default_features = false +features = ["alloc"] optional = true [dependencies.tiny-keccak] diff --git a/devtools/axon-tools/src/hex.rs b/devtools/axon-tools/src/hex.rs index 38caaebb6..177de6a2a 100644 --- a/devtools/axon-tools/src/hex.rs +++ b/devtools/axon-tools/src/hex.rs @@ -1,3 +1,7 @@ +use alloc::string::String; +use alloc::vec; +use alloc::vec::Vec; + use crate::Error; pub fn hex_encode>(src: T) -> String { diff --git a/devtools/axon-tools/src/lib.rs b/devtools/axon-tools/src/lib.rs index fe58a3058..535a6c355 100644 --- a/devtools/axon-tools/src/lib.rs +++ b/devtools/axon-tools/src/lib.rs @@ -14,6 +14,7 @@ pub mod hex; pub mod precompile; #[cfg(feature = "proof")] mod proof; +#[cfg(feature = "impl-rlp")] mod rlp_codec; pub mod types; diff --git a/devtools/axon-tools/src/rlp_codec.rs b/devtools/axon-tools/src/rlp_codec.rs index e72501b4a..bf820cce7 100644 --- a/devtools/axon-tools/src/rlp_codec.rs +++ b/devtools/axon-tools/src/rlp_codec.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "impl-rlp")] use crate::types::BlockVersion; #[cfg(feature = "proof")] use crate::types::{Proposal, Vote}; -#[cfg(feature = "impl-rlp")] use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; -#[cfg(feature = "impl-rlp")] impl Encodable for BlockVersion { fn rlp_append(&self, s: &mut RlpStream) { let ver: u8 = (*self).into(); @@ -13,7 +10,6 @@ impl Encodable for BlockVersion { } } -#[cfg(feature = "impl-rlp")] impl Decodable for BlockVersion { fn decode(r: &Rlp) -> Result { let ver: u8 = r.val_at(0)?; @@ -22,7 +18,7 @@ impl Decodable for BlockVersion { } } -#[cfg(feature = "impl-rlp")] +#[cfg(feature = "proof")] impl Encodable for Vote { fn rlp_append(&self, s: &mut RlpStream) { let vote_type: u8 = self.vote_type; @@ -34,7 +30,7 @@ impl Encodable for Vote { } } -#[cfg(feature = "impl-rlp")] +#[cfg(feature = "proof")] impl Encodable for Proposal { fn rlp_append(&self, s: &mut RlpStream) { s.begin_list(13) diff --git a/devtools/axon-tools/src/types.rs b/devtools/axon-tools/src/types.rs index 38f665b9e..e6bf0a7a1 100644 --- a/devtools/axon-tools/src/types.rs +++ b/devtools/axon-tools/src/types.rs @@ -6,6 +6,8 @@ // are recommended to ensure the definitions in this file align with those in // the 'axon-protocol' package. use crate::error::TypesError; +#[cfg(any(feature = "hex", feature = "impl-serde"))] +use alloc::string::String; use alloc::vec; use alloc::vec::Vec; use bytes::{Bytes, BytesMut}; @@ -24,10 +26,8 @@ use crate::hex::{hex_decode, hex_encode}; use crate::Error; #[cfg(feature = "hex")] use core::str::FromStr; -#[cfg(feature = "hex")] -use faster_hex::withpfx_lowercase; -#[cfg(feature = "std")] +#[cfg(feature = "hex")] const HEX_PREFIX: &str = "0x"; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] @@ -53,7 +53,7 @@ impl Hex { #[cfg(feature = "hex")] pub fn as_string(&self) -> String { - HEX_PREFIX.to_string() + &hex_encode(self.0.as_ref()) + String::from(HEX_PREFIX) + &hex_encode(self.0.as_ref()) } #[cfg(feature = "hex")] @@ -115,7 +115,7 @@ impl Serialize for Hex { where S: serde::ser::Serializer, { - withpfx_lowercase::serialize(&self.0, serializer) + faster_hex::withpfx_lowercase::serialize(&self.0, serializer) } } @@ -170,8 +170,8 @@ pub struct ExtraData { #[cfg_attr( all(feature = "impl-serde", feature = "std"), serde( - serialize_with = "withpfx_lowercase::serialize", - deserialize_with = "withpfx_lowercase::deserialize" + serialize_with = "faster_hex::withpfx_lowercase::serialize", + deserialize_with = "faster_hex::withpfx_lowercase::deserialize" ) )] pub inner: Bytes, @@ -314,16 +314,16 @@ pub struct Proof { #[cfg_attr( all(feature = "impl-serde", feature = "std"), serde( - serialize_with = "withpfx_lowercase::serialize", - deserialize_with = "withpfx_lowercase::deserialize" + serialize_with = "faster_hex::withpfx_lowercase::serialize", + deserialize_with = "faster_hex::withpfx_lowercase::deserialize" ) )] pub signature: Bytes, #[cfg_attr( all(feature = "impl-serde", feature = "std"), serde( - serialize_with = "withpfx_lowercase::serialize", - deserialize_with = "withpfx_lowercase::deserialize" + serialize_with = "faster_hex::withpfx_lowercase::serialize", + deserialize_with = "faster_hex::withpfx_lowercase::deserialize" ) )] pub bitmap: Bytes, @@ -417,7 +417,7 @@ impl MetadataVersion { all(feature = "impl-serde", feature = "std"), derive(serde::Serialize, serde::Deserialize) )] -#[cfg_attr(feature = "hex", derive(Debug))] +#[cfg_attr(feature = "std", derive(Debug))] pub struct Metadata { pub version: MetadataVersion, #[cfg_attr( @@ -532,7 +532,7 @@ impl Ord for ValidatorExtend { } } -#[cfg(feature = "hex")] +#[cfg(feature = "std")] impl std::fmt::Debug for ValidatorExtend { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let bls_pub_key = self.bls_pub_key.as_string_trim0x();