From 6fa0d58a6c5f02b572ffcc85ef1fa6526cf11780 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Sun, 5 Nov 2023 09:43:40 -0500 Subject: [PATCH] replace `lazy_static!` with `once_cell::sync::Lazy` --- Cargo.lock | 4 ++-- message-queue/Cargo.toml | 2 +- message-queue/src/main.rs | 11 +++++------ processor/Cargo.toml | 2 +- processor/src/networks/bitcoin.rs | 8 ++++---- processor/src/tests/mod.rs | 4 +--- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 890d040de..179a3bf26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8336,8 +8336,8 @@ dependencies = [ "flexible-transcript", "hex", "jsonrpsee", - "lazy_static", "log", + "once_cell", "rand_core", "reqwest", "schnorr-signatures", @@ -8452,10 +8452,10 @@ dependencies = [ "futures", "hex", "k256", - "lazy_static", "log", "modular-frost", "monero-serai", + "once_cell", "parity-scale-codec", "rand_chacha", "rand_core", diff --git a/message-queue/Cargo.toml b/message-queue/Cargo.toml index d131e4228..0185aa8fd 100644 --- a/message-queue/Cargo.toml +++ b/message-queue/Cargo.toml @@ -15,7 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] # Macros -lazy_static = { version = "1", default-features = false } +once_cell = { version = "1", default-features = false } serde = { version = "1", default-features = false, features = ["std", "derive"] } # Encoders diff --git a/message-queue/src/main.rs b/message-queue/src/main.rs index 313fd979a..69c7166bc 100644 --- a/message-queue/src/main.rs +++ b/message-queue/src/main.rs @@ -28,12 +28,11 @@ mod binaries { #[allow(clippy::type_complexity)] mod clippy { use super::*; - lazy_static::lazy_static! { - pub(crate) static ref KEYS: Arc::G>>> = - Arc::new(RwLock::new(HashMap::new())); - pub(crate) static ref QUEUES: Arc>>>> = - Arc::new(RwLock::new(HashMap::new())); - } + use once_cell::sync::Lazy; + pub(crate) static KEYS: Lazy::G>>>> = + Lazy::new(|| Arc::new(RwLock::new(HashMap::new()))); + pub(crate) static QUEUES: Lazy>>>>> = + Lazy::new(|| Arc::new(RwLock::new(HashMap::new()))); } pub(crate) use self::clippy::*; diff --git a/processor/Cargo.toml b/processor/Cargo.toml index 50d1a61e5..830394d1f 100644 --- a/processor/Cargo.toml +++ b/processor/Cargo.toml @@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] # Macros async-trait = { version = "0.1", default-features = false } -lazy_static = { version = "1", default-features = false } +once_cell = { version = "1", default-features = false } zeroize = { version = "1", default-features = false, features = ["std"] } thiserror = { version = "1", default-features = false } serde = { version = "1", default-features = false, features = ["std", "derive"] } diff --git a/processor/src/networks/bitcoin.rs b/processor/src/networks/bitcoin.rs index 382e904c8..f8d1498d8 100644 --- a/processor/src/networks/bitcoin.rs +++ b/processor/src/networks/bitcoin.rs @@ -53,6 +53,8 @@ use crate::{ Payment, }; +use once_cell::sync::Lazy; + #[derive(Clone, PartialEq, Eq, Debug)] pub struct OutputId(pub [u8; 36]); impl Default for OutputId { @@ -259,10 +261,8 @@ impl BlockTrait for Block { } const KEY_DST: &[u8] = b"Serai Bitcoin Output Offset"; -lazy_static::lazy_static! { - static ref BRANCH_OFFSET: Scalar = Secp256k1::hash_to_F(KEY_DST, b"branch"); - static ref CHANGE_OFFSET: Scalar = Secp256k1::hash_to_F(KEY_DST, b"change"); -} +static BRANCH_OFFSET: Lazy = Lazy::new(|| Secp256k1::hash_to_F(KEY_DST, b"branch")); +static CHANGE_OFFSET: Lazy = Lazy::new(|| Secp256k1::hash_to_F(KEY_DST, b"change")); // Always construct the full scanner in order to ensure there's no collisions fn scanner( diff --git a/processor/src/tests/mod.rs b/processor/src/tests/mod.rs index b36449287..05f9cd0b1 100644 --- a/processor/src/tests/mod.rs +++ b/processor/src/tests/mod.rs @@ -16,9 +16,7 @@ mod addresses; pub(crate) use addresses::test_addresses; // Effective Once -lazy_static::lazy_static! { - static ref INIT_LOGGER: () = env_logger::init(); -} +static INIT_LOGGER: once_cell::sync::Lazy<()> = once_cell::sync::Lazy::new(env_logger::init); #[macro_export] macro_rules! test_network {