Skip to content

Commit

Permalink
replace lazy_static! with once_cell::sync::Lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai authored and kayabaNerve committed Nov 6, 2023
1 parent de41be6 commit bd3272a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion message-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions message-queue/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ mod binaries {
#[allow(clippy::type_complexity)]
mod clippy {
use super::*;
lazy_static::lazy_static! {
pub(crate) static ref KEYS: Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>> =
Arc::new(RwLock::new(HashMap::new()));
pub(crate) static ref QUEUES: Arc<RwLock<HashMap<(Service, Service), RwLock<Queue<Db>>>>> =
Arc::new(RwLock::new(HashMap::new()));
}
use once_cell::sync::Lazy;
pub(crate) static KEYS: Lazy<Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>>> =
Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
pub(crate) static QUEUES: Lazy<Arc<RwLock<HashMap<(Service, Service), RwLock<Queue<Db>>>>>> =
Lazy::new(|| Arc::new(RwLock::new(HashMap::new())));
}
pub(crate) use self::clippy::*;

Expand Down
2 changes: 1 addition & 1 deletion processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 4 additions & 4 deletions processor/src/networks/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -259,10 +261,8 @@ impl BlockTrait<Bitcoin> 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<Scalar> = Lazy::new(|| Secp256k1::hash_to_F(KEY_DST, b"branch"));
static CHANGE_OFFSET: Lazy<Scalar> = 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(
Expand Down
4 changes: 1 addition & 3 deletions processor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bd3272a

Please sign in to comment.