From f4bb947423aefcaf31d9b0a0e839328012c3f915 Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Mon, 2 Dec 2024 20:28:38 -0800 Subject: [PATCH 1/3] Fixes for new clippy lints / rustc warnings --- chain/rust/src/builders/witness_builder.rs | 7 ++----- chain/rust/src/genesis/byron/config.rs | 1 - crypto/rust/Cargo.toml | 5 +++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/chain/rust/src/builders/witness_builder.rs b/chain/rust/src/builders/witness_builder.rs index 269a3419..0d62ed79 100644 --- a/chain/rust/src/builders/witness_builder.rs +++ b/chain/rust/src/builders/witness_builder.rs @@ -140,11 +140,8 @@ impl RequiredWitnessSet { // } pub fn add_script_hash(&mut self, script_hash: ScriptHash) { - match self.script_refs.get(&script_hash) { - None => { - self.scripts.insert(script_hash); - } - Some(_) => {} + if !self.script_refs.contains(&script_hash) { + self.scripts.insert(script_hash); } } diff --git a/chain/rust/src/genesis/byron/config.rs b/chain/rust/src/genesis/byron/config.rs index d9271547..b543f92a 100644 --- a/chain/rust/src/genesis/byron/config.rs +++ b/chain/rust/src/genesis/byron/config.rs @@ -21,7 +21,6 @@ use cml_crypto::{ /// Configuration for the wallet-crypto #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] -#[cfg_attr(feature = "generic-serialization", derive(Serialize, Deserialize))] pub struct Config { pub protocol_magic: ProtocolMagic, } diff --git a/crypto/rust/Cargo.toml b/crypto/rust/Cargo.toml index 30b3b5ac..e4228f13 100644 --- a/crypto/rust/Cargo.toml +++ b/crypto/rust/Cargo.toml @@ -13,6 +13,11 @@ keywords = ["cardano"] [lib] crate-type = ["cdylib", "rlib"] +[features] +# these features are only used within chain-libs +generic-serialization = [] +property-test-api = [] + [dependencies] cml-core = { "path" = "../../core/rust", version = "6.0.1" } base64 = "0.21.5" From 2de31c782001d12c1e9de754219dc51e4b24aa2d Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Tue, 3 Dec 2024 10:08:04 -0800 Subject: [PATCH 2/3] set resolver to 2, move deps to workspace --- Cargo.toml | 15 ++++++++++++++- chain/rust/Cargo.toml | 16 ++++++++-------- chain/rust/src/byron/crc32.rs | 2 +- chain/wasm/Cargo.toml | 12 ++++++------ cip25/rust/Cargo.toml | 14 +++++++------- cip25/wasm/Cargo.toml | 12 ++++++------ cip36/rust/Cargo.toml | 16 ++++++++-------- cip36/wasm/Cargo.toml | 12 ++++++------ cml/wasm/Cargo.toml | 12 ++++++------ core/rust/Cargo.toml | 16 ++++++++-------- core/wasm/Cargo.toml | 12 ++++++------ crypto/rust/Cargo.toml | 14 +++++++------- crypto/wasm/Cargo.toml | 8 ++++---- multi-era/rust/Cargo.toml | 14 +++++++------- multi-era/wasm/Cargo.toml | 12 ++++++------ 15 files changed, 100 insertions(+), 87 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d2a4d61a..d0f1c8f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" # this is for the new crate structure. The legacy code (current CML) still resides in the `rust` directory. members = [ @@ -32,4 +33,16 @@ exclude = [ [profile.release] lto = true -opt-level = "z" \ No newline at end of file +opt-level = "z" + +[workspace.dependencies] +cbor_event = "2.4.0" +hex = "0.4.0" +linked-hash-map = "0.5.3" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.57" +serde-wasm-bindgen = "0.4.5" +wasm-bindgen = { version = "0.2.97" } +schemars = "0.8.8" +derivative = "2.2.0" +thiserror = "1.0.37" \ No newline at end of file diff --git a/chain/rust/Cargo.toml b/chain/rust/Cargo.toml index 704f315c..9057faf9 100644 --- a/chain/rust/Cargo.toml +++ b/chain/rust/Cargo.toml @@ -19,15 +19,15 @@ used_from_wasm = ["wasm-bindgen"] [dependencies] cml-core = { "path" = "../../core/rust", version = "6.0.1" } cml-crypto = { "path" = "../../crypto/rust", version = "6.0.1" } -cbor_event = "2.2.0" -linked-hash-map = "0.5.3" -derivative = "2.2.0" -serde = { version = "1.0", features = ["derive"] } +cbor_event.workspace = true +linked-hash-map.workspace = true +derivative.workspace = true +serde.workspace = true serde_json = { version = "1.0.57", features = ["arbitrary_precision"] } -schemars = "0.8.8" +schemars.workspace = true bech32 = "0.7.2" -hex = "0.4.0" +hex.workspace = true itertools = "0.10.1" getrandom = { version = "0.2.3", features = ["js"] } rand = "0.8.5" @@ -35,7 +35,7 @@ fraction = "0.10.0" base64 = "0.21.5" num-bigint = "0.4.0" num-integer = "0.1.45" -thiserror = "1.0.37" +thiserror.workspace = true num = "0.4" unicode-segmentation = "1.10.1" chrono = "0.4.38" @@ -44,7 +44,7 @@ chrono = "0.4.38" noop_proc_macro = { version = "0.3.0", optional = false } # wasm -wasm-bindgen = { version = "0.2.87", optional = true } +wasm-bindgen = { version = "0.2.97", optional = true } [dev-dependencies] diff --git a/chain/rust/src/byron/crc32.rs b/chain/rust/src/byron/crc32.rs index c58bdc7d..acdabf31 100644 --- a/chain/rust/src/byron/crc32.rs +++ b/chain/rust/src/byron/crc32.rs @@ -304,7 +304,7 @@ impl Crc32 { /// beware that the order in which you update the Crc32 /// matter. #[inline] - pub fn update<'a, I>(&'a mut self, bytes: I) -> &mut Self + pub fn update<'a, I>(&'a mut self, bytes: I) -> &'a mut Self where I: IntoIterator, { diff --git a/chain/wasm/Cargo.toml b/chain/wasm/Cargo.toml index a5f44211..3a7e246c 100644 --- a/chain/wasm/Cargo.toml +++ b/chain/wasm/Cargo.toml @@ -20,9 +20,9 @@ cml-core-wasm = { path = "../../core/wasm", version = "6.0.1" } # TODO: remove this dependency if possible to reduce confusion? maybe pub export necessary things in crypto-wasm? cml-crypto = { path = "../../crypto/rust", version = "6.0.1" } cml-crypto-wasm = { path = "../../crypto/wasm", version = "6.0.1" } -cbor_event = "2.4.0" -hex = "0.4.0" -wasm-bindgen = { version = "0.2.87" } -linked-hash-map = "0.5.3" -serde_json = "1.0.57" -serde-wasm-bindgen = "0.4.5" +cbor_event.workspace = true +hex.workspace = true +wasm-bindgen.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true +serde-wasm-bindgen.workspace = true diff --git a/cip25/rust/Cargo.toml b/cip25/rust/Cargo.toml index ef83fb0f..3d9a8a3f 100644 --- a/cip25/rust/Cargo.toml +++ b/cip25/rust/Cargo.toml @@ -17,11 +17,11 @@ crate-type = ["cdylib", "rlib"] cml-chain = { "path" = "../../chain/rust", version = "6.0.1" } cml-core = { "path" = "../../core/rust", version = "6.0.1" } cml-crypto = { "path" = "../../crypto/rust", version = "6.0.1" } -cbor_event = "2.2.0" -hex = "0.4.0" -schemars = "0.8.8" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.57" -thiserror = "1.0.37" +cbor_event.workspace = true +hex.workspace = true +schemars.workspace = true +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true # for enums -wasm-bindgen = { version = "0.2.87" } +wasm-bindgen.workspace = true diff --git a/cip25/wasm/Cargo.toml b/cip25/wasm/Cargo.toml index 161c8fae..d7d1696b 100644 --- a/cip25/wasm/Cargo.toml +++ b/cip25/wasm/Cargo.toml @@ -14,14 +14,14 @@ keywords = ["cardano", "cip25"] crate-type = ["cdylib", "rlib"] [dependencies] -cbor_event = "2.2.0" +cbor_event.workspace = true cml-chain = { path = "../../chain/rust", version = "6.0.1", features = ["used_from_wasm"] } cml-chain-wasm = { path = "../../chain/wasm", version = "6.0.1" } cml-core = { path = "../../core/rust", version = "6.0.1" } cml-core-wasm = { path = "../../core/wasm", version = "6.0.1" } cml-cip25 = { path = "../rust", version = "6.0.1" } -hex = "0.4.0" -linked-hash-map = "0.5.3" -serde_json = "1.0.57" -serde-wasm-bindgen = "0.4.5" -wasm-bindgen = { version = "0.2.87" } +hex.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true +serde-wasm-bindgen.workspace = true +wasm-bindgen.workspace = true diff --git a/cip36/rust/Cargo.toml b/cip36/rust/Cargo.toml index 3453b39a..0c8aecca 100644 --- a/cip36/rust/Cargo.toml +++ b/cip36/rust/Cargo.toml @@ -17,11 +17,11 @@ crate-type = ["cdylib", "rlib"] cml-core = { "path" = "../../core/rust", version = "6.0.1" } cml-crypto = { "path" = "../../crypto/rust", version = "6.0.1" } cml-chain = { "path" = "../../chain/rust", version = "6.0.1" } -cbor_event = "2.2.0" -linked-hash-map = "0.5.3" -derivative = "2.2.0" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.57" -schemars = "0.8.8" -hex = "0.4.0" -thiserror = "1.0.37" \ No newline at end of file +cbor_event.workspace = true +linked-hash-map.workspace = true +derivative.workspace = true +serde.workspace = true +serde_json.workspace = true +schemars.workspace = true +hex.workspace = true +thiserror.workspace = true \ No newline at end of file diff --git a/cip36/wasm/Cargo.toml b/cip36/wasm/Cargo.toml index a1c9052e..480564a8 100644 --- a/cip36/wasm/Cargo.toml +++ b/cip36/wasm/Cargo.toml @@ -21,9 +21,9 @@ cml-chain = { path = "../../chain/rust", version = "6.0.1" } cml-chain-wasm = { path = "../../chain/wasm", version = "6.0.1" } cml-core = { path = "../../core/rust", version = "6.0.1" } cml-core-wasm = { path = "../../core/wasm", version = "6.0.1" } -cbor_event = "2.2.0" -hex = "0.4.0" -wasm-bindgen = { version = "0.2.87" } -linked-hash-map = "0.5.3" -serde_json = "1.0.57" -serde-wasm-bindgen = "0.4.5" +cbor_event.workspace = true +hex.workspace = true +wasm-bindgen.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true +serde-wasm-bindgen.workspace = true diff --git a/cml/wasm/Cargo.toml b/cml/wasm/Cargo.toml index b90f79dc..0cc9bc4d 100644 --- a/cml/wasm/Cargo.toml +++ b/cml/wasm/Cargo.toml @@ -18,9 +18,9 @@ cml-cip25-wasm = { path = "../../cip25/wasm", version = "6.0.1" } cml-cip36-wasm = { path = "../../cip36/wasm", version = "6.0.1" } cml-crypto-wasm = { path = "../../crypto/wasm", version = "6.0.1" } cml-core-wasm = { path = "../../core/wasm", version = "6.0.1" } -cbor_event = "2.4.0" -hex = "0.4.0" -linked-hash-map = "0.5.3" -serde_json = "1.0.57" -serde-wasm-bindgen = "0.4.5" -wasm-bindgen = { version = "0.2.87" } +cbor_event.workspace = true +hex.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true +serde-wasm-bindgen.workspace = true +wasm-bindgen.workspace = true diff --git a/core/rust/Cargo.toml b/core/rust/Cargo.toml index 5f0622d2..e272e3a2 100644 --- a/core/rust/Cargo.toml +++ b/core/rust/Cargo.toml @@ -14,15 +14,15 @@ keywords = ["cardano"] crate-type = ["cdylib", "rlib"] [dependencies] -cbor_event = "2.2.0" -linked-hash-map = "0.5.3" -derivative = "2.2.0" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.57" -schemars = "0.8.8" +cbor_event.workspace = true +linked-hash-map.workspace = true +derivative.workspace = true +serde.workspace = true +serde_json.workspace = true +schemars.workspace = true bech32 = "0.7.2" -hex = "0.4.0" +hex.workspace = true itertools = "0.10.1" getrandom = { version = "0.2.3", features = ["js"] } rand = "0.8.5" @@ -31,7 +31,7 @@ base64 = "0.13" num-bigint = "0.4.0" num-integer = "0.1.45" #rand_os = "0.1" -thiserror = "1.0.37" +thiserror.workspace = true cfg-if = "1" diff --git a/core/wasm/Cargo.toml b/core/wasm/Cargo.toml index c68261bb..b51da132 100644 --- a/core/wasm/Cargo.toml +++ b/core/wasm/Cargo.toml @@ -14,9 +14,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] cml-core = { path = "../rust", version = "6.0.1" } -cbor_event = "2.2.0" -hex = "0.4.0" -wasm-bindgen = { version = "0.2.87" } -linked-hash-map = "0.5.3" -serde_json = "1.0.57" -serde-wasm-bindgen = "0.4.5" +cbor_event.workspace = true +hex.workspace = true +wasm-bindgen.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true +serde-wasm-bindgen.workspace = true diff --git a/crypto/rust/Cargo.toml b/crypto/rust/Cargo.toml index e4228f13..d61fcea7 100644 --- a/crypto/rust/Cargo.toml +++ b/crypto/rust/Cargo.toml @@ -21,21 +21,21 @@ property-test-api = [] [dependencies] cml-core = { "path" = "../../core/rust", version = "6.0.1" } base64 = "0.21.5" -cbor_event = "2.2.0" +cbor_event.workspace = true cryptoxide = "0.4.2" ed25519-bip32 = "0.4.1" sha2 = "^0.9" digest = "^0.9" bech32 = "0.7.2" -hex = "0.4.0" -thiserror = "1.0.37" +hex.workspace = true +thiserror.workspace = true rand = "0.8.5" cfg-if = "1" -derivative = "2.2.0" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.57" -schemars = "0.8.8" +derivative.workspace = true +serde.workspace = true +serde_json.workspace = true +schemars.workspace = true [dev-dependencies] quickcheck = "0.9.2" diff --git a/crypto/wasm/Cargo.toml b/crypto/wasm/Cargo.toml index 9da7cdea..1158c122 100644 --- a/crypto/wasm/Cargo.toml +++ b/crypto/wasm/Cargo.toml @@ -16,7 +16,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] cml-core-wasm = { path = "../../core/wasm", version = "6.0.1" } cml-crypto = { path = "../rust", version = "6.0.1" } -cbor_event = "2.2.0" -wasm-bindgen = { version = "0.2.87" } -linked-hash-map = "0.5.3" -serde_json = "1.0.57" +cbor_event.workspace = true +wasm-bindgen.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true diff --git a/multi-era/rust/Cargo.toml b/multi-era/rust/Cargo.toml index 9b0c22ca..794bec03 100644 --- a/multi-era/rust/Cargo.toml +++ b/multi-era/rust/Cargo.toml @@ -20,16 +20,16 @@ used_from_wasm = ["wasm-bindgen"] cml-core = { path = "../../core/rust", version = "6.0.1" } cml-crypto = { path = "../../crypto/rust", version = "6.0.1" } cml-chain = { path = "../../chain/rust", version = "6.0.1" } -cbor_event = "2.4.0" -linked-hash-map = "0.5.3" -derivative = "2.2.0" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.57" -schemars = "0.8.8" +cbor_event.workspace = true +linked-hash-map.workspace = true +derivative.workspace = true +serde.workspace = true +serde_json.workspace = true +schemars.workspace = true # only for declaring hash types bech32 = "0.7.2" -hex = "0.4.0" +hex.workspace = true # non-wasm noop_proc_macro = { version = "0.3.0" } diff --git a/multi-era/wasm/Cargo.toml b/multi-era/wasm/Cargo.toml index 42f219b6..eaec6dcd 100644 --- a/multi-era/wasm/Cargo.toml +++ b/multi-era/wasm/Cargo.toml @@ -21,12 +21,12 @@ cml-crypto-wasm = { path = "../../crypto/wasm", version = "6.0.1" } cml-core = { path = "../../core/rust", version = "6.0.1" } cml-core-wasm = { path = "../../core/wasm", version = "6.0.1" } cml-multi-era = { path = "../rust", version = "6.0.1", features = ["used_from_wasm"] } -cbor_event = "2.4.0" -hex = "0.4.0" -linked-hash-map = "0.5.3" -serde_json = "1.0.57" -serde-wasm-bindgen = "0.4.5" -wasm-bindgen = { version = "0.2.87" } +cbor_event.workspace = true +hex.workspace = true +linked-hash-map.workspace = true +serde_json.workspace = true +serde-wasm-bindgen.workspace = true +wasm-bindgen.workspace = true # not actual multi-era dependencies but we re-export these for the wasm builds cml-cip25-wasm = { path = "../../cip25/wasm", version = "6.0.1" } cml-cip36-wasm = { path = "../../cip36/wasm", version = "6.0.1" } From dcb499c9fd9413b18528095b6daf66290cd24879 Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Tue, 3 Dec 2024 10:25:54 -0800 Subject: [PATCH 3/3] more clippy fixes (in tests this time) --- chain/rust/src/byron/base58.rs | 6 +++--- chain/rust/src/genesis/shelley/raw.rs | 6 +++--- core/wasm/src/wasm_wrappers.rs | 6 +++--- crypto/rust/src/chain_crypto/sign.rs | 2 +- crypto/rust/src/typed_bytes/mod.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/chain/rust/src/byron/base58.rs b/chain/rust/src/byron/base58.rs index e5163729..037f19ee 100644 --- a/chain/rust/src/byron/base58.rs +++ b/chain/rust/src/byron/base58.rs @@ -31,10 +31,10 @@ pub fn decode(input: &str) -> Result> { base_decode(ALPHABET, input.as_bytes()) } -/// decode from base58 the given input -//pub fn decode_bytes(input: &[u8]) -> Result> { +// /// decode from base58 the given input +// pub fn decode_bytes(input: &[u8]) -> Result> { // base_decode(ALPHABET, input) -//} +// } fn base_encode(alphabet_s: &str, input: &[u8]) -> Vec { let alphabet = alphabet_s.as_bytes(); diff --git a/chain/rust/src/genesis/shelley/raw.rs b/chain/rust/src/genesis/shelley/raw.rs index 9e623e00..d96a49b4 100644 --- a/chain/rust/src/genesis/shelley/raw.rs +++ b/chain/rust/src/genesis/shelley/raw.rs @@ -2,9 +2,9 @@ use crate::assets::Coin; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -/// Parsing of the JSON representation of the Shelley genesis block -/// Note: for a lot of these fields, I didn't check what the max valid size is in the Haskell code -/// so I just used u64 everywhere +// Parsing of the JSON representation of the Shelley genesis block +// Note: for a lot of these fields, I didn't check what the max valid size is in the Haskell code +// so I just used u64 everywhere #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Debug)] diff --git a/core/wasm/src/wasm_wrappers.rs b/core/wasm/src/wasm_wrappers.rs index 4f002476..a5ff3bec 100644 --- a/core/wasm/src/wasm_wrappers.rs +++ b/core/wasm/src/wasm_wrappers.rs @@ -1,6 +1,6 @@ -/// Various code-generation macros to help with WASM wrapper creation. -/// Includes many things that auto-generated by cddl-codegen so we can -/// use these with utility code that had to be hand-written. +//! Various code-generation macros to help with WASM wrapper creation. +//! Includes many things that auto-generated by cddl-codegen so we can +//! use these with utility code that had to be hand-written. /// Auto-declare From/AsRef conversions between rust and WASM wrappers #[macro_export] diff --git a/crypto/rust/src/chain_crypto/sign.rs b/crypto/rust/src/chain_crypto/sign.rs index 587de569..54a3cb18 100644 --- a/crypto/rust/src/chain_crypto/sign.rs +++ b/crypto/rust/src/chain_crypto/sign.rs @@ -132,7 +132,7 @@ impl Signature { pub trait SafeSignatureCoerce {} -impl<'a, T> SafeSignatureCoerce> for ByteSlice<'a, T> {} +impl SafeSignatureCoerce> for ByteSlice<'_, T> {} impl> Signature { #[must_use] diff --git a/crypto/rust/src/typed_bytes/mod.rs b/crypto/rust/src/typed_bytes/mod.rs index 2032d9ae..bd234554 100644 --- a/crypto/rust/src/typed_bytes/mod.rs +++ b/crypto/rust/src/typed_bytes/mod.rs @@ -23,7 +23,7 @@ impl AsRef<[u8]> for ByteArray { } } -impl<'a, T> AsRef<[u8]> for ByteSlice<'a, T> { +impl AsRef<[u8]> for ByteSlice<'_, T> { fn as_ref(&self) -> &[u8] { self.as_slice() }